echarts-wordcloud.js 414 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918159191592015921159221592315924159251592615927159281592915930159311593215933159341593515936159371593815939159401594115942159431594415945159461594715948159491595015951159521595315954159551595615957159581595915960159611596215963159641596515966159671596815969159701597115972159731597415975159761597715978159791598015981159821598315984159851598615987159881598915990159911599215993159941599515996159971599815999160001600116002160031600416005160061600716008160091601016011160121601316014160151601616017160181601916020160211602216023160241602516026160271602816029160301603116032160331603416035160361603716038160391604016041160421604316044160451604616047160481604916050160511605216053160541605516056160571605816059160601606116062160631606416065160661606716068160691607016071160721607316074160751607616077160781607916080160811608216083160841608516086160871608816089160901609116092160931609416095160961609716098160991610016101161021610316104161051610616107161081610916110161111611216113161141611516116161171611816119161201612116122161231612416125161261612716128161291613016131161321613316134161351613616137161381613916140161411614216143161441614516146161471614816149161501615116152161531615416155161561615716158161591616016161161621616316164161651616616167161681616916170161711617216173161741617516176161771617816179161801618116182161831618416185161861618716188161891619016191161921619316194161951619616197161981619916200162011620216203162041620516206162071620816209162101621116212162131621416215162161621716218162191622016221162221622316224162251622616227162281622916230162311623216233162341623516236162371623816239162401624116242162431624416245162461624716248162491625016251162521625316254162551625616257162581625916260162611626216263162641626516266162671626816269162701627116272162731627416275162761627716278162791628016281162821628316284162851628616287162881628916290162911629216293162941629516296162971629816299163001630116302163031630416305163061630716308163091631016311163121631316314163151631616317163181631916320163211632216323163241632516326163271632816329163301633116332163331633416335163361633716338163391634016341163421634316344163451634616347163481634916350163511635216353163541635516356163571635816359163601636116362163631636416365163661636716368163691637016371163721637316374163751637616377163781637916380163811638216383163841638516386163871638816389163901639116392163931639416395163961639716398163991640016401164021640316404164051640616407164081640916410164111641216413164141641516416164171641816419164201642116422164231642416425164261642716428164291643016431164321643316434164351643616437164381643916440164411644216443164441644516446164471644816449164501645116452164531645416455164561645716458164591646016461164621646316464164651646616467164681646916470164711647216473164741647516476164771647816479164801648116482164831648416485164861648716488164891649016491164921649316494164951649616497164981649916500165011650216503165041650516506165071650816509165101651116512165131651416515165161651716518165191652016521165221652316524165251652616527165281652916530165311653216533165341653516536165371653816539165401654116542165431654416545165461654716548
  1. (function webpackUniversalModuleDefinition(root, factory) {
  2. if(typeof exports === 'object' && typeof module === 'object')
  3. module.exports = factory(require("echarts"));
  4. else if(typeof define === 'function' && define.amd)
  5. define(["echarts"], factory);
  6. else if(typeof exports === 'object')
  7. exports["echarts-wordcloud"] = factory(require("echarts"));
  8. else
  9. root["echarts-wordcloud"] = factory(root["echarts"]);
  10. })(this, function(__WEBPACK_EXTERNAL_MODULE_7__) {
  11. return /******/ (function(modules) { // webpackBootstrap
  12. /******/ // The module cache
  13. /******/ var installedModules = {};
  14. /******/
  15. /******/ // The require function
  16. /******/ function __webpack_require__(moduleId) {
  17. /******/
  18. /******/ // Check if module is in cache
  19. /******/ if(installedModules[moduleId]) {
  20. /******/ return installedModules[moduleId].exports;
  21. /******/ }
  22. /******/ // Create a new module (and put it into the cache)
  23. /******/ var module = installedModules[moduleId] = {
  24. /******/ i: moduleId,
  25. /******/ l: false,
  26. /******/ exports: {}
  27. /******/ };
  28. /******/
  29. /******/ // Execute the module function
  30. /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
  31. /******/
  32. /******/ // Flag the module as loaded
  33. /******/ module.l = true;
  34. /******/
  35. /******/ // Return the exports of the module
  36. /******/ return module.exports;
  37. /******/ }
  38. /******/
  39. /******/
  40. /******/ // expose the modules object (__webpack_modules__)
  41. /******/ __webpack_require__.m = modules;
  42. /******/
  43. /******/ // expose the module cache
  44. /******/ __webpack_require__.c = installedModules;
  45. /******/
  46. /******/ // define getter function for harmony exports
  47. /******/ __webpack_require__.d = function(exports, name, getter) {
  48. /******/ if(!__webpack_require__.o(exports, name)) {
  49. /******/ Object.defineProperty(exports, name, {
  50. /******/ configurable: false,
  51. /******/ enumerable: true,
  52. /******/ get: getter
  53. /******/ });
  54. /******/ }
  55. /******/ };
  56. /******/
  57. /******/ // getDefaultExport function for compatibility with non-harmony modules
  58. /******/ __webpack_require__.n = function(module) {
  59. /******/ var getter = module && module.__esModule ?
  60. /******/ function getDefault() { return module['default']; } :
  61. /******/ function getModuleExports() { return module; };
  62. /******/ __webpack_require__.d(getter, 'a', getter);
  63. /******/ return getter;
  64. /******/ };
  65. /******/
  66. /******/ // Object.prototype.hasOwnProperty.call
  67. /******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
  68. /******/
  69. /******/ // __webpack_public_path__
  70. /******/ __webpack_require__.p = "";
  71. /******/
  72. /******/ // Load entry module and return exports
  73. /******/ return __webpack_require__(__webpack_require__.s = 25);
  74. /******/ })
  75. /************************************************************************/
  76. /******/ ([
  77. /* 0 */
  78. /***/ (function(module, exports) {
  79. /**
  80. * @module zrender/core/util
  81. */
  82. // 用于处理merge时无法遍历Date等对象的问题
  83. var BUILTIN_OBJECT = {
  84. '[object Function]': 1,
  85. '[object RegExp]': 1,
  86. '[object Date]': 1,
  87. '[object Error]': 1,
  88. '[object CanvasGradient]': 1,
  89. '[object CanvasPattern]': 1,
  90. // For node-canvas
  91. '[object Image]': 1,
  92. '[object Canvas]': 1
  93. };
  94. var TYPED_ARRAY = {
  95. '[object Int8Array]': 1,
  96. '[object Uint8Array]': 1,
  97. '[object Uint8ClampedArray]': 1,
  98. '[object Int16Array]': 1,
  99. '[object Uint16Array]': 1,
  100. '[object Int32Array]': 1,
  101. '[object Uint32Array]': 1,
  102. '[object Float32Array]': 1,
  103. '[object Float64Array]': 1
  104. };
  105. var objToString = Object.prototype.toString;
  106. var arrayProto = Array.prototype;
  107. var nativeForEach = arrayProto.forEach;
  108. var nativeFilter = arrayProto.filter;
  109. var nativeSlice = arrayProto.slice;
  110. var nativeMap = arrayProto.map;
  111. var nativeReduce = arrayProto.reduce; // Avoid assign to an exported variable, for transforming to cjs.
  112. var methods = {};
  113. function $override(name, fn) {
  114. methods[name] = fn;
  115. }
  116. /**
  117. * Those data types can be cloned:
  118. * Plain object, Array, TypedArray, number, string, null, undefined.
  119. * Those data types will be assgined using the orginal data:
  120. * BUILTIN_OBJECT
  121. * Instance of user defined class will be cloned to a plain object, without
  122. * properties in prototype.
  123. * Other data types is not supported (not sure what will happen).
  124. *
  125. * Caution: do not support clone Date, for performance consideration.
  126. * (There might be a large number of date in `series.data`).
  127. * So date should not be modified in and out of echarts.
  128. *
  129. * @param {*} source
  130. * @return {*} new
  131. */
  132. function clone(source) {
  133. if (source == null || typeof source != 'object') {
  134. return source;
  135. }
  136. var result = source;
  137. var typeStr = objToString.call(source);
  138. if (typeStr === '[object Array]') {
  139. result = [];
  140. for (var i = 0, len = source.length; i < len; i++) {
  141. result[i] = clone(source[i]);
  142. }
  143. } else if (TYPED_ARRAY[typeStr]) {
  144. var Ctor = source.constructor;
  145. if (source.constructor.from) {
  146. result = Ctor.from(source);
  147. } else {
  148. result = new Ctor(source.length);
  149. for (var i = 0, len = source.length; i < len; i++) {
  150. result[i] = clone(source[i]);
  151. }
  152. }
  153. } else if (!BUILTIN_OBJECT[typeStr] && !isPrimitive(source) && !isDom(source)) {
  154. result = {};
  155. for (var key in source) {
  156. if (source.hasOwnProperty(key)) {
  157. result[key] = clone(source[key]);
  158. }
  159. }
  160. }
  161. return result;
  162. }
  163. /**
  164. * @memberOf module:zrender/core/util
  165. * @param {*} target
  166. * @param {*} source
  167. * @param {boolean} [overwrite=false]
  168. */
  169. function merge(target, source, overwrite) {
  170. // We should escapse that source is string
  171. // and enter for ... in ...
  172. if (!isObject(source) || !isObject(target)) {
  173. return overwrite ? clone(source) : target;
  174. }
  175. for (var key in source) {
  176. if (source.hasOwnProperty(key)) {
  177. var targetProp = target[key];
  178. var sourceProp = source[key];
  179. if (isObject(sourceProp) && isObject(targetProp) && !isArray(sourceProp) && !isArray(targetProp) && !isDom(sourceProp) && !isDom(targetProp) && !isBuiltInObject(sourceProp) && !isBuiltInObject(targetProp) && !isPrimitive(sourceProp) && !isPrimitive(targetProp)) {
  180. // 如果需要递归覆盖,就递归调用merge
  181. merge(targetProp, sourceProp, overwrite);
  182. } else if (overwrite || !(key in target)) {
  183. // 否则只处理overwrite为true,或者在目标对象中没有此属性的情况
  184. // NOTE,在 target[key] 不存在的时候也是直接覆盖
  185. target[key] = clone(source[key], true);
  186. }
  187. }
  188. }
  189. return target;
  190. }
  191. /**
  192. * @param {Array} targetAndSources The first item is target, and the rests are source.
  193. * @param {boolean} [overwrite=false]
  194. * @return {*} target
  195. */
  196. function mergeAll(targetAndSources, overwrite) {
  197. var result = targetAndSources[0];
  198. for (var i = 1, len = targetAndSources.length; i < len; i++) {
  199. result = merge(result, targetAndSources[i], overwrite);
  200. }
  201. return result;
  202. }
  203. /**
  204. * @param {*} target
  205. * @param {*} source
  206. * @memberOf module:zrender/core/util
  207. */
  208. function extend(target, source) {
  209. for (var key in source) {
  210. if (source.hasOwnProperty(key)) {
  211. target[key] = source[key];
  212. }
  213. }
  214. return target;
  215. }
  216. /**
  217. * @param {*} target
  218. * @param {*} source
  219. * @param {boolean} [overlay=false]
  220. * @memberOf module:zrender/core/util
  221. */
  222. function defaults(target, source, overlay) {
  223. for (var key in source) {
  224. if (source.hasOwnProperty(key) && (overlay ? source[key] != null : target[key] == null)) {
  225. target[key] = source[key];
  226. }
  227. }
  228. return target;
  229. }
  230. var createCanvas = function () {
  231. return methods.createCanvas();
  232. };
  233. methods.createCanvas = function () {
  234. return document.createElement('canvas');
  235. }; // FIXME
  236. var _ctx;
  237. function getContext() {
  238. if (!_ctx) {
  239. // Use util.createCanvas instead of createCanvas
  240. // because createCanvas may be overwritten in different environment
  241. _ctx = createCanvas().getContext('2d');
  242. }
  243. return _ctx;
  244. }
  245. /**
  246. * 查询数组中元素的index
  247. * @memberOf module:zrender/core/util
  248. */
  249. function indexOf(array, value) {
  250. if (array) {
  251. if (array.indexOf) {
  252. return array.indexOf(value);
  253. }
  254. for (var i = 0, len = array.length; i < len; i++) {
  255. if (array[i] === value) {
  256. return i;
  257. }
  258. }
  259. }
  260. return -1;
  261. }
  262. /**
  263. * 构造类继承关系
  264. *
  265. * @memberOf module:zrender/core/util
  266. * @param {Function} clazz 源类
  267. * @param {Function} baseClazz 基类
  268. */
  269. function inherits(clazz, baseClazz) {
  270. var clazzPrototype = clazz.prototype;
  271. function F() {}
  272. F.prototype = baseClazz.prototype;
  273. clazz.prototype = new F();
  274. for (var prop in clazzPrototype) {
  275. clazz.prototype[prop] = clazzPrototype[prop];
  276. }
  277. clazz.prototype.constructor = clazz;
  278. clazz.superClass = baseClazz;
  279. }
  280. /**
  281. * @memberOf module:zrender/core/util
  282. * @param {Object|Function} target
  283. * @param {Object|Function} sorce
  284. * @param {boolean} overlay
  285. */
  286. function mixin(target, source, overlay) {
  287. target = 'prototype' in target ? target.prototype : target;
  288. source = 'prototype' in source ? source.prototype : source;
  289. defaults(target, source, overlay);
  290. }
  291. /**
  292. * Consider typed array.
  293. * @param {Array|TypedArray} data
  294. */
  295. function isArrayLike(data) {
  296. if (!data) {
  297. return;
  298. }
  299. if (typeof data == 'string') {
  300. return false;
  301. }
  302. return typeof data.length == 'number';
  303. }
  304. /**
  305. * 数组或对象遍历
  306. * @memberOf module:zrender/core/util
  307. * @param {Object|Array} obj
  308. * @param {Function} cb
  309. * @param {*} [context]
  310. */
  311. function each(obj, cb, context) {
  312. if (!(obj && cb)) {
  313. return;
  314. }
  315. if (obj.forEach && obj.forEach === nativeForEach) {
  316. obj.forEach(cb, context);
  317. } else if (obj.length === +obj.length) {
  318. for (var i = 0, len = obj.length; i < len; i++) {
  319. cb.call(context, obj[i], i, obj);
  320. }
  321. } else {
  322. for (var key in obj) {
  323. if (obj.hasOwnProperty(key)) {
  324. cb.call(context, obj[key], key, obj);
  325. }
  326. }
  327. }
  328. }
  329. /**
  330. * 数组映射
  331. * @memberOf module:zrender/core/util
  332. * @param {Array} obj
  333. * @param {Function} cb
  334. * @param {*} [context]
  335. * @return {Array}
  336. */
  337. function map(obj, cb, context) {
  338. if (!(obj && cb)) {
  339. return;
  340. }
  341. if (obj.map && obj.map === nativeMap) {
  342. return obj.map(cb, context);
  343. } else {
  344. var result = [];
  345. for (var i = 0, len = obj.length; i < len; i++) {
  346. result.push(cb.call(context, obj[i], i, obj));
  347. }
  348. return result;
  349. }
  350. }
  351. /**
  352. * @memberOf module:zrender/core/util
  353. * @param {Array} obj
  354. * @param {Function} cb
  355. * @param {Object} [memo]
  356. * @param {*} [context]
  357. * @return {Array}
  358. */
  359. function reduce(obj, cb, memo, context) {
  360. if (!(obj && cb)) {
  361. return;
  362. }
  363. if (obj.reduce && obj.reduce === nativeReduce) {
  364. return obj.reduce(cb, memo, context);
  365. } else {
  366. for (var i = 0, len = obj.length; i < len; i++) {
  367. memo = cb.call(context, memo, obj[i], i, obj);
  368. }
  369. return memo;
  370. }
  371. }
  372. /**
  373. * 数组过滤
  374. * @memberOf module:zrender/core/util
  375. * @param {Array} obj
  376. * @param {Function} cb
  377. * @param {*} [context]
  378. * @return {Array}
  379. */
  380. function filter(obj, cb, context) {
  381. if (!(obj && cb)) {
  382. return;
  383. }
  384. if (obj.filter && obj.filter === nativeFilter) {
  385. return obj.filter(cb, context);
  386. } else {
  387. var result = [];
  388. for (var i = 0, len = obj.length; i < len; i++) {
  389. if (cb.call(context, obj[i], i, obj)) {
  390. result.push(obj[i]);
  391. }
  392. }
  393. return result;
  394. }
  395. }
  396. /**
  397. * 数组项查找
  398. * @memberOf module:zrender/core/util
  399. * @param {Array} obj
  400. * @param {Function} cb
  401. * @param {*} [context]
  402. * @return {*}
  403. */
  404. function find(obj, cb, context) {
  405. if (!(obj && cb)) {
  406. return;
  407. }
  408. for (var i = 0, len = obj.length; i < len; i++) {
  409. if (cb.call(context, obj[i], i, obj)) {
  410. return obj[i];
  411. }
  412. }
  413. }
  414. /**
  415. * @memberOf module:zrender/core/util
  416. * @param {Function} func
  417. * @param {*} context
  418. * @return {Function}
  419. */
  420. function bind(func, context) {
  421. var args = nativeSlice.call(arguments, 2);
  422. return function () {
  423. return func.apply(context, args.concat(nativeSlice.call(arguments)));
  424. };
  425. }
  426. /**
  427. * @memberOf module:zrender/core/util
  428. * @param {Function} func
  429. * @return {Function}
  430. */
  431. function curry(func) {
  432. var args = nativeSlice.call(arguments, 1);
  433. return function () {
  434. return func.apply(this, args.concat(nativeSlice.call(arguments)));
  435. };
  436. }
  437. /**
  438. * @memberOf module:zrender/core/util
  439. * @param {*} value
  440. * @return {boolean}
  441. */
  442. function isArray(value) {
  443. return objToString.call(value) === '[object Array]';
  444. }
  445. /**
  446. * @memberOf module:zrender/core/util
  447. * @param {*} value
  448. * @return {boolean}
  449. */
  450. function isFunction(value) {
  451. return typeof value === 'function';
  452. }
  453. /**
  454. * @memberOf module:zrender/core/util
  455. * @param {*} value
  456. * @return {boolean}
  457. */
  458. function isString(value) {
  459. return objToString.call(value) === '[object String]';
  460. }
  461. /**
  462. * @memberOf module:zrender/core/util
  463. * @param {*} value
  464. * @return {boolean}
  465. */
  466. function isObject(value) {
  467. // Avoid a V8 JIT bug in Chrome 19-20.
  468. // See https://code.google.com/p/v8/issues/detail?id=2291 for more details.
  469. var type = typeof value;
  470. return type === 'function' || !!value && type == 'object';
  471. }
  472. /**
  473. * @memberOf module:zrender/core/util
  474. * @param {*} value
  475. * @return {boolean}
  476. */
  477. function isBuiltInObject(value) {
  478. return !!BUILTIN_OBJECT[objToString.call(value)];
  479. }
  480. /**
  481. * @memberOf module:zrender/core/util
  482. * @param {*} value
  483. * @return {boolean}
  484. */
  485. function isDom(value) {
  486. return typeof value === 'object' && typeof value.nodeType === 'number' && typeof value.ownerDocument === 'object';
  487. }
  488. /**
  489. * Whether is exactly NaN. Notice isNaN('a') returns true.
  490. * @param {*} value
  491. * @return {boolean}
  492. */
  493. function eqNaN(value) {
  494. return value !== value;
  495. }
  496. /**
  497. * If value1 is not null, then return value1, otherwise judget rest of values.
  498. * Low performance.
  499. * @memberOf module:zrender/core/util
  500. * @return {*} Final value
  501. */
  502. function retrieve(values) {
  503. for (var i = 0, len = arguments.length; i < len; i++) {
  504. if (arguments[i] != null) {
  505. return arguments[i];
  506. }
  507. }
  508. }
  509. function retrieve2(value0, value1) {
  510. return value0 != null ? value0 : value1;
  511. }
  512. function retrieve3(value0, value1, value2) {
  513. return value0 != null ? value0 : value1 != null ? value1 : value2;
  514. }
  515. /**
  516. * @memberOf module:zrender/core/util
  517. * @param {Array} arr
  518. * @param {number} startIndex
  519. * @param {number} endIndex
  520. * @return {Array}
  521. */
  522. function slice() {
  523. return Function.call.apply(nativeSlice, arguments);
  524. }
  525. /**
  526. * Normalize css liked array configuration
  527. * e.g.
  528. * 3 => [3, 3, 3, 3]
  529. * [4, 2] => [4, 2, 4, 2]
  530. * [4, 3, 2] => [4, 3, 2, 3]
  531. * @param {number|Array.<number>} val
  532. * @return {Array.<number>}
  533. */
  534. function normalizeCssArray(val) {
  535. if (typeof val === 'number') {
  536. return [val, val, val, val];
  537. }
  538. var len = val.length;
  539. if (len === 2) {
  540. // vertical | horizontal
  541. return [val[0], val[1], val[0], val[1]];
  542. } else if (len === 3) {
  543. // top | horizontal | bottom
  544. return [val[0], val[1], val[2], val[1]];
  545. }
  546. return val;
  547. }
  548. /**
  549. * @memberOf module:zrender/core/util
  550. * @param {boolean} condition
  551. * @param {string} message
  552. */
  553. function assert(condition, message) {
  554. if (!condition) {
  555. throw new Error(message);
  556. }
  557. }
  558. var primitiveKey = '__ec_primitive__';
  559. /**
  560. * Set an object as primitive to be ignored traversing children in clone or merge
  561. */
  562. function setAsPrimitive(obj) {
  563. obj[primitiveKey] = true;
  564. }
  565. function isPrimitive(obj) {
  566. return obj[primitiveKey];
  567. }
  568. /**
  569. * @constructor
  570. * @param {Object} obj Only apply `ownProperty`.
  571. */
  572. function HashMap(obj) {
  573. obj && each(obj, function (value, key) {
  574. this.set(key, value);
  575. }, this);
  576. } // Add prefix to avoid conflict with Object.prototype.
  577. var HASH_MAP_PREFIX = '_ec_';
  578. var HASH_MAP_PREFIX_LENGTH = 4;
  579. HashMap.prototype = {
  580. constructor: HashMap,
  581. // Do not provide `has` method to avoid defining what is `has`.
  582. // (We usually treat `null` and `undefined` as the same, different
  583. // from ES6 Map).
  584. get: function (key) {
  585. return this[HASH_MAP_PREFIX + key];
  586. },
  587. set: function (key, value) {
  588. this[HASH_MAP_PREFIX + key] = value; // Comparing with invocation chaining, `return value` is more commonly
  589. // used in this case: `var someVal = map.set('a', genVal());`
  590. return value;
  591. },
  592. // Although util.each can be performed on this hashMap directly, user
  593. // should not use the exposed keys, who are prefixed.
  594. each: function (cb, context) {
  595. context !== void 0 && (cb = bind(cb, context));
  596. for (var prefixedKey in this) {
  597. this.hasOwnProperty(prefixedKey) && cb(this[prefixedKey], prefixedKey.slice(HASH_MAP_PREFIX_LENGTH));
  598. }
  599. },
  600. // Do not use this method if performance sensitive.
  601. removeKey: function (key) {
  602. delete this[HASH_MAP_PREFIX + key];
  603. }
  604. };
  605. function createHashMap(obj) {
  606. return new HashMap(obj);
  607. }
  608. function noop() {}
  609. exports.$override = $override;
  610. exports.clone = clone;
  611. exports.merge = merge;
  612. exports.mergeAll = mergeAll;
  613. exports.extend = extend;
  614. exports.defaults = defaults;
  615. exports.createCanvas = createCanvas;
  616. exports.getContext = getContext;
  617. exports.indexOf = indexOf;
  618. exports.inherits = inherits;
  619. exports.mixin = mixin;
  620. exports.isArrayLike = isArrayLike;
  621. exports.each = each;
  622. exports.map = map;
  623. exports.reduce = reduce;
  624. exports.filter = filter;
  625. exports.find = find;
  626. exports.bind = bind;
  627. exports.curry = curry;
  628. exports.isArray = isArray;
  629. exports.isFunction = isFunction;
  630. exports.isString = isString;
  631. exports.isObject = isObject;
  632. exports.isBuiltInObject = isBuiltInObject;
  633. exports.isDom = isDom;
  634. exports.eqNaN = eqNaN;
  635. exports.retrieve = retrieve;
  636. exports.retrieve2 = retrieve2;
  637. exports.retrieve3 = retrieve3;
  638. exports.slice = slice;
  639. exports.normalizeCssArray = normalizeCssArray;
  640. exports.assert = assert;
  641. exports.setAsPrimitive = setAsPrimitive;
  642. exports.isPrimitive = isPrimitive;
  643. exports.createHashMap = createHashMap;
  644. exports.noop = noop;
  645. /***/ }),
  646. /* 1 */
  647. /***/ (function(module, exports, __webpack_require__) {
  648. var Displayable = __webpack_require__(12);
  649. var zrUtil = __webpack_require__(0);
  650. var PathProxy = __webpack_require__(6);
  651. var pathContain = __webpack_require__(50);
  652. var Pattern = __webpack_require__(56);
  653. var getCanvasPattern = Pattern.prototype.getCanvasPattern;
  654. var abs = Math.abs;
  655. var pathProxyForDraw = new PathProxy(true);
  656. /**
  657. * @alias module:zrender/graphic/Path
  658. * @extends module:zrender/graphic/Displayable
  659. * @constructor
  660. * @param {Object} opts
  661. */
  662. function Path(opts) {
  663. Displayable.call(this, opts);
  664. /**
  665. * @type {module:zrender/core/PathProxy}
  666. * @readOnly
  667. */
  668. this.path = null;
  669. }
  670. Path.prototype = {
  671. constructor: Path,
  672. type: 'path',
  673. __dirtyPath: true,
  674. strokeContainThreshold: 5,
  675. brush: function (ctx, prevEl) {
  676. var style = this.style;
  677. var path = this.path || pathProxyForDraw;
  678. var hasStroke = style.hasStroke();
  679. var hasFill = style.hasFill();
  680. var fill = style.fill;
  681. var stroke = style.stroke;
  682. var hasFillGradient = hasFill && !!fill.colorStops;
  683. var hasStrokeGradient = hasStroke && !!stroke.colorStops;
  684. var hasFillPattern = hasFill && !!fill.image;
  685. var hasStrokePattern = hasStroke && !!stroke.image;
  686. style.bind(ctx, this, prevEl);
  687. this.setTransform(ctx);
  688. if (this.__dirty) {
  689. var rect; // Update gradient because bounding rect may changed
  690. if (hasFillGradient) {
  691. rect = rect || this.getBoundingRect();
  692. this._fillGradient = style.getGradient(ctx, fill, rect);
  693. }
  694. if (hasStrokeGradient) {
  695. rect = rect || this.getBoundingRect();
  696. this._strokeGradient = style.getGradient(ctx, stroke, rect);
  697. }
  698. } // Use the gradient or pattern
  699. if (hasFillGradient) {
  700. // PENDING If may have affect the state
  701. ctx.fillStyle = this._fillGradient;
  702. } else if (hasFillPattern) {
  703. ctx.fillStyle = getCanvasPattern.call(fill, ctx);
  704. }
  705. if (hasStrokeGradient) {
  706. ctx.strokeStyle = this._strokeGradient;
  707. } else if (hasStrokePattern) {
  708. ctx.strokeStyle = getCanvasPattern.call(stroke, ctx);
  709. }
  710. var lineDash = style.lineDash;
  711. var lineDashOffset = style.lineDashOffset;
  712. var ctxLineDash = !!ctx.setLineDash; // Update path sx, sy
  713. var scale = this.getGlobalScale();
  714. path.setScale(scale[0], scale[1]); // Proxy context
  715. // Rebuild path in following 2 cases
  716. // 1. Path is dirty
  717. // 2. Path needs javascript implemented lineDash stroking.
  718. // In this case, lineDash information will not be saved in PathProxy
  719. if (this.__dirtyPath || lineDash && !ctxLineDash && hasStroke) {
  720. path.beginPath(ctx); // Setting line dash before build path
  721. if (lineDash && !ctxLineDash) {
  722. path.setLineDash(lineDash);
  723. path.setLineDashOffset(lineDashOffset);
  724. }
  725. this.buildPath(path, this.shape, false); // Clear path dirty flag
  726. if (this.path) {
  727. this.__dirtyPath = false;
  728. }
  729. } else {
  730. // Replay path building
  731. ctx.beginPath();
  732. this.path.rebuildPath(ctx);
  733. }
  734. hasFill && path.fill(ctx);
  735. if (lineDash && ctxLineDash) {
  736. ctx.setLineDash(lineDash);
  737. ctx.lineDashOffset = lineDashOffset;
  738. }
  739. hasStroke && path.stroke(ctx);
  740. if (lineDash && ctxLineDash) {
  741. // PENDING
  742. // Remove lineDash
  743. ctx.setLineDash([]);
  744. }
  745. this.restoreTransform(ctx); // Draw rect text
  746. if (style.text != null) {
  747. this.drawRectText(ctx, this.getBoundingRect());
  748. }
  749. },
  750. // When bundling path, some shape may decide if use moveTo to begin a new subpath or closePath
  751. // Like in circle
  752. buildPath: function (ctx, shapeCfg, inBundle) {},
  753. createPathProxy: function () {
  754. this.path = new PathProxy();
  755. },
  756. getBoundingRect: function () {
  757. var rect = this._rect;
  758. var style = this.style;
  759. var needsUpdateRect = !rect;
  760. if (needsUpdateRect) {
  761. var path = this.path;
  762. if (!path) {
  763. // Create path on demand.
  764. path = this.path = new PathProxy();
  765. }
  766. if (this.__dirtyPath) {
  767. path.beginPath();
  768. this.buildPath(path, this.shape, false);
  769. }
  770. rect = path.getBoundingRect();
  771. }
  772. this._rect = rect;
  773. if (style.hasStroke()) {
  774. // Needs update rect with stroke lineWidth when
  775. // 1. Element changes scale or lineWidth
  776. // 2. Shape is changed
  777. var rectWithStroke = this._rectWithStroke || (this._rectWithStroke = rect.clone());
  778. if (this.__dirty || needsUpdateRect) {
  779. rectWithStroke.copy(rect); // FIXME Must after updateTransform
  780. var w = style.lineWidth; // PENDING, Min line width is needed when line is horizontal or vertical
  781. var lineScale = style.strokeNoScale ? this.getLineScale() : 1; // Only add extra hover lineWidth when there are no fill
  782. if (!style.hasFill()) {
  783. w = Math.max(w, this.strokeContainThreshold || 4);
  784. } // Consider line width
  785. // Line scale can't be 0;
  786. if (lineScale > 1e-10) {
  787. rectWithStroke.width += w / lineScale;
  788. rectWithStroke.height += w / lineScale;
  789. rectWithStroke.x -= w / lineScale / 2;
  790. rectWithStroke.y -= w / lineScale / 2;
  791. }
  792. } // Return rect with stroke
  793. return rectWithStroke;
  794. }
  795. return rect;
  796. },
  797. contain: function (x, y) {
  798. var localPos = this.transformCoordToLocal(x, y);
  799. var rect = this.getBoundingRect();
  800. var style = this.style;
  801. x = localPos[0];
  802. y = localPos[1];
  803. if (rect.contain(x, y)) {
  804. var pathData = this.path.data;
  805. if (style.hasStroke()) {
  806. var lineWidth = style.lineWidth;
  807. var lineScale = style.strokeNoScale ? this.getLineScale() : 1; // Line scale can't be 0;
  808. if (lineScale > 1e-10) {
  809. // Only add extra hover lineWidth when there are no fill
  810. if (!style.hasFill()) {
  811. lineWidth = Math.max(lineWidth, this.strokeContainThreshold);
  812. }
  813. if (pathContain.containStroke(pathData, lineWidth / lineScale, x, y)) {
  814. return true;
  815. }
  816. }
  817. }
  818. if (style.hasFill()) {
  819. return pathContain.contain(pathData, x, y);
  820. }
  821. }
  822. return false;
  823. },
  824. /**
  825. * @param {boolean} dirtyPath
  826. */
  827. dirty: function (dirtyPath) {
  828. if (dirtyPath == null) {
  829. dirtyPath = true;
  830. } // Only mark dirty, not mark clean
  831. if (dirtyPath) {
  832. this.__dirtyPath = dirtyPath;
  833. this._rect = null;
  834. }
  835. this.__dirty = true;
  836. this.__zr && this.__zr.refresh(); // Used as a clipping path
  837. if (this.__clipTarget) {
  838. this.__clipTarget.dirty();
  839. }
  840. },
  841. /**
  842. * Alias for animate('shape')
  843. * @param {boolean} loop
  844. */
  845. animateShape: function (loop) {
  846. return this.animate('shape', loop);
  847. },
  848. // Overwrite attrKV
  849. attrKV: function (key, value) {
  850. // FIXME
  851. if (key === 'shape') {
  852. this.setShape(value);
  853. this.__dirtyPath = true;
  854. this._rect = null;
  855. } else {
  856. Displayable.prototype.attrKV.call(this, key, value);
  857. }
  858. },
  859. /**
  860. * @param {Object|string} key
  861. * @param {*} value
  862. */
  863. setShape: function (key, value) {
  864. var shape = this.shape; // Path from string may not have shape
  865. if (shape) {
  866. if (zrUtil.isObject(key)) {
  867. for (var name in key) {
  868. if (key.hasOwnProperty(name)) {
  869. shape[name] = key[name];
  870. }
  871. }
  872. } else {
  873. shape[key] = value;
  874. }
  875. this.dirty(true);
  876. }
  877. return this;
  878. },
  879. getLineScale: function () {
  880. var m = this.transform; // Get the line scale.
  881. // Determinant of `m` means how much the area is enlarged by the
  882. // transformation. So its square root can be used as a scale factor
  883. // for width.
  884. return m && abs(m[0] - 1) > 1e-10 && abs(m[3] - 1) > 1e-10 ? Math.sqrt(abs(m[0] * m[3] - m[2] * m[1])) : 1;
  885. }
  886. };
  887. /**
  888. * 扩展一个 Path element, 比如星形,圆等。
  889. * Extend a path element
  890. * @param {Object} props
  891. * @param {string} props.type Path type
  892. * @param {Function} props.init Initialize
  893. * @param {Function} props.buildPath Overwrite buildPath method
  894. * @param {Object} [props.style] Extended default style config
  895. * @param {Object} [props.shape] Extended default shape config
  896. */
  897. Path.extend = function (defaults) {
  898. var Sub = function (opts) {
  899. Path.call(this, opts);
  900. if (defaults.style) {
  901. // Extend default style
  902. this.style.extendFrom(defaults.style, false);
  903. } // Extend default shape
  904. var defaultShape = defaults.shape;
  905. if (defaultShape) {
  906. this.shape = this.shape || {};
  907. var thisShape = this.shape;
  908. for (var name in defaultShape) {
  909. if (!thisShape.hasOwnProperty(name) && defaultShape.hasOwnProperty(name)) {
  910. thisShape[name] = defaultShape[name];
  911. }
  912. }
  913. }
  914. defaults.init && defaults.init.call(this, opts);
  915. };
  916. zrUtil.inherits(Sub, Path); // FIXME 不能 extend position, rotation 等引用对象
  917. for (var name in defaults) {
  918. // Extending prototype values and methods
  919. if (name !== 'style' && name !== 'shape') {
  920. Sub.prototype[name] = defaults[name];
  921. }
  922. }
  923. return Sub;
  924. };
  925. zrUtil.inherits(Path, Displayable);
  926. var _default = Path;
  927. module.exports = _default;
  928. /***/ }),
  929. /* 2 */
  930. /***/ (function(module, exports) {
  931. var ArrayCtor = typeof Float32Array === 'undefined' ? Array : Float32Array;
  932. /**
  933. * 创建一个向量
  934. * @param {number} [x=0]
  935. * @param {number} [y=0]
  936. * @return {Vector2}
  937. */
  938. function create(x, y) {
  939. var out = new ArrayCtor(2);
  940. if (x == null) {
  941. x = 0;
  942. }
  943. if (y == null) {
  944. y = 0;
  945. }
  946. out[0] = x;
  947. out[1] = y;
  948. return out;
  949. }
  950. /**
  951. * 复制向量数据
  952. * @param {Vector2} out
  953. * @param {Vector2} v
  954. * @return {Vector2}
  955. */
  956. function copy(out, v) {
  957. out[0] = v[0];
  958. out[1] = v[1];
  959. return out;
  960. }
  961. /**
  962. * 克隆一个向量
  963. * @param {Vector2} v
  964. * @return {Vector2}
  965. */
  966. function clone(v) {
  967. var out = new ArrayCtor(2);
  968. out[0] = v[0];
  969. out[1] = v[1];
  970. return out;
  971. }
  972. /**
  973. * 设置向量的两个项
  974. * @param {Vector2} out
  975. * @param {number} a
  976. * @param {number} b
  977. * @return {Vector2} 结果
  978. */
  979. function set(out, a, b) {
  980. out[0] = a;
  981. out[1] = b;
  982. return out;
  983. }
  984. /**
  985. * 向量相加
  986. * @param {Vector2} out
  987. * @param {Vector2} v1
  988. * @param {Vector2} v2
  989. */
  990. function add(out, v1, v2) {
  991. out[0] = v1[0] + v2[0];
  992. out[1] = v1[1] + v2[1];
  993. return out;
  994. }
  995. /**
  996. * 向量缩放后相加
  997. * @param {Vector2} out
  998. * @param {Vector2} v1
  999. * @param {Vector2} v2
  1000. * @param {number} a
  1001. */
  1002. function scaleAndAdd(out, v1, v2, a) {
  1003. out[0] = v1[0] + v2[0] * a;
  1004. out[1] = v1[1] + v2[1] * a;
  1005. return out;
  1006. }
  1007. /**
  1008. * 向量相减
  1009. * @param {Vector2} out
  1010. * @param {Vector2} v1
  1011. * @param {Vector2} v2
  1012. */
  1013. function sub(out, v1, v2) {
  1014. out[0] = v1[0] - v2[0];
  1015. out[1] = v1[1] - v2[1];
  1016. return out;
  1017. }
  1018. /**
  1019. * 向量长度
  1020. * @param {Vector2} v
  1021. * @return {number}
  1022. */
  1023. function len(v) {
  1024. return Math.sqrt(lenSquare(v));
  1025. }
  1026. var length = len; // jshint ignore:line
  1027. /**
  1028. * 向量长度平方
  1029. * @param {Vector2} v
  1030. * @return {number}
  1031. */
  1032. function lenSquare(v) {
  1033. return v[0] * v[0] + v[1] * v[1];
  1034. }
  1035. var lengthSquare = lenSquare;
  1036. /**
  1037. * 向量乘法
  1038. * @param {Vector2} out
  1039. * @param {Vector2} v1
  1040. * @param {Vector2} v2
  1041. */
  1042. function mul(out, v1, v2) {
  1043. out[0] = v1[0] * v2[0];
  1044. out[1] = v1[1] * v2[1];
  1045. return out;
  1046. }
  1047. /**
  1048. * 向量除法
  1049. * @param {Vector2} out
  1050. * @param {Vector2} v1
  1051. * @param {Vector2} v2
  1052. */
  1053. function div(out, v1, v2) {
  1054. out[0] = v1[0] / v2[0];
  1055. out[1] = v1[1] / v2[1];
  1056. return out;
  1057. }
  1058. /**
  1059. * 向量点乘
  1060. * @param {Vector2} v1
  1061. * @param {Vector2} v2
  1062. * @return {number}
  1063. */
  1064. function dot(v1, v2) {
  1065. return v1[0] * v2[0] + v1[1] * v2[1];
  1066. }
  1067. /**
  1068. * 向量缩放
  1069. * @param {Vector2} out
  1070. * @param {Vector2} v
  1071. * @param {number} s
  1072. */
  1073. function scale(out, v, s) {
  1074. out[0] = v[0] * s;
  1075. out[1] = v[1] * s;
  1076. return out;
  1077. }
  1078. /**
  1079. * 向量归一化
  1080. * @param {Vector2} out
  1081. * @param {Vector2} v
  1082. */
  1083. function normalize(out, v) {
  1084. var d = len(v);
  1085. if (d === 0) {
  1086. out[0] = 0;
  1087. out[1] = 0;
  1088. } else {
  1089. out[0] = v[0] / d;
  1090. out[1] = v[1] / d;
  1091. }
  1092. return out;
  1093. }
  1094. /**
  1095. * 计算向量间距离
  1096. * @param {Vector2} v1
  1097. * @param {Vector2} v2
  1098. * @return {number}
  1099. */
  1100. function distance(v1, v2) {
  1101. return Math.sqrt((v1[0] - v2[0]) * (v1[0] - v2[0]) + (v1[1] - v2[1]) * (v1[1] - v2[1]));
  1102. }
  1103. var dist = distance;
  1104. /**
  1105. * 向量距离平方
  1106. * @param {Vector2} v1
  1107. * @param {Vector2} v2
  1108. * @return {number}
  1109. */
  1110. function distanceSquare(v1, v2) {
  1111. return (v1[0] - v2[0]) * (v1[0] - v2[0]) + (v1[1] - v2[1]) * (v1[1] - v2[1]);
  1112. }
  1113. var distSquare = distanceSquare;
  1114. /**
  1115. * 求负向量
  1116. * @param {Vector2} out
  1117. * @param {Vector2} v
  1118. */
  1119. function negate(out, v) {
  1120. out[0] = -v[0];
  1121. out[1] = -v[1];
  1122. return out;
  1123. }
  1124. /**
  1125. * 插值两个点
  1126. * @param {Vector2} out
  1127. * @param {Vector2} v1
  1128. * @param {Vector2} v2
  1129. * @param {number} t
  1130. */
  1131. function lerp(out, v1, v2, t) {
  1132. out[0] = v1[0] + t * (v2[0] - v1[0]);
  1133. out[1] = v1[1] + t * (v2[1] - v1[1]);
  1134. return out;
  1135. }
  1136. /**
  1137. * 矩阵左乘向量
  1138. * @param {Vector2} out
  1139. * @param {Vector2} v
  1140. * @param {Vector2} m
  1141. */
  1142. function applyTransform(out, v, m) {
  1143. var x = v[0];
  1144. var y = v[1];
  1145. out[0] = m[0] * x + m[2] * y + m[4];
  1146. out[1] = m[1] * x + m[3] * y + m[5];
  1147. return out;
  1148. }
  1149. /**
  1150. * 求两个向量最小值
  1151. * @param {Vector2} out
  1152. * @param {Vector2} v1
  1153. * @param {Vector2} v2
  1154. */
  1155. function min(out, v1, v2) {
  1156. out[0] = Math.min(v1[0], v2[0]);
  1157. out[1] = Math.min(v1[1], v2[1]);
  1158. return out;
  1159. }
  1160. /**
  1161. * 求两个向量最大值
  1162. * @param {Vector2} out
  1163. * @param {Vector2} v1
  1164. * @param {Vector2} v2
  1165. */
  1166. function max(out, v1, v2) {
  1167. out[0] = Math.max(v1[0], v2[0]);
  1168. out[1] = Math.max(v1[1], v2[1]);
  1169. return out;
  1170. }
  1171. exports.create = create;
  1172. exports.copy = copy;
  1173. exports.clone = clone;
  1174. exports.set = set;
  1175. exports.add = add;
  1176. exports.scaleAndAdd = scaleAndAdd;
  1177. exports.sub = sub;
  1178. exports.len = len;
  1179. exports.length = length;
  1180. exports.lenSquare = lenSquare;
  1181. exports.lengthSquare = lengthSquare;
  1182. exports.mul = mul;
  1183. exports.div = div;
  1184. exports.dot = dot;
  1185. exports.scale = scale;
  1186. exports.normalize = normalize;
  1187. exports.distance = distance;
  1188. exports.dist = dist;
  1189. exports.distanceSquare = distanceSquare;
  1190. exports.distSquare = distSquare;
  1191. exports.negate = negate;
  1192. exports.lerp = lerp;
  1193. exports.applyTransform = applyTransform;
  1194. exports.min = min;
  1195. exports.max = max;
  1196. /***/ }),
  1197. /* 3 */
  1198. /***/ (function(module, exports, __webpack_require__) {
  1199. var vec2 = __webpack_require__(2);
  1200. var matrix = __webpack_require__(8);
  1201. /**
  1202. * @module echarts/core/BoundingRect
  1203. */
  1204. var v2ApplyTransform = vec2.applyTransform;
  1205. var mathMin = Math.min;
  1206. var mathMax = Math.max;
  1207. /**
  1208. * @alias module:echarts/core/BoundingRect
  1209. */
  1210. function BoundingRect(x, y, width, height) {
  1211. if (width < 0) {
  1212. x = x + width;
  1213. width = -width;
  1214. }
  1215. if (height < 0) {
  1216. y = y + height;
  1217. height = -height;
  1218. }
  1219. /**
  1220. * @type {number}
  1221. */
  1222. this.x = x;
  1223. /**
  1224. * @type {number}
  1225. */
  1226. this.y = y;
  1227. /**
  1228. * @type {number}
  1229. */
  1230. this.width = width;
  1231. /**
  1232. * @type {number}
  1233. */
  1234. this.height = height;
  1235. }
  1236. BoundingRect.prototype = {
  1237. constructor: BoundingRect,
  1238. /**
  1239. * @param {module:echarts/core/BoundingRect} other
  1240. */
  1241. union: function (other) {
  1242. var x = mathMin(other.x, this.x);
  1243. var y = mathMin(other.y, this.y);
  1244. this.width = mathMax(other.x + other.width, this.x + this.width) - x;
  1245. this.height = mathMax(other.y + other.height, this.y + this.height) - y;
  1246. this.x = x;
  1247. this.y = y;
  1248. },
  1249. /**
  1250. * @param {Array.<number>} m
  1251. * @methods
  1252. */
  1253. applyTransform: function () {
  1254. var lt = [];
  1255. var rb = [];
  1256. var lb = [];
  1257. var rt = [];
  1258. return function (m) {
  1259. // In case usage like this
  1260. // el.getBoundingRect().applyTransform(el.transform)
  1261. // And element has no transform
  1262. if (!m) {
  1263. return;
  1264. }
  1265. lt[0] = lb[0] = this.x;
  1266. lt[1] = rt[1] = this.y;
  1267. rb[0] = rt[0] = this.x + this.width;
  1268. rb[1] = lb[1] = this.y + this.height;
  1269. v2ApplyTransform(lt, lt, m);
  1270. v2ApplyTransform(rb, rb, m);
  1271. v2ApplyTransform(lb, lb, m);
  1272. v2ApplyTransform(rt, rt, m);
  1273. this.x = mathMin(lt[0], rb[0], lb[0], rt[0]);
  1274. this.y = mathMin(lt[1], rb[1], lb[1], rt[1]);
  1275. var maxX = mathMax(lt[0], rb[0], lb[0], rt[0]);
  1276. var maxY = mathMax(lt[1], rb[1], lb[1], rt[1]);
  1277. this.width = maxX - this.x;
  1278. this.height = maxY - this.y;
  1279. };
  1280. }(),
  1281. /**
  1282. * Calculate matrix of transforming from self to target rect
  1283. * @param {module:zrender/core/BoundingRect} b
  1284. * @return {Array.<number>}
  1285. */
  1286. calculateTransform: function (b) {
  1287. var a = this;
  1288. var sx = b.width / a.width;
  1289. var sy = b.height / a.height;
  1290. var m = matrix.create(); // 矩阵右乘
  1291. matrix.translate(m, m, [-a.x, -a.y]);
  1292. matrix.scale(m, m, [sx, sy]);
  1293. matrix.translate(m, m, [b.x, b.y]);
  1294. return m;
  1295. },
  1296. /**
  1297. * @param {(module:echarts/core/BoundingRect|Object)} b
  1298. * @return {boolean}
  1299. */
  1300. intersect: function (b) {
  1301. if (!b) {
  1302. return false;
  1303. }
  1304. if (!(b instanceof BoundingRect)) {
  1305. // Normalize negative width/height.
  1306. b = BoundingRect.create(b);
  1307. }
  1308. var a = this;
  1309. var ax0 = a.x;
  1310. var ax1 = a.x + a.width;
  1311. var ay0 = a.y;
  1312. var ay1 = a.y + a.height;
  1313. var bx0 = b.x;
  1314. var bx1 = b.x + b.width;
  1315. var by0 = b.y;
  1316. var by1 = b.y + b.height;
  1317. return !(ax1 < bx0 || bx1 < ax0 || ay1 < by0 || by1 < ay0);
  1318. },
  1319. contain: function (x, y) {
  1320. var rect = this;
  1321. return x >= rect.x && x <= rect.x + rect.width && y >= rect.y && y <= rect.y + rect.height;
  1322. },
  1323. /**
  1324. * @return {module:echarts/core/BoundingRect}
  1325. */
  1326. clone: function () {
  1327. return new BoundingRect(this.x, this.y, this.width, this.height);
  1328. },
  1329. /**
  1330. * Copy from another rect
  1331. */
  1332. copy: function (other) {
  1333. this.x = other.x;
  1334. this.y = other.y;
  1335. this.width = other.width;
  1336. this.height = other.height;
  1337. },
  1338. plain: function () {
  1339. return {
  1340. x: this.x,
  1341. y: this.y,
  1342. width: this.width,
  1343. height: this.height
  1344. };
  1345. }
  1346. };
  1347. /**
  1348. * @param {Object|module:zrender/core/BoundingRect} rect
  1349. * @param {number} rect.x
  1350. * @param {number} rect.y
  1351. * @param {number} rect.width
  1352. * @param {number} rect.height
  1353. * @return {module:zrender/core/BoundingRect}
  1354. */
  1355. BoundingRect.create = function (rect) {
  1356. return new BoundingRect(rect.x, rect.y, rect.width, rect.height);
  1357. };
  1358. var _default = BoundingRect;
  1359. module.exports = _default;
  1360. /***/ }),
  1361. /* 4 */
  1362. /***/ (function(module, exports, __webpack_require__) {
  1363. var _vector = __webpack_require__(2);
  1364. var v2Create = _vector.create;
  1365. var v2DistSquare = _vector.distSquare;
  1366. /**
  1367. * 曲线辅助模块
  1368. * @module zrender/core/curve
  1369. * @author pissang(https://www.github.com/pissang)
  1370. */
  1371. var mathPow = Math.pow;
  1372. var mathSqrt = Math.sqrt;
  1373. var EPSILON = 1e-8;
  1374. var EPSILON_NUMERIC = 1e-4;
  1375. var THREE_SQRT = mathSqrt(3);
  1376. var ONE_THIRD = 1 / 3; // 临时变量
  1377. var _v0 = v2Create();
  1378. var _v1 = v2Create();
  1379. var _v2 = v2Create();
  1380. function isAroundZero(val) {
  1381. return val > -EPSILON && val < EPSILON;
  1382. }
  1383. function isNotAroundZero(val) {
  1384. return val > EPSILON || val < -EPSILON;
  1385. }
  1386. /**
  1387. * 计算三次贝塞尔值
  1388. * @memberOf module:zrender/core/curve
  1389. * @param {number} p0
  1390. * @param {number} p1
  1391. * @param {number} p2
  1392. * @param {number} p3
  1393. * @param {number} t
  1394. * @return {number}
  1395. */
  1396. function cubicAt(p0, p1, p2, p3, t) {
  1397. var onet = 1 - t;
  1398. return onet * onet * (onet * p0 + 3 * t * p1) + t * t * (t * p3 + 3 * onet * p2);
  1399. }
  1400. /**
  1401. * 计算三次贝塞尔导数值
  1402. * @memberOf module:zrender/core/curve
  1403. * @param {number} p0
  1404. * @param {number} p1
  1405. * @param {number} p2
  1406. * @param {number} p3
  1407. * @param {number} t
  1408. * @return {number}
  1409. */
  1410. function cubicDerivativeAt(p0, p1, p2, p3, t) {
  1411. var onet = 1 - t;
  1412. return 3 * (((p1 - p0) * onet + 2 * (p2 - p1) * t) * onet + (p3 - p2) * t * t);
  1413. }
  1414. /**
  1415. * 计算三次贝塞尔方程根,使用盛金公式
  1416. * @memberOf module:zrender/core/curve
  1417. * @param {number} p0
  1418. * @param {number} p1
  1419. * @param {number} p2
  1420. * @param {number} p3
  1421. * @param {number} val
  1422. * @param {Array.<number>} roots
  1423. * @return {number} 有效根数目
  1424. */
  1425. function cubicRootAt(p0, p1, p2, p3, val, roots) {
  1426. // Evaluate roots of cubic functions
  1427. var a = p3 + 3 * (p1 - p2) - p0;
  1428. var b = 3 * (p2 - p1 * 2 + p0);
  1429. var c = 3 * (p1 - p0);
  1430. var d = p0 - val;
  1431. var A = b * b - 3 * a * c;
  1432. var B = b * c - 9 * a * d;
  1433. var C = c * c - 3 * b * d;
  1434. var n = 0;
  1435. if (isAroundZero(A) && isAroundZero(B)) {
  1436. if (isAroundZero(b)) {
  1437. roots[0] = 0;
  1438. } else {
  1439. var t1 = -c / b; //t1, t2, t3, b is not zero
  1440. if (t1 >= 0 && t1 <= 1) {
  1441. roots[n++] = t1;
  1442. }
  1443. }
  1444. } else {
  1445. var disc = B * B - 4 * A * C;
  1446. if (isAroundZero(disc)) {
  1447. var K = B / A;
  1448. var t1 = -b / a + K; // t1, a is not zero
  1449. var t2 = -K / 2; // t2, t3
  1450. if (t1 >= 0 && t1 <= 1) {
  1451. roots[n++] = t1;
  1452. }
  1453. if (t2 >= 0 && t2 <= 1) {
  1454. roots[n++] = t2;
  1455. }
  1456. } else if (disc > 0) {
  1457. var discSqrt = mathSqrt(disc);
  1458. var Y1 = A * b + 1.5 * a * (-B + discSqrt);
  1459. var Y2 = A * b + 1.5 * a * (-B - discSqrt);
  1460. if (Y1 < 0) {
  1461. Y1 = -mathPow(-Y1, ONE_THIRD);
  1462. } else {
  1463. Y1 = mathPow(Y1, ONE_THIRD);
  1464. }
  1465. if (Y2 < 0) {
  1466. Y2 = -mathPow(-Y2, ONE_THIRD);
  1467. } else {
  1468. Y2 = mathPow(Y2, ONE_THIRD);
  1469. }
  1470. var t1 = (-b - (Y1 + Y2)) / (3 * a);
  1471. if (t1 >= 0 && t1 <= 1) {
  1472. roots[n++] = t1;
  1473. }
  1474. } else {
  1475. var T = (2 * A * b - 3 * a * B) / (2 * mathSqrt(A * A * A));
  1476. var theta = Math.acos(T) / 3;
  1477. var ASqrt = mathSqrt(A);
  1478. var tmp = Math.cos(theta);
  1479. var t1 = (-b - 2 * ASqrt * tmp) / (3 * a);
  1480. var t2 = (-b + ASqrt * (tmp + THREE_SQRT * Math.sin(theta))) / (3 * a);
  1481. var t3 = (-b + ASqrt * (tmp - THREE_SQRT * Math.sin(theta))) / (3 * a);
  1482. if (t1 >= 0 && t1 <= 1) {
  1483. roots[n++] = t1;
  1484. }
  1485. if (t2 >= 0 && t2 <= 1) {
  1486. roots[n++] = t2;
  1487. }
  1488. if (t3 >= 0 && t3 <= 1) {
  1489. roots[n++] = t3;
  1490. }
  1491. }
  1492. }
  1493. return n;
  1494. }
  1495. /**
  1496. * 计算三次贝塞尔方程极限值的位置
  1497. * @memberOf module:zrender/core/curve
  1498. * @param {number} p0
  1499. * @param {number} p1
  1500. * @param {number} p2
  1501. * @param {number} p3
  1502. * @param {Array.<number>} extrema
  1503. * @return {number} 有效数目
  1504. */
  1505. function cubicExtrema(p0, p1, p2, p3, extrema) {
  1506. var b = 6 * p2 - 12 * p1 + 6 * p0;
  1507. var a = 9 * p1 + 3 * p3 - 3 * p0 - 9 * p2;
  1508. var c = 3 * p1 - 3 * p0;
  1509. var n = 0;
  1510. if (isAroundZero(a)) {
  1511. if (isNotAroundZero(b)) {
  1512. var t1 = -c / b;
  1513. if (t1 >= 0 && t1 <= 1) {
  1514. extrema[n++] = t1;
  1515. }
  1516. }
  1517. } else {
  1518. var disc = b * b - 4 * a * c;
  1519. if (isAroundZero(disc)) {
  1520. extrema[0] = -b / (2 * a);
  1521. } else if (disc > 0) {
  1522. var discSqrt = mathSqrt(disc);
  1523. var t1 = (-b + discSqrt) / (2 * a);
  1524. var t2 = (-b - discSqrt) / (2 * a);
  1525. if (t1 >= 0 && t1 <= 1) {
  1526. extrema[n++] = t1;
  1527. }
  1528. if (t2 >= 0 && t2 <= 1) {
  1529. extrema[n++] = t2;
  1530. }
  1531. }
  1532. }
  1533. return n;
  1534. }
  1535. /**
  1536. * 细分三次贝塞尔曲线
  1537. * @memberOf module:zrender/core/curve
  1538. * @param {number} p0
  1539. * @param {number} p1
  1540. * @param {number} p2
  1541. * @param {number} p3
  1542. * @param {number} t
  1543. * @param {Array.<number>} out
  1544. */
  1545. function cubicSubdivide(p0, p1, p2, p3, t, out) {
  1546. var p01 = (p1 - p0) * t + p0;
  1547. var p12 = (p2 - p1) * t + p1;
  1548. var p23 = (p3 - p2) * t + p2;
  1549. var p012 = (p12 - p01) * t + p01;
  1550. var p123 = (p23 - p12) * t + p12;
  1551. var p0123 = (p123 - p012) * t + p012; // Seg0
  1552. out[0] = p0;
  1553. out[1] = p01;
  1554. out[2] = p012;
  1555. out[3] = p0123; // Seg1
  1556. out[4] = p0123;
  1557. out[5] = p123;
  1558. out[6] = p23;
  1559. out[7] = p3;
  1560. }
  1561. /**
  1562. * 投射点到三次贝塞尔曲线上,返回投射距离。
  1563. * 投射点有可能会有一个或者多个,这里只返回其中距离最短的一个。
  1564. * @param {number} x0
  1565. * @param {number} y0
  1566. * @param {number} x1
  1567. * @param {number} y1
  1568. * @param {number} x2
  1569. * @param {number} y2
  1570. * @param {number} x3
  1571. * @param {number} y3
  1572. * @param {number} x
  1573. * @param {number} y
  1574. * @param {Array.<number>} [out] 投射点
  1575. * @return {number}
  1576. */
  1577. function cubicProjectPoint(x0, y0, x1, y1, x2, y2, x3, y3, x, y, out) {
  1578. // http://pomax.github.io/bezierinfo/#projections
  1579. var t;
  1580. var interval = 0.005;
  1581. var d = Infinity;
  1582. var prev;
  1583. var next;
  1584. var d1;
  1585. var d2;
  1586. _v0[0] = x;
  1587. _v0[1] = y; // 先粗略估计一下可能的最小距离的 t 值
  1588. // PENDING
  1589. for (var _t = 0; _t < 1; _t += 0.05) {
  1590. _v1[0] = cubicAt(x0, x1, x2, x3, _t);
  1591. _v1[1] = cubicAt(y0, y1, y2, y3, _t);
  1592. d1 = v2DistSquare(_v0, _v1);
  1593. if (d1 < d) {
  1594. t = _t;
  1595. d = d1;
  1596. }
  1597. }
  1598. d = Infinity; // At most 32 iteration
  1599. for (var i = 0; i < 32; i++) {
  1600. if (interval < EPSILON_NUMERIC) {
  1601. break;
  1602. }
  1603. prev = t - interval;
  1604. next = t + interval; // t - interval
  1605. _v1[0] = cubicAt(x0, x1, x2, x3, prev);
  1606. _v1[1] = cubicAt(y0, y1, y2, y3, prev);
  1607. d1 = v2DistSquare(_v1, _v0);
  1608. if (prev >= 0 && d1 < d) {
  1609. t = prev;
  1610. d = d1;
  1611. } else {
  1612. // t + interval
  1613. _v2[0] = cubicAt(x0, x1, x2, x3, next);
  1614. _v2[1] = cubicAt(y0, y1, y2, y3, next);
  1615. d2 = v2DistSquare(_v2, _v0);
  1616. if (next <= 1 && d2 < d) {
  1617. t = next;
  1618. d = d2;
  1619. } else {
  1620. interval *= 0.5;
  1621. }
  1622. }
  1623. } // t
  1624. if (out) {
  1625. out[0] = cubicAt(x0, x1, x2, x3, t);
  1626. out[1] = cubicAt(y0, y1, y2, y3, t);
  1627. } // console.log(interval, i);
  1628. return mathSqrt(d);
  1629. }
  1630. /**
  1631. * 计算二次方贝塞尔值
  1632. * @param {number} p0
  1633. * @param {number} p1
  1634. * @param {number} p2
  1635. * @param {number} t
  1636. * @return {number}
  1637. */
  1638. function quadraticAt(p0, p1, p2, t) {
  1639. var onet = 1 - t;
  1640. return onet * (onet * p0 + 2 * t * p1) + t * t * p2;
  1641. }
  1642. /**
  1643. * 计算二次方贝塞尔导数值
  1644. * @param {number} p0
  1645. * @param {number} p1
  1646. * @param {number} p2
  1647. * @param {number} t
  1648. * @return {number}
  1649. */
  1650. function quadraticDerivativeAt(p0, p1, p2, t) {
  1651. return 2 * ((1 - t) * (p1 - p0) + t * (p2 - p1));
  1652. }
  1653. /**
  1654. * 计算二次方贝塞尔方程根
  1655. * @param {number} p0
  1656. * @param {number} p1
  1657. * @param {number} p2
  1658. * @param {number} t
  1659. * @param {Array.<number>} roots
  1660. * @return {number} 有效根数目
  1661. */
  1662. function quadraticRootAt(p0, p1, p2, val, roots) {
  1663. var a = p0 - 2 * p1 + p2;
  1664. var b = 2 * (p1 - p0);
  1665. var c = p0 - val;
  1666. var n = 0;
  1667. if (isAroundZero(a)) {
  1668. if (isNotAroundZero(b)) {
  1669. var t1 = -c / b;
  1670. if (t1 >= 0 && t1 <= 1) {
  1671. roots[n++] = t1;
  1672. }
  1673. }
  1674. } else {
  1675. var disc = b * b - 4 * a * c;
  1676. if (isAroundZero(disc)) {
  1677. var t1 = -b / (2 * a);
  1678. if (t1 >= 0 && t1 <= 1) {
  1679. roots[n++] = t1;
  1680. }
  1681. } else if (disc > 0) {
  1682. var discSqrt = mathSqrt(disc);
  1683. var t1 = (-b + discSqrt) / (2 * a);
  1684. var t2 = (-b - discSqrt) / (2 * a);
  1685. if (t1 >= 0 && t1 <= 1) {
  1686. roots[n++] = t1;
  1687. }
  1688. if (t2 >= 0 && t2 <= 1) {
  1689. roots[n++] = t2;
  1690. }
  1691. }
  1692. }
  1693. return n;
  1694. }
  1695. /**
  1696. * 计算二次贝塞尔方程极限值
  1697. * @memberOf module:zrender/core/curve
  1698. * @param {number} p0
  1699. * @param {number} p1
  1700. * @param {number} p2
  1701. * @return {number}
  1702. */
  1703. function quadraticExtremum(p0, p1, p2) {
  1704. var divider = p0 + p2 - 2 * p1;
  1705. if (divider === 0) {
  1706. // p1 is center of p0 and p2
  1707. return 0.5;
  1708. } else {
  1709. return (p0 - p1) / divider;
  1710. }
  1711. }
  1712. /**
  1713. * 细分二次贝塞尔曲线
  1714. * @memberOf module:zrender/core/curve
  1715. * @param {number} p0
  1716. * @param {number} p1
  1717. * @param {number} p2
  1718. * @param {number} t
  1719. * @param {Array.<number>} out
  1720. */
  1721. function quadraticSubdivide(p0, p1, p2, t, out) {
  1722. var p01 = (p1 - p0) * t + p0;
  1723. var p12 = (p2 - p1) * t + p1;
  1724. var p012 = (p12 - p01) * t + p01; // Seg0
  1725. out[0] = p0;
  1726. out[1] = p01;
  1727. out[2] = p012; // Seg1
  1728. out[3] = p012;
  1729. out[4] = p12;
  1730. out[5] = p2;
  1731. }
  1732. /**
  1733. * 投射点到二次贝塞尔曲线上,返回投射距离。
  1734. * 投射点有可能会有一个或者多个,这里只返回其中距离最短的一个。
  1735. * @param {number} x0
  1736. * @param {number} y0
  1737. * @param {number} x1
  1738. * @param {number} y1
  1739. * @param {number} x2
  1740. * @param {number} y2
  1741. * @param {number} x
  1742. * @param {number} y
  1743. * @param {Array.<number>} out 投射点
  1744. * @return {number}
  1745. */
  1746. function quadraticProjectPoint(x0, y0, x1, y1, x2, y2, x, y, out) {
  1747. // http://pomax.github.io/bezierinfo/#projections
  1748. var t;
  1749. var interval = 0.005;
  1750. var d = Infinity;
  1751. _v0[0] = x;
  1752. _v0[1] = y; // 先粗略估计一下可能的最小距离的 t 值
  1753. // PENDING
  1754. for (var _t = 0; _t < 1; _t += 0.05) {
  1755. _v1[0] = quadraticAt(x0, x1, x2, _t);
  1756. _v1[1] = quadraticAt(y0, y1, y2, _t);
  1757. var d1 = v2DistSquare(_v0, _v1);
  1758. if (d1 < d) {
  1759. t = _t;
  1760. d = d1;
  1761. }
  1762. }
  1763. d = Infinity; // At most 32 iteration
  1764. for (var i = 0; i < 32; i++) {
  1765. if (interval < EPSILON_NUMERIC) {
  1766. break;
  1767. }
  1768. var prev = t - interval;
  1769. var next = t + interval; // t - interval
  1770. _v1[0] = quadraticAt(x0, x1, x2, prev);
  1771. _v1[1] = quadraticAt(y0, y1, y2, prev);
  1772. var d1 = v2DistSquare(_v1, _v0);
  1773. if (prev >= 0 && d1 < d) {
  1774. t = prev;
  1775. d = d1;
  1776. } else {
  1777. // t + interval
  1778. _v2[0] = quadraticAt(x0, x1, x2, next);
  1779. _v2[1] = quadraticAt(y0, y1, y2, next);
  1780. var d2 = v2DistSquare(_v2, _v0);
  1781. if (next <= 1 && d2 < d) {
  1782. t = next;
  1783. d = d2;
  1784. } else {
  1785. interval *= 0.5;
  1786. }
  1787. }
  1788. } // t
  1789. if (out) {
  1790. out[0] = quadraticAt(x0, x1, x2, t);
  1791. out[1] = quadraticAt(y0, y1, y2, t);
  1792. } // console.log(interval, i);
  1793. return mathSqrt(d);
  1794. }
  1795. exports.cubicAt = cubicAt;
  1796. exports.cubicDerivativeAt = cubicDerivativeAt;
  1797. exports.cubicRootAt = cubicRootAt;
  1798. exports.cubicExtrema = cubicExtrema;
  1799. exports.cubicSubdivide = cubicSubdivide;
  1800. exports.cubicProjectPoint = cubicProjectPoint;
  1801. exports.quadraticAt = quadraticAt;
  1802. exports.quadraticDerivativeAt = quadraticDerivativeAt;
  1803. exports.quadraticRootAt = quadraticRootAt;
  1804. exports.quadraticExtremum = quadraticExtremum;
  1805. exports.quadraticSubdivide = quadraticSubdivide;
  1806. exports.quadraticProjectPoint = quadraticProjectPoint;
  1807. /***/ }),
  1808. /* 5 */
  1809. /***/ (function(module, exports, __webpack_require__) {
  1810. var BoundingRect = __webpack_require__(3);
  1811. var imageHelper = __webpack_require__(10);
  1812. var _util = __webpack_require__(0);
  1813. var getContext = _util.getContext;
  1814. var extend = _util.extend;
  1815. var retrieve2 = _util.retrieve2;
  1816. var retrieve3 = _util.retrieve3;
  1817. var textWidthCache = {};
  1818. var textWidthCacheCounter = 0;
  1819. var TEXT_CACHE_MAX = 5000;
  1820. var STYLE_REG = /\{([a-zA-Z0-9_]+)\|([^}]*)\}/g;
  1821. var DEFAULT_FONT = '12px sans-serif'; // Avoid assign to an exported variable, for transforming to cjs.
  1822. var methods = {};
  1823. function $override(name, fn) {
  1824. methods[name] = fn;
  1825. }
  1826. /**
  1827. * @public
  1828. * @param {string} text
  1829. * @param {string} font
  1830. * @return {number} width
  1831. */
  1832. function getWidth(text, font) {
  1833. font = font || DEFAULT_FONT;
  1834. var key = text + ':' + font;
  1835. if (textWidthCache[key]) {
  1836. return textWidthCache[key];
  1837. }
  1838. var textLines = (text + '').split('\n');
  1839. var width = 0;
  1840. for (var i = 0, l = textLines.length; i < l; i++) {
  1841. // textContain.measureText may be overrided in SVG or VML
  1842. width = Math.max(measureText(textLines[i], font).width, width);
  1843. }
  1844. if (textWidthCacheCounter > TEXT_CACHE_MAX) {
  1845. textWidthCacheCounter = 0;
  1846. textWidthCache = {};
  1847. }
  1848. textWidthCacheCounter++;
  1849. textWidthCache[key] = width;
  1850. return width;
  1851. }
  1852. /**
  1853. * @public
  1854. * @param {string} text
  1855. * @param {string} font
  1856. * @param {string} [textAlign='left']
  1857. * @param {string} [textVerticalAlign='top']
  1858. * @param {Array.<number>} [textPadding]
  1859. * @param {Object} [rich]
  1860. * @param {Object} [truncate]
  1861. * @return {Object} {x, y, width, height, lineHeight}
  1862. */
  1863. function getBoundingRect(text, font, textAlign, textVerticalAlign, textPadding, rich, truncate) {
  1864. return rich ? getRichTextRect(text, font, textAlign, textVerticalAlign, textPadding, rich, truncate) : getPlainTextRect(text, font, textAlign, textVerticalAlign, textPadding, truncate);
  1865. }
  1866. function getPlainTextRect(text, font, textAlign, textVerticalAlign, textPadding, truncate) {
  1867. var contentBlock = parsePlainText(text, font, textPadding, truncate);
  1868. var outerWidth = getWidth(text, font);
  1869. if (textPadding) {
  1870. outerWidth += textPadding[1] + textPadding[3];
  1871. }
  1872. var outerHeight = contentBlock.outerHeight;
  1873. var x = adjustTextX(0, outerWidth, textAlign);
  1874. var y = adjustTextY(0, outerHeight, textVerticalAlign);
  1875. var rect = new BoundingRect(x, y, outerWidth, outerHeight);
  1876. rect.lineHeight = contentBlock.lineHeight;
  1877. return rect;
  1878. }
  1879. function getRichTextRect(text, font, textAlign, textVerticalAlign, textPadding, rich, truncate) {
  1880. var contentBlock = parseRichText(text, {
  1881. rich: rich,
  1882. truncate: truncate,
  1883. font: font,
  1884. textAlign: textAlign,
  1885. textPadding: textPadding
  1886. });
  1887. var outerWidth = contentBlock.outerWidth;
  1888. var outerHeight = contentBlock.outerHeight;
  1889. var x = adjustTextX(0, outerWidth, textAlign);
  1890. var y = adjustTextY(0, outerHeight, textVerticalAlign);
  1891. return new BoundingRect(x, y, outerWidth, outerHeight);
  1892. }
  1893. /**
  1894. * @public
  1895. * @param {number} x
  1896. * @param {number} width
  1897. * @param {string} [textAlign='left']
  1898. * @return {number} Adjusted x.
  1899. */
  1900. function adjustTextX(x, width, textAlign) {
  1901. // FIXME Right to left language
  1902. if (textAlign === 'right') {
  1903. x -= width;
  1904. } else if (textAlign === 'center') {
  1905. x -= width / 2;
  1906. }
  1907. return x;
  1908. }
  1909. /**
  1910. * @public
  1911. * @param {number} y
  1912. * @param {number} height
  1913. * @param {string} [textVerticalAlign='top']
  1914. * @return {number} Adjusted y.
  1915. */
  1916. function adjustTextY(y, height, textVerticalAlign) {
  1917. if (textVerticalAlign === 'middle') {
  1918. y -= height / 2;
  1919. } else if (textVerticalAlign === 'bottom') {
  1920. y -= height;
  1921. }
  1922. return y;
  1923. }
  1924. /**
  1925. * @public
  1926. * @param {stirng} textPosition
  1927. * @param {Object} rect {x, y, width, height}
  1928. * @param {number} distance
  1929. * @return {Object} {x, y, textAlign, textVerticalAlign}
  1930. */
  1931. function adjustTextPositionOnRect(textPosition, rect, distance) {
  1932. var x = rect.x;
  1933. var y = rect.y;
  1934. var height = rect.height;
  1935. var width = rect.width;
  1936. var halfHeight = height / 2;
  1937. var textAlign = 'left';
  1938. var textVerticalAlign = 'top';
  1939. switch (textPosition) {
  1940. case 'left':
  1941. x -= distance;
  1942. y += halfHeight;
  1943. textAlign = 'right';
  1944. textVerticalAlign = 'middle';
  1945. break;
  1946. case 'right':
  1947. x += distance + width;
  1948. y += halfHeight;
  1949. textVerticalAlign = 'middle';
  1950. break;
  1951. case 'top':
  1952. x += width / 2;
  1953. y -= distance;
  1954. textAlign = 'center';
  1955. textVerticalAlign = 'bottom';
  1956. break;
  1957. case 'bottom':
  1958. x += width / 2;
  1959. y += height + distance;
  1960. textAlign = 'center';
  1961. break;
  1962. case 'inside':
  1963. x += width / 2;
  1964. y += halfHeight;
  1965. textAlign = 'center';
  1966. textVerticalAlign = 'middle';
  1967. break;
  1968. case 'insideLeft':
  1969. x += distance;
  1970. y += halfHeight;
  1971. textVerticalAlign = 'middle';
  1972. break;
  1973. case 'insideRight':
  1974. x += width - distance;
  1975. y += halfHeight;
  1976. textAlign = 'right';
  1977. textVerticalAlign = 'middle';
  1978. break;
  1979. case 'insideTop':
  1980. x += width / 2;
  1981. y += distance;
  1982. textAlign = 'center';
  1983. break;
  1984. case 'insideBottom':
  1985. x += width / 2;
  1986. y += height - distance;
  1987. textAlign = 'center';
  1988. textVerticalAlign = 'bottom';
  1989. break;
  1990. case 'insideTopLeft':
  1991. x += distance;
  1992. y += distance;
  1993. break;
  1994. case 'insideTopRight':
  1995. x += width - distance;
  1996. y += distance;
  1997. textAlign = 'right';
  1998. break;
  1999. case 'insideBottomLeft':
  2000. x += distance;
  2001. y += height - distance;
  2002. textVerticalAlign = 'bottom';
  2003. break;
  2004. case 'insideBottomRight':
  2005. x += width - distance;
  2006. y += height - distance;
  2007. textAlign = 'right';
  2008. textVerticalAlign = 'bottom';
  2009. break;
  2010. }
  2011. return {
  2012. x: x,
  2013. y: y,
  2014. textAlign: textAlign,
  2015. textVerticalAlign: textVerticalAlign
  2016. };
  2017. }
  2018. /**
  2019. * Show ellipsis if overflow.
  2020. *
  2021. * @public
  2022. * @param {string} text
  2023. * @param {string} containerWidth
  2024. * @param {string} font
  2025. * @param {number} [ellipsis='...']
  2026. * @param {Object} [options]
  2027. * @param {number} [options.maxIterations=3]
  2028. * @param {number} [options.minChar=0] If truncate result are less
  2029. * then minChar, ellipsis will not show, which is
  2030. * better for user hint in some cases.
  2031. * @param {number} [options.placeholder=''] When all truncated, use the placeholder.
  2032. * @return {string}
  2033. */
  2034. function truncateText(text, containerWidth, font, ellipsis, options) {
  2035. if (!containerWidth) {
  2036. return '';
  2037. }
  2038. var textLines = (text + '').split('\n');
  2039. options = prepareTruncateOptions(containerWidth, font, ellipsis, options); // FIXME
  2040. // It is not appropriate that every line has '...' when truncate multiple lines.
  2041. for (var i = 0, len = textLines.length; i < len; i++) {
  2042. textLines[i] = truncateSingleLine(textLines[i], options);
  2043. }
  2044. return textLines.join('\n');
  2045. }
  2046. function prepareTruncateOptions(containerWidth, font, ellipsis, options) {
  2047. options = extend({}, options);
  2048. options.font = font;
  2049. var ellipsis = retrieve2(ellipsis, '...');
  2050. options.maxIterations = retrieve2(options.maxIterations, 2);
  2051. var minChar = options.minChar = retrieve2(options.minChar, 0); // FIXME
  2052. // Other languages?
  2053. options.cnCharWidth = getWidth('国', font); // FIXME
  2054. // Consider proportional font?
  2055. var ascCharWidth = options.ascCharWidth = getWidth('a', font);
  2056. options.placeholder = retrieve2(options.placeholder, ''); // Example 1: minChar: 3, text: 'asdfzxcv', truncate result: 'asdf', but not: 'a...'.
  2057. // Example 2: minChar: 3, text: '维度', truncate result: '维', but not: '...'.
  2058. var contentWidth = containerWidth = Math.max(0, containerWidth - 1); // Reserve some gap.
  2059. for (var i = 0; i < minChar && contentWidth >= ascCharWidth; i++) {
  2060. contentWidth -= ascCharWidth;
  2061. }
  2062. var ellipsisWidth = getWidth(ellipsis);
  2063. if (ellipsisWidth > contentWidth) {
  2064. ellipsis = '';
  2065. ellipsisWidth = 0;
  2066. }
  2067. contentWidth = containerWidth - ellipsisWidth;
  2068. options.ellipsis = ellipsis;
  2069. options.ellipsisWidth = ellipsisWidth;
  2070. options.contentWidth = contentWidth;
  2071. options.containerWidth = containerWidth;
  2072. return options;
  2073. }
  2074. function truncateSingleLine(textLine, options) {
  2075. var containerWidth = options.containerWidth;
  2076. var font = options.font;
  2077. var contentWidth = options.contentWidth;
  2078. if (!containerWidth) {
  2079. return '';
  2080. }
  2081. var lineWidth = getWidth(textLine, font);
  2082. if (lineWidth <= containerWidth) {
  2083. return textLine;
  2084. }
  2085. for (var j = 0;; j++) {
  2086. if (lineWidth <= contentWidth || j >= options.maxIterations) {
  2087. textLine += options.ellipsis;
  2088. break;
  2089. }
  2090. var subLength = j === 0 ? estimateLength(textLine, contentWidth, options.ascCharWidth, options.cnCharWidth) : lineWidth > 0 ? Math.floor(textLine.length * contentWidth / lineWidth) : 0;
  2091. textLine = textLine.substr(0, subLength);
  2092. lineWidth = getWidth(textLine, font);
  2093. }
  2094. if (textLine === '') {
  2095. textLine = options.placeholder;
  2096. }
  2097. return textLine;
  2098. }
  2099. function estimateLength(text, contentWidth, ascCharWidth, cnCharWidth) {
  2100. var width = 0;
  2101. var i = 0;
  2102. for (var len = text.length; i < len && width < contentWidth; i++) {
  2103. var charCode = text.charCodeAt(i);
  2104. width += 0 <= charCode && charCode <= 127 ? ascCharWidth : cnCharWidth;
  2105. }
  2106. return i;
  2107. }
  2108. /**
  2109. * @public
  2110. * @param {string} font
  2111. * @return {number} line height
  2112. */
  2113. function getLineHeight(font) {
  2114. // FIXME A rough approach.
  2115. return getWidth('国', font);
  2116. }
  2117. /**
  2118. * @public
  2119. * @param {string} text
  2120. * @param {string} font
  2121. * @return {Object} width
  2122. */
  2123. function measureText(text, font) {
  2124. return methods.measureText(text, font);
  2125. } // Avoid assign to an exported variable, for transforming to cjs.
  2126. methods.measureText = function (text, font) {
  2127. var ctx = getContext();
  2128. ctx.font = font || DEFAULT_FONT;
  2129. return ctx.measureText(text);
  2130. };
  2131. /**
  2132. * @public
  2133. * @param {string} text
  2134. * @param {string} font
  2135. * @param {Object} [truncate]
  2136. * @return {Object} block: {lineHeight, lines, height, outerHeight}
  2137. * Notice: for performance, do not calculate outerWidth util needed.
  2138. */
  2139. function parsePlainText(text, font, padding, truncate) {
  2140. text != null && (text += '');
  2141. var lineHeight = getLineHeight(font);
  2142. var lines = text ? text.split('\n') : [];
  2143. var height = lines.length * lineHeight;
  2144. var outerHeight = height;
  2145. if (padding) {
  2146. outerHeight += padding[0] + padding[2];
  2147. }
  2148. if (text && truncate) {
  2149. var truncOuterHeight = truncate.outerHeight;
  2150. var truncOuterWidth = truncate.outerWidth;
  2151. if (truncOuterHeight != null && outerHeight > truncOuterHeight) {
  2152. text = '';
  2153. lines = [];
  2154. } else if (truncOuterWidth != null) {
  2155. var options = prepareTruncateOptions(truncOuterWidth - (padding ? padding[1] + padding[3] : 0), font, truncate.ellipsis, {
  2156. minChar: truncate.minChar,
  2157. placeholder: truncate.placeholder
  2158. }); // FIXME
  2159. // It is not appropriate that every line has '...' when truncate multiple lines.
  2160. for (var i = 0, len = lines.length; i < len; i++) {
  2161. lines[i] = truncateSingleLine(lines[i], options);
  2162. }
  2163. }
  2164. }
  2165. return {
  2166. lines: lines,
  2167. height: height,
  2168. outerHeight: outerHeight,
  2169. lineHeight: lineHeight
  2170. };
  2171. }
  2172. /**
  2173. * For example: 'some text {a|some text}other text{b|some text}xxx{c|}xxx'
  2174. * Also consider 'bbbb{a|xxx\nzzz}xxxx\naaaa'.
  2175. *
  2176. * @public
  2177. * @param {string} text
  2178. * @param {Object} style
  2179. * @return {Object} block
  2180. * {
  2181. * width,
  2182. * height,
  2183. * lines: [{
  2184. * lineHeight,
  2185. * width,
  2186. * tokens: [[{
  2187. * styleName,
  2188. * text,
  2189. * width, // include textPadding
  2190. * height, // include textPadding
  2191. * textWidth, // pure text width
  2192. * textHeight, // pure text height
  2193. * lineHeihgt,
  2194. * font,
  2195. * textAlign,
  2196. * textVerticalAlign
  2197. * }], [...], ...]
  2198. * }, ...]
  2199. * }
  2200. * If styleName is undefined, it is plain text.
  2201. */
  2202. function parseRichText(text, style) {
  2203. var contentBlock = {
  2204. lines: [],
  2205. width: 0,
  2206. height: 0
  2207. };
  2208. text != null && (text += '');
  2209. if (!text) {
  2210. return contentBlock;
  2211. }
  2212. var lastIndex = STYLE_REG.lastIndex = 0;
  2213. var result;
  2214. while ((result = STYLE_REG.exec(text)) != null) {
  2215. var matchedIndex = result.index;
  2216. if (matchedIndex > lastIndex) {
  2217. pushTokens(contentBlock, text.substring(lastIndex, matchedIndex));
  2218. }
  2219. pushTokens(contentBlock, result[2], result[1]);
  2220. lastIndex = STYLE_REG.lastIndex;
  2221. }
  2222. if (lastIndex < text.length) {
  2223. pushTokens(contentBlock, text.substring(lastIndex, text.length));
  2224. }
  2225. var lines = contentBlock.lines;
  2226. var contentHeight = 0;
  2227. var contentWidth = 0; // For `textWidth: 100%`
  2228. var pendingList = [];
  2229. var stlPadding = style.textPadding;
  2230. var truncate = style.truncate;
  2231. var truncateWidth = truncate && truncate.outerWidth;
  2232. var truncateHeight = truncate && truncate.outerHeight;
  2233. if (stlPadding) {
  2234. truncateWidth != null && (truncateWidth -= stlPadding[1] + stlPadding[3]);
  2235. truncateHeight != null && (truncateHeight -= stlPadding[0] + stlPadding[2]);
  2236. } // Calculate layout info of tokens.
  2237. for (var i = 0; i < lines.length; i++) {
  2238. var line = lines[i];
  2239. var lineHeight = 0;
  2240. var lineWidth = 0;
  2241. for (var j = 0; j < line.tokens.length; j++) {
  2242. var token = line.tokens[j];
  2243. var tokenStyle = token.styleName && style.rich[token.styleName] || {}; // textPadding should not inherit from style.
  2244. var textPadding = token.textPadding = tokenStyle.textPadding; // textFont has been asigned to font by `normalizeStyle`.
  2245. var font = token.font = tokenStyle.font || style.font; // textHeight can be used when textVerticalAlign is specified in token.
  2246. var tokenHeight = token.textHeight = retrieve2( // textHeight should not be inherited, consider it can be specified
  2247. // as box height of the block.
  2248. tokenStyle.textHeight, getLineHeight(font));
  2249. textPadding && (tokenHeight += textPadding[0] + textPadding[2]);
  2250. token.height = tokenHeight;
  2251. token.lineHeight = retrieve3(tokenStyle.textLineHeight, style.textLineHeight, tokenHeight);
  2252. token.textAlign = tokenStyle && tokenStyle.textAlign || style.textAlign;
  2253. token.textVerticalAlign = tokenStyle && tokenStyle.textVerticalAlign || 'middle';
  2254. if (truncateHeight != null && contentHeight + token.lineHeight > truncateHeight) {
  2255. return {
  2256. lines: [],
  2257. width: 0,
  2258. height: 0
  2259. };
  2260. }
  2261. token.textWidth = getWidth(token.text, font);
  2262. var tokenWidth = tokenStyle.textWidth;
  2263. var tokenWidthNotSpecified = tokenWidth == null || tokenWidth === 'auto'; // Percent width, can be `100%`, can be used in drawing separate
  2264. // line when box width is needed to be auto.
  2265. if (typeof tokenWidth === 'string' && tokenWidth.charAt(tokenWidth.length - 1) === '%') {
  2266. token.percentWidth = tokenWidth;
  2267. pendingList.push(token);
  2268. tokenWidth = 0; // Do not truncate in this case, because there is no user case
  2269. // and it is too complicated.
  2270. } else {
  2271. if (tokenWidthNotSpecified) {
  2272. tokenWidth = token.textWidth; // FIXME: If image is not loaded and textWidth is not specified, calling
  2273. // `getBoundingRect()` will not get correct result.
  2274. var textBackgroundColor = tokenStyle.textBackgroundColor;
  2275. var bgImg = textBackgroundColor && textBackgroundColor.image; // Use cases:
  2276. // (1) If image is not loaded, it will be loaded at render phase and call
  2277. // `dirty()` and `textBackgroundColor.image` will be replaced with the loaded
  2278. // image, and then the right size will be calculated here at the next tick.
  2279. // See `graphic/helper/text.js`.
  2280. // (2) If image loaded, and `textBackgroundColor.image` is image src string,
  2281. // use `imageHelper.findExistImage` to find cached image.
  2282. // `imageHelper.findExistImage` will always be called here before
  2283. // `imageHelper.createOrUpdateImage` in `graphic/helper/text.js#renderRichText`
  2284. // which ensures that image will not be rendered before correct size calcualted.
  2285. if (bgImg) {
  2286. bgImg = imageHelper.findExistImage(bgImg);
  2287. if (imageHelper.isImageReady(bgImg)) {
  2288. tokenWidth = Math.max(tokenWidth, bgImg.width * tokenHeight / bgImg.height);
  2289. }
  2290. }
  2291. }
  2292. var paddingW = textPadding ? textPadding[1] + textPadding[3] : 0;
  2293. tokenWidth += paddingW;
  2294. var remianTruncWidth = truncateWidth != null ? truncateWidth - lineWidth : null;
  2295. if (remianTruncWidth != null && remianTruncWidth < tokenWidth) {
  2296. if (!tokenWidthNotSpecified || remianTruncWidth < paddingW) {
  2297. token.text = '';
  2298. token.textWidth = tokenWidth = 0;
  2299. } else {
  2300. token.text = truncateText(token.text, remianTruncWidth - paddingW, font, truncate.ellipsis, {
  2301. minChar: truncate.minChar
  2302. });
  2303. token.textWidth = getWidth(token.text, font);
  2304. tokenWidth = token.textWidth + paddingW;
  2305. }
  2306. }
  2307. }
  2308. lineWidth += token.width = tokenWidth;
  2309. tokenStyle && (lineHeight = Math.max(lineHeight, token.lineHeight));
  2310. }
  2311. line.width = lineWidth;
  2312. line.lineHeight = lineHeight;
  2313. contentHeight += lineHeight;
  2314. contentWidth = Math.max(contentWidth, lineWidth);
  2315. }
  2316. contentBlock.outerWidth = contentBlock.width = retrieve2(style.textWidth, contentWidth);
  2317. contentBlock.outerHeight = contentBlock.height = retrieve2(style.textHeight, contentHeight);
  2318. if (stlPadding) {
  2319. contentBlock.outerWidth += stlPadding[1] + stlPadding[3];
  2320. contentBlock.outerHeight += stlPadding[0] + stlPadding[2];
  2321. }
  2322. for (var i = 0; i < pendingList.length; i++) {
  2323. var token = pendingList[i];
  2324. var percentWidth = token.percentWidth; // Should not base on outerWidth, because token can not be placed out of padding.
  2325. token.width = parseInt(percentWidth, 10) / 100 * contentWidth;
  2326. }
  2327. return contentBlock;
  2328. }
  2329. function pushTokens(block, str, styleName) {
  2330. var isEmptyStr = str === '';
  2331. var strs = str.split('\n');
  2332. var lines = block.lines;
  2333. for (var i = 0; i < strs.length; i++) {
  2334. var text = strs[i];
  2335. var token = {
  2336. styleName: styleName,
  2337. text: text,
  2338. isLineHolder: !text && !isEmptyStr
  2339. }; // The first token should be appended to the last line.
  2340. if (!i) {
  2341. var tokens = (lines[lines.length - 1] || (lines[0] = {
  2342. tokens: []
  2343. })).tokens; // Consider cases:
  2344. // (1) ''.split('\n') => ['', '\n', ''], the '' at the first item
  2345. // (which is a placeholder) should be replaced by new token.
  2346. // (2) A image backage, where token likes {a|}.
  2347. // (3) A redundant '' will affect textAlign in line.
  2348. // (4) tokens with the same tplName should not be merged, because
  2349. // they should be displayed in different box (with border and padding).
  2350. var tokensLen = tokens.length;
  2351. tokensLen === 1 && tokens[0].isLineHolder ? tokens[0] = token : // Consider text is '', only insert when it is the "lineHolder" or
  2352. // "emptyStr". Otherwise a redundant '' will affect textAlign in line.
  2353. (text || !tokensLen || isEmptyStr) && tokens.push(token);
  2354. } // Other tokens always start a new line.
  2355. else {
  2356. // If there is '', insert it as a placeholder.
  2357. lines.push({
  2358. tokens: [token]
  2359. });
  2360. }
  2361. }
  2362. }
  2363. function makeFont(style) {
  2364. // FIXME in node-canvas fontWeight is before fontStyle
  2365. // Use `fontSize` `fontFamily` to check whether font properties are defined.
  2366. return (style.fontSize || style.fontFamily) && [style.fontStyle, style.fontWeight, (style.fontSize || 12) + 'px', // If font properties are defined, `fontFamily` should not be ignored.
  2367. style.fontFamily || 'sans-serif'].join(' ') || style.textFont || style.font;
  2368. }
  2369. exports.DEFAULT_FONT = DEFAULT_FONT;
  2370. exports.$override = $override;
  2371. exports.getWidth = getWidth;
  2372. exports.getBoundingRect = getBoundingRect;
  2373. exports.adjustTextX = adjustTextX;
  2374. exports.adjustTextY = adjustTextY;
  2375. exports.adjustTextPositionOnRect = adjustTextPositionOnRect;
  2376. exports.truncateText = truncateText;
  2377. exports.getLineHeight = getLineHeight;
  2378. exports.measureText = measureText;
  2379. exports.parsePlainText = parsePlainText;
  2380. exports.parseRichText = parseRichText;
  2381. exports.makeFont = makeFont;
  2382. /***/ }),
  2383. /* 6 */
  2384. /***/ (function(module, exports, __webpack_require__) {
  2385. var curve = __webpack_require__(4);
  2386. var vec2 = __webpack_require__(2);
  2387. var bbox = __webpack_require__(49);
  2388. var BoundingRect = __webpack_require__(3);
  2389. var _config = __webpack_require__(19);
  2390. var dpr = _config.devicePixelRatio;
  2391. /**
  2392. * Path 代理,可以在`buildPath`中用于替代`ctx`, 会保存每个path操作的命令到pathCommands属性中
  2393. * 可以用于 isInsidePath 判断以及获取boundingRect
  2394. *
  2395. * @module zrender/core/PathProxy
  2396. * @author Yi Shen (http://www.github.com/pissang)
  2397. */
  2398. // TODO getTotalLength, getPointAtLength
  2399. var CMD = {
  2400. M: 1,
  2401. L: 2,
  2402. C: 3,
  2403. Q: 4,
  2404. A: 5,
  2405. Z: 6,
  2406. // Rect
  2407. R: 7
  2408. }; // var CMD_MEM_SIZE = {
  2409. // M: 3,
  2410. // L: 3,
  2411. // C: 7,
  2412. // Q: 5,
  2413. // A: 9,
  2414. // R: 5,
  2415. // Z: 1
  2416. // };
  2417. var min = [];
  2418. var max = [];
  2419. var min2 = [];
  2420. var max2 = [];
  2421. var mathMin = Math.min;
  2422. var mathMax = Math.max;
  2423. var mathCos = Math.cos;
  2424. var mathSin = Math.sin;
  2425. var mathSqrt = Math.sqrt;
  2426. var mathAbs = Math.abs;
  2427. var hasTypedArray = typeof Float32Array != 'undefined';
  2428. /**
  2429. * @alias module:zrender/core/PathProxy
  2430. * @constructor
  2431. */
  2432. var PathProxy = function (notSaveData) {
  2433. this._saveData = !(notSaveData || false);
  2434. if (this._saveData) {
  2435. /**
  2436. * Path data. Stored as flat array
  2437. * @type {Array.<Object>}
  2438. */
  2439. this.data = [];
  2440. }
  2441. this._ctx = null;
  2442. };
  2443. /**
  2444. * 快速计算Path包围盒(并不是最小包围盒)
  2445. * @return {Object}
  2446. */
  2447. PathProxy.prototype = {
  2448. constructor: PathProxy,
  2449. _xi: 0,
  2450. _yi: 0,
  2451. _x0: 0,
  2452. _y0: 0,
  2453. // Unit x, Unit y. Provide for avoiding drawing that too short line segment
  2454. _ux: 0,
  2455. _uy: 0,
  2456. _len: 0,
  2457. _lineDash: null,
  2458. _dashOffset: 0,
  2459. _dashIdx: 0,
  2460. _dashSum: 0,
  2461. /**
  2462. * @readOnly
  2463. */
  2464. setScale: function (sx, sy) {
  2465. this._ux = mathAbs(1 / dpr / sx) || 0;
  2466. this._uy = mathAbs(1 / dpr / sy) || 0;
  2467. },
  2468. getContext: function () {
  2469. return this._ctx;
  2470. },
  2471. /**
  2472. * @param {CanvasRenderingContext2D} ctx
  2473. * @return {module:zrender/core/PathProxy}
  2474. */
  2475. beginPath: function (ctx) {
  2476. this._ctx = ctx;
  2477. ctx && ctx.beginPath();
  2478. ctx && (this.dpr = ctx.dpr); // Reset
  2479. if (this._saveData) {
  2480. this._len = 0;
  2481. }
  2482. if (this._lineDash) {
  2483. this._lineDash = null;
  2484. this._dashOffset = 0;
  2485. }
  2486. return this;
  2487. },
  2488. /**
  2489. * @param {number} x
  2490. * @param {number} y
  2491. * @return {module:zrender/core/PathProxy}
  2492. */
  2493. moveTo: function (x, y) {
  2494. this.addData(CMD.M, x, y);
  2495. this._ctx && this._ctx.moveTo(x, y); // x0, y0, xi, yi 是记录在 _dashedXXXXTo 方法中使用
  2496. // xi, yi 记录当前点, x0, y0 在 closePath 的时候回到起始点。
  2497. // 有可能在 beginPath 之后直接调用 lineTo,这时候 x0, y0 需要
  2498. // 在 lineTo 方法中记录,这里先不考虑这种情况,dashed line 也只在 IE10- 中不支持
  2499. this._x0 = x;
  2500. this._y0 = y;
  2501. this._xi = x;
  2502. this._yi = y;
  2503. return this;
  2504. },
  2505. /**
  2506. * @param {number} x
  2507. * @param {number} y
  2508. * @return {module:zrender/core/PathProxy}
  2509. */
  2510. lineTo: function (x, y) {
  2511. var exceedUnit = mathAbs(x - this._xi) > this._ux || mathAbs(y - this._yi) > this._uy // Force draw the first segment
  2512. || this._len < 5;
  2513. this.addData(CMD.L, x, y);
  2514. if (this._ctx && exceedUnit) {
  2515. this._needsDash() ? this._dashedLineTo(x, y) : this._ctx.lineTo(x, y);
  2516. }
  2517. if (exceedUnit) {
  2518. this._xi = x;
  2519. this._yi = y;
  2520. }
  2521. return this;
  2522. },
  2523. /**
  2524. * @param {number} x1
  2525. * @param {number} y1
  2526. * @param {number} x2
  2527. * @param {number} y2
  2528. * @param {number} x3
  2529. * @param {number} y3
  2530. * @return {module:zrender/core/PathProxy}
  2531. */
  2532. bezierCurveTo: function (x1, y1, x2, y2, x3, y3) {
  2533. this.addData(CMD.C, x1, y1, x2, y2, x3, y3);
  2534. if (this._ctx) {
  2535. this._needsDash() ? this._dashedBezierTo(x1, y1, x2, y2, x3, y3) : this._ctx.bezierCurveTo(x1, y1, x2, y2, x3, y3);
  2536. }
  2537. this._xi = x3;
  2538. this._yi = y3;
  2539. return this;
  2540. },
  2541. /**
  2542. * @param {number} x1
  2543. * @param {number} y1
  2544. * @param {number} x2
  2545. * @param {number} y2
  2546. * @return {module:zrender/core/PathProxy}
  2547. */
  2548. quadraticCurveTo: function (x1, y1, x2, y2) {
  2549. this.addData(CMD.Q, x1, y1, x2, y2);
  2550. if (this._ctx) {
  2551. this._needsDash() ? this._dashedQuadraticTo(x1, y1, x2, y2) : this._ctx.quadraticCurveTo(x1, y1, x2, y2);
  2552. }
  2553. this._xi = x2;
  2554. this._yi = y2;
  2555. return this;
  2556. },
  2557. /**
  2558. * @param {number} cx
  2559. * @param {number} cy
  2560. * @param {number} r
  2561. * @param {number} startAngle
  2562. * @param {number} endAngle
  2563. * @param {boolean} anticlockwise
  2564. * @return {module:zrender/core/PathProxy}
  2565. */
  2566. arc: function (cx, cy, r, startAngle, endAngle, anticlockwise) {
  2567. this.addData(CMD.A, cx, cy, r, r, startAngle, endAngle - startAngle, 0, anticlockwise ? 0 : 1);
  2568. this._ctx && this._ctx.arc(cx, cy, r, startAngle, endAngle, anticlockwise);
  2569. this._xi = mathCos(endAngle) * r + cx;
  2570. this._yi = mathSin(endAngle) * r + cx;
  2571. return this;
  2572. },
  2573. // TODO
  2574. arcTo: function (x1, y1, x2, y2, radius) {
  2575. if (this._ctx) {
  2576. this._ctx.arcTo(x1, y1, x2, y2, radius);
  2577. }
  2578. return this;
  2579. },
  2580. // TODO
  2581. rect: function (x, y, w, h) {
  2582. this._ctx && this._ctx.rect(x, y, w, h);
  2583. this.addData(CMD.R, x, y, w, h);
  2584. return this;
  2585. },
  2586. /**
  2587. * @return {module:zrender/core/PathProxy}
  2588. */
  2589. closePath: function () {
  2590. this.addData(CMD.Z);
  2591. var ctx = this._ctx;
  2592. var x0 = this._x0;
  2593. var y0 = this._y0;
  2594. if (ctx) {
  2595. this._needsDash() && this._dashedLineTo(x0, y0);
  2596. ctx.closePath();
  2597. }
  2598. this._xi = x0;
  2599. this._yi = y0;
  2600. return this;
  2601. },
  2602. /**
  2603. * Context 从外部传入,因为有可能是 rebuildPath 完之后再 fill。
  2604. * stroke 同样
  2605. * @param {CanvasRenderingContext2D} ctx
  2606. * @return {module:zrender/core/PathProxy}
  2607. */
  2608. fill: function (ctx) {
  2609. ctx && ctx.fill();
  2610. this.toStatic();
  2611. },
  2612. /**
  2613. * @param {CanvasRenderingContext2D} ctx
  2614. * @return {module:zrender/core/PathProxy}
  2615. */
  2616. stroke: function (ctx) {
  2617. ctx && ctx.stroke();
  2618. this.toStatic();
  2619. },
  2620. /**
  2621. * 必须在其它绘制命令前调用
  2622. * Must be invoked before all other path drawing methods
  2623. * @return {module:zrender/core/PathProxy}
  2624. */
  2625. setLineDash: function (lineDash) {
  2626. if (lineDash instanceof Array) {
  2627. this._lineDash = lineDash;
  2628. this._dashIdx = 0;
  2629. var lineDashSum = 0;
  2630. for (var i = 0; i < lineDash.length; i++) {
  2631. lineDashSum += lineDash[i];
  2632. }
  2633. this._dashSum = lineDashSum;
  2634. }
  2635. return this;
  2636. },
  2637. /**
  2638. * 必须在其它绘制命令前调用
  2639. * Must be invoked before all other path drawing methods
  2640. * @return {module:zrender/core/PathProxy}
  2641. */
  2642. setLineDashOffset: function (offset) {
  2643. this._dashOffset = offset;
  2644. return this;
  2645. },
  2646. /**
  2647. *
  2648. * @return {boolean}
  2649. */
  2650. len: function () {
  2651. return this._len;
  2652. },
  2653. /**
  2654. * 直接设置 Path 数据
  2655. */
  2656. setData: function (data) {
  2657. var len = data.length;
  2658. if (!(this.data && this.data.length == len) && hasTypedArray) {
  2659. this.data = new Float32Array(len);
  2660. }
  2661. for (var i = 0; i < len; i++) {
  2662. this.data[i] = data[i];
  2663. }
  2664. this._len = len;
  2665. },
  2666. /**
  2667. * 添加子路径
  2668. * @param {module:zrender/core/PathProxy|Array.<module:zrender/core/PathProxy>} path
  2669. */
  2670. appendPath: function (path) {
  2671. if (!(path instanceof Array)) {
  2672. path = [path];
  2673. }
  2674. var len = path.length;
  2675. var appendSize = 0;
  2676. var offset = this._len;
  2677. for (var i = 0; i < len; i++) {
  2678. appendSize += path[i].len();
  2679. }
  2680. if (hasTypedArray && this.data instanceof Float32Array) {
  2681. this.data = new Float32Array(offset + appendSize);
  2682. }
  2683. for (var i = 0; i < len; i++) {
  2684. var appendPathData = path[i].data;
  2685. for (var k = 0; k < appendPathData.length; k++) {
  2686. this.data[offset++] = appendPathData[k];
  2687. }
  2688. }
  2689. this._len = offset;
  2690. },
  2691. /**
  2692. * 填充 Path 数据。
  2693. * 尽量复用而不申明新的数组。大部分图形重绘的指令数据长度都是不变的。
  2694. */
  2695. addData: function (cmd) {
  2696. if (!this._saveData) {
  2697. return;
  2698. }
  2699. var data = this.data;
  2700. if (this._len + arguments.length > data.length) {
  2701. // 因为之前的数组已经转换成静态的 Float32Array
  2702. // 所以不够用时需要扩展一个新的动态数组
  2703. this._expandData();
  2704. data = this.data;
  2705. }
  2706. for (var i = 0; i < arguments.length; i++) {
  2707. data[this._len++] = arguments[i];
  2708. }
  2709. this._prevCmd = cmd;
  2710. },
  2711. _expandData: function () {
  2712. // Only if data is Float32Array
  2713. if (!(this.data instanceof Array)) {
  2714. var newData = [];
  2715. for (var i = 0; i < this._len; i++) {
  2716. newData[i] = this.data[i];
  2717. }
  2718. this.data = newData;
  2719. }
  2720. },
  2721. /**
  2722. * If needs js implemented dashed line
  2723. * @return {boolean}
  2724. * @private
  2725. */
  2726. _needsDash: function () {
  2727. return this._lineDash;
  2728. },
  2729. _dashedLineTo: function (x1, y1) {
  2730. var dashSum = this._dashSum;
  2731. var offset = this._dashOffset;
  2732. var lineDash = this._lineDash;
  2733. var ctx = this._ctx;
  2734. var x0 = this._xi;
  2735. var y0 = this._yi;
  2736. var dx = x1 - x0;
  2737. var dy = y1 - y0;
  2738. var dist = mathSqrt(dx * dx + dy * dy);
  2739. var x = x0;
  2740. var y = y0;
  2741. var dash;
  2742. var nDash = lineDash.length;
  2743. var idx;
  2744. dx /= dist;
  2745. dy /= dist;
  2746. if (offset < 0) {
  2747. // Convert to positive offset
  2748. offset = dashSum + offset;
  2749. }
  2750. offset %= dashSum;
  2751. x -= offset * dx;
  2752. y -= offset * dy;
  2753. while (dx > 0 && x <= x1 || dx < 0 && x >= x1 || dx == 0 && (dy > 0 && y <= y1 || dy < 0 && y >= y1)) {
  2754. idx = this._dashIdx;
  2755. dash = lineDash[idx];
  2756. x += dx * dash;
  2757. y += dy * dash;
  2758. this._dashIdx = (idx + 1) % nDash; // Skip positive offset
  2759. if (dx > 0 && x < x0 || dx < 0 && x > x0 || dy > 0 && y < y0 || dy < 0 && y > y0) {
  2760. continue;
  2761. }
  2762. ctx[idx % 2 ? 'moveTo' : 'lineTo'](dx >= 0 ? mathMin(x, x1) : mathMax(x, x1), dy >= 0 ? mathMin(y, y1) : mathMax(y, y1));
  2763. } // Offset for next lineTo
  2764. dx = x - x1;
  2765. dy = y - y1;
  2766. this._dashOffset = -mathSqrt(dx * dx + dy * dy);
  2767. },
  2768. // Not accurate dashed line to
  2769. _dashedBezierTo: function (x1, y1, x2, y2, x3, y3) {
  2770. var dashSum = this._dashSum;
  2771. var offset = this._dashOffset;
  2772. var lineDash = this._lineDash;
  2773. var ctx = this._ctx;
  2774. var x0 = this._xi;
  2775. var y0 = this._yi;
  2776. var t;
  2777. var dx;
  2778. var dy;
  2779. var cubicAt = curve.cubicAt;
  2780. var bezierLen = 0;
  2781. var idx = this._dashIdx;
  2782. var nDash = lineDash.length;
  2783. var x;
  2784. var y;
  2785. var tmpLen = 0;
  2786. if (offset < 0) {
  2787. // Convert to positive offset
  2788. offset = dashSum + offset;
  2789. }
  2790. offset %= dashSum; // Bezier approx length
  2791. for (t = 0; t < 1; t += 0.1) {
  2792. dx = cubicAt(x0, x1, x2, x3, t + 0.1) - cubicAt(x0, x1, x2, x3, t);
  2793. dy = cubicAt(y0, y1, y2, y3, t + 0.1) - cubicAt(y0, y1, y2, y3, t);
  2794. bezierLen += mathSqrt(dx * dx + dy * dy);
  2795. } // Find idx after add offset
  2796. for (; idx < nDash; idx++) {
  2797. tmpLen += lineDash[idx];
  2798. if (tmpLen > offset) {
  2799. break;
  2800. }
  2801. }
  2802. t = (tmpLen - offset) / bezierLen;
  2803. while (t <= 1) {
  2804. x = cubicAt(x0, x1, x2, x3, t);
  2805. y = cubicAt(y0, y1, y2, y3, t); // Use line to approximate dashed bezier
  2806. // Bad result if dash is long
  2807. idx % 2 ? ctx.moveTo(x, y) : ctx.lineTo(x, y);
  2808. t += lineDash[idx] / bezierLen;
  2809. idx = (idx + 1) % nDash;
  2810. } // Finish the last segment and calculate the new offset
  2811. idx % 2 !== 0 && ctx.lineTo(x3, y3);
  2812. dx = x3 - x;
  2813. dy = y3 - y;
  2814. this._dashOffset = -mathSqrt(dx * dx + dy * dy);
  2815. },
  2816. _dashedQuadraticTo: function (x1, y1, x2, y2) {
  2817. // Convert quadratic to cubic using degree elevation
  2818. var x3 = x2;
  2819. var y3 = y2;
  2820. x2 = (x2 + 2 * x1) / 3;
  2821. y2 = (y2 + 2 * y1) / 3;
  2822. x1 = (this._xi + 2 * x1) / 3;
  2823. y1 = (this._yi + 2 * y1) / 3;
  2824. this._dashedBezierTo(x1, y1, x2, y2, x3, y3);
  2825. },
  2826. /**
  2827. * 转成静态的 Float32Array 减少堆内存占用
  2828. * Convert dynamic array to static Float32Array
  2829. */
  2830. toStatic: function () {
  2831. var data = this.data;
  2832. if (data instanceof Array) {
  2833. data.length = this._len;
  2834. if (hasTypedArray) {
  2835. this.data = new Float32Array(data);
  2836. }
  2837. }
  2838. },
  2839. /**
  2840. * @return {module:zrender/core/BoundingRect}
  2841. */
  2842. getBoundingRect: function () {
  2843. min[0] = min[1] = min2[0] = min2[1] = Number.MAX_VALUE;
  2844. max[0] = max[1] = max2[0] = max2[1] = -Number.MAX_VALUE;
  2845. var data = this.data;
  2846. var xi = 0;
  2847. var yi = 0;
  2848. var x0 = 0;
  2849. var y0 = 0;
  2850. for (var i = 0; i < data.length;) {
  2851. var cmd = data[i++];
  2852. if (i == 1) {
  2853. // 如果第一个命令是 L, C, Q
  2854. // 则 previous point 同绘制命令的第一个 point
  2855. //
  2856. // 第一个命令为 Arc 的情况下会在后面特殊处理
  2857. xi = data[i];
  2858. yi = data[i + 1];
  2859. x0 = xi;
  2860. y0 = yi;
  2861. }
  2862. switch (cmd) {
  2863. case CMD.M:
  2864. // moveTo 命令重新创建一个新的 subpath, 并且更新新的起点
  2865. // 在 closePath 的时候使用
  2866. x0 = data[i++];
  2867. y0 = data[i++];
  2868. xi = x0;
  2869. yi = y0;
  2870. min2[0] = x0;
  2871. min2[1] = y0;
  2872. max2[0] = x0;
  2873. max2[1] = y0;
  2874. break;
  2875. case CMD.L:
  2876. bbox.fromLine(xi, yi, data[i], data[i + 1], min2, max2);
  2877. xi = data[i++];
  2878. yi = data[i++];
  2879. break;
  2880. case CMD.C:
  2881. bbox.fromCubic(xi, yi, data[i++], data[i++], data[i++], data[i++], data[i], data[i + 1], min2, max2);
  2882. xi = data[i++];
  2883. yi = data[i++];
  2884. break;
  2885. case CMD.Q:
  2886. bbox.fromQuadratic(xi, yi, data[i++], data[i++], data[i], data[i + 1], min2, max2);
  2887. xi = data[i++];
  2888. yi = data[i++];
  2889. break;
  2890. case CMD.A:
  2891. // TODO Arc 判断的开销比较大
  2892. var cx = data[i++];
  2893. var cy = data[i++];
  2894. var rx = data[i++];
  2895. var ry = data[i++];
  2896. var startAngle = data[i++];
  2897. var endAngle = data[i++] + startAngle; // TODO Arc 旋转
  2898. var psi = data[i++];
  2899. var anticlockwise = 1 - data[i++];
  2900. if (i == 1) {
  2901. // 直接使用 arc 命令
  2902. // 第一个命令起点还未定义
  2903. x0 = mathCos(startAngle) * rx + cx;
  2904. y0 = mathSin(startAngle) * ry + cy;
  2905. }
  2906. bbox.fromArc(cx, cy, rx, ry, startAngle, endAngle, anticlockwise, min2, max2);
  2907. xi = mathCos(endAngle) * rx + cx;
  2908. yi = mathSin(endAngle) * ry + cy;
  2909. break;
  2910. case CMD.R:
  2911. x0 = xi = data[i++];
  2912. y0 = yi = data[i++];
  2913. var width = data[i++];
  2914. var height = data[i++]; // Use fromLine
  2915. bbox.fromLine(x0, y0, x0 + width, y0 + height, min2, max2);
  2916. break;
  2917. case CMD.Z:
  2918. xi = x0;
  2919. yi = y0;
  2920. break;
  2921. } // Union
  2922. vec2.min(min, min, min2);
  2923. vec2.max(max, max, max2);
  2924. } // No data
  2925. if (i === 0) {
  2926. min[0] = min[1] = max[0] = max[1] = 0;
  2927. }
  2928. return new BoundingRect(min[0], min[1], max[0] - min[0], max[1] - min[1]);
  2929. },
  2930. /**
  2931. * Rebuild path from current data
  2932. * Rebuild path will not consider javascript implemented line dash.
  2933. * @param {CanvasRenderingContext2D} ctx
  2934. */
  2935. rebuildPath: function (ctx) {
  2936. var d = this.data;
  2937. var x0, y0;
  2938. var xi, yi;
  2939. var x, y;
  2940. var ux = this._ux;
  2941. var uy = this._uy;
  2942. var len = this._len;
  2943. for (var i = 0; i < len;) {
  2944. var cmd = d[i++];
  2945. if (i == 1) {
  2946. // 如果第一个命令是 L, C, Q
  2947. // 则 previous point 同绘制命令的第一个 point
  2948. //
  2949. // 第一个命令为 Arc 的情况下会在后面特殊处理
  2950. xi = d[i];
  2951. yi = d[i + 1];
  2952. x0 = xi;
  2953. y0 = yi;
  2954. }
  2955. switch (cmd) {
  2956. case CMD.M:
  2957. x0 = xi = d[i++];
  2958. y0 = yi = d[i++];
  2959. ctx.moveTo(xi, yi);
  2960. break;
  2961. case CMD.L:
  2962. x = d[i++];
  2963. y = d[i++]; // Not draw too small seg between
  2964. if (mathAbs(x - xi) > ux || mathAbs(y - yi) > uy || i === len - 1) {
  2965. ctx.lineTo(x, y);
  2966. xi = x;
  2967. yi = y;
  2968. }
  2969. break;
  2970. case CMD.C:
  2971. ctx.bezierCurveTo(d[i++], d[i++], d[i++], d[i++], d[i++], d[i++]);
  2972. xi = d[i - 2];
  2973. yi = d[i - 1];
  2974. break;
  2975. case CMD.Q:
  2976. ctx.quadraticCurveTo(d[i++], d[i++], d[i++], d[i++]);
  2977. xi = d[i - 2];
  2978. yi = d[i - 1];
  2979. break;
  2980. case CMD.A:
  2981. var cx = d[i++];
  2982. var cy = d[i++];
  2983. var rx = d[i++];
  2984. var ry = d[i++];
  2985. var theta = d[i++];
  2986. var dTheta = d[i++];
  2987. var psi = d[i++];
  2988. var fs = d[i++];
  2989. var r = rx > ry ? rx : ry;
  2990. var scaleX = rx > ry ? 1 : rx / ry;
  2991. var scaleY = rx > ry ? ry / rx : 1;
  2992. var isEllipse = Math.abs(rx - ry) > 1e-3;
  2993. var endAngle = theta + dTheta;
  2994. if (isEllipse) {
  2995. ctx.translate(cx, cy);
  2996. ctx.rotate(psi);
  2997. ctx.scale(scaleX, scaleY);
  2998. ctx.arc(0, 0, r, theta, endAngle, 1 - fs);
  2999. ctx.scale(1 / scaleX, 1 / scaleY);
  3000. ctx.rotate(-psi);
  3001. ctx.translate(-cx, -cy);
  3002. } else {
  3003. ctx.arc(cx, cy, r, theta, endAngle, 1 - fs);
  3004. }
  3005. if (i == 1) {
  3006. // 直接使用 arc 命令
  3007. // 第一个命令起点还未定义
  3008. x0 = mathCos(theta) * rx + cx;
  3009. y0 = mathSin(theta) * ry + cy;
  3010. }
  3011. xi = mathCos(endAngle) * rx + cx;
  3012. yi = mathSin(endAngle) * ry + cy;
  3013. break;
  3014. case CMD.R:
  3015. x0 = xi = d[i];
  3016. y0 = yi = d[i + 1];
  3017. ctx.rect(d[i++], d[i++], d[i++], d[i++]);
  3018. break;
  3019. case CMD.Z:
  3020. ctx.closePath();
  3021. xi = x0;
  3022. yi = y0;
  3023. }
  3024. }
  3025. }
  3026. };
  3027. PathProxy.CMD = CMD;
  3028. var _default = PathProxy;
  3029. module.exports = _default;
  3030. /***/ }),
  3031. /* 7 */
  3032. /***/ (function(module, exports) {
  3033. module.exports = __WEBPACK_EXTERNAL_MODULE_7__;
  3034. /***/ }),
  3035. /* 8 */
  3036. /***/ (function(module, exports) {
  3037. /**
  3038. * 3x2矩阵操作类
  3039. * @exports zrender/tool/matrix
  3040. */
  3041. var ArrayCtor = typeof Float32Array === 'undefined' ? Array : Float32Array;
  3042. /**
  3043. * 创建一个单位矩阵
  3044. * @return {Float32Array|Array.<number>}
  3045. */
  3046. function create() {
  3047. var out = new ArrayCtor(6);
  3048. identity(out);
  3049. return out;
  3050. }
  3051. /**
  3052. * 设置矩阵为单位矩阵
  3053. * @param {Float32Array|Array.<number>} out
  3054. */
  3055. function identity(out) {
  3056. out[0] = 1;
  3057. out[1] = 0;
  3058. out[2] = 0;
  3059. out[3] = 1;
  3060. out[4] = 0;
  3061. out[5] = 0;
  3062. return out;
  3063. }
  3064. /**
  3065. * 复制矩阵
  3066. * @param {Float32Array|Array.<number>} out
  3067. * @param {Float32Array|Array.<number>} m
  3068. */
  3069. function copy(out, m) {
  3070. out[0] = m[0];
  3071. out[1] = m[1];
  3072. out[2] = m[2];
  3073. out[3] = m[3];
  3074. out[4] = m[4];
  3075. out[5] = m[5];
  3076. return out;
  3077. }
  3078. /**
  3079. * 矩阵相乘
  3080. * @param {Float32Array|Array.<number>} out
  3081. * @param {Float32Array|Array.<number>} m1
  3082. * @param {Float32Array|Array.<number>} m2
  3083. */
  3084. function mul(out, m1, m2) {
  3085. // Consider matrix.mul(m, m2, m);
  3086. // where out is the same as m2.
  3087. // So use temp variable to escape error.
  3088. var out0 = m1[0] * m2[0] + m1[2] * m2[1];
  3089. var out1 = m1[1] * m2[0] + m1[3] * m2[1];
  3090. var out2 = m1[0] * m2[2] + m1[2] * m2[3];
  3091. var out3 = m1[1] * m2[2] + m1[3] * m2[3];
  3092. var out4 = m1[0] * m2[4] + m1[2] * m2[5] + m1[4];
  3093. var out5 = m1[1] * m2[4] + m1[3] * m2[5] + m1[5];
  3094. out[0] = out0;
  3095. out[1] = out1;
  3096. out[2] = out2;
  3097. out[3] = out3;
  3098. out[4] = out4;
  3099. out[5] = out5;
  3100. return out;
  3101. }
  3102. /**
  3103. * 平移变换
  3104. * @param {Float32Array|Array.<number>} out
  3105. * @param {Float32Array|Array.<number>} a
  3106. * @param {Float32Array|Array.<number>} v
  3107. */
  3108. function translate(out, a, v) {
  3109. out[0] = a[0];
  3110. out[1] = a[1];
  3111. out[2] = a[2];
  3112. out[3] = a[3];
  3113. out[4] = a[4] + v[0];
  3114. out[5] = a[5] + v[1];
  3115. return out;
  3116. }
  3117. /**
  3118. * 旋转变换
  3119. * @param {Float32Array|Array.<number>} out
  3120. * @param {Float32Array|Array.<number>} a
  3121. * @param {number} rad
  3122. */
  3123. function rotate(out, a, rad) {
  3124. var aa = a[0];
  3125. var ac = a[2];
  3126. var atx = a[4];
  3127. var ab = a[1];
  3128. var ad = a[3];
  3129. var aty = a[5];
  3130. var st = Math.sin(rad);
  3131. var ct = Math.cos(rad);
  3132. out[0] = aa * ct + ab * st;
  3133. out[1] = -aa * st + ab * ct;
  3134. out[2] = ac * ct + ad * st;
  3135. out[3] = -ac * st + ct * ad;
  3136. out[4] = ct * atx + st * aty;
  3137. out[5] = ct * aty - st * atx;
  3138. return out;
  3139. }
  3140. /**
  3141. * 缩放变换
  3142. * @param {Float32Array|Array.<number>} out
  3143. * @param {Float32Array|Array.<number>} a
  3144. * @param {Float32Array|Array.<number>} v
  3145. */
  3146. function scale(out, a, v) {
  3147. var vx = v[0];
  3148. var vy = v[1];
  3149. out[0] = a[0] * vx;
  3150. out[1] = a[1] * vy;
  3151. out[2] = a[2] * vx;
  3152. out[3] = a[3] * vy;
  3153. out[4] = a[4] * vx;
  3154. out[5] = a[5] * vy;
  3155. return out;
  3156. }
  3157. /**
  3158. * 求逆矩阵
  3159. * @param {Float32Array|Array.<number>} out
  3160. * @param {Float32Array|Array.<number>} a
  3161. */
  3162. function invert(out, a) {
  3163. var aa = a[0];
  3164. var ac = a[2];
  3165. var atx = a[4];
  3166. var ab = a[1];
  3167. var ad = a[3];
  3168. var aty = a[5];
  3169. var det = aa * ad - ab * ac;
  3170. if (!det) {
  3171. return null;
  3172. }
  3173. det = 1.0 / det;
  3174. out[0] = ad * det;
  3175. out[1] = -ab * det;
  3176. out[2] = -ac * det;
  3177. out[3] = aa * det;
  3178. out[4] = (ac * aty - ad * atx) * det;
  3179. out[5] = (ab * atx - aa * aty) * det;
  3180. return out;
  3181. }
  3182. exports.create = create;
  3183. exports.identity = identity;
  3184. exports.copy = copy;
  3185. exports.mul = mul;
  3186. exports.translate = translate;
  3187. exports.rotate = rotate;
  3188. exports.scale = scale;
  3189. exports.invert = invert;
  3190. /***/ }),
  3191. /* 9 */
  3192. /***/ (function(module, exports, __webpack_require__) {
  3193. var zrUtil = __webpack_require__(0);
  3194. var RADIAN_EPSILON = 1e-4;
  3195. function _trim(str) {
  3196. return str.replace(/^\s+/, '').replace(/\s+$/, '');
  3197. }
  3198. /**
  3199. * Linear mapping a value from domain to range
  3200. * @memberOf module:echarts/util/number
  3201. * @param {(number|Array.<number>)} val
  3202. * @param {Array.<number>} domain Domain extent domain[0] can be bigger than domain[1]
  3203. * @param {Array.<number>} range Range extent range[0] can be bigger than range[1]
  3204. * @param {boolean} clamp
  3205. * @return {(number|Array.<number>}
  3206. */
  3207. function linearMap(val, domain, range, clamp) {
  3208. var subDomain = domain[1] - domain[0];
  3209. var subRange = range[1] - range[0];
  3210. if (subDomain === 0) {
  3211. return subRange === 0 ? range[0] : (range[0] + range[1]) / 2;
  3212. } // Avoid accuracy problem in edge, such as
  3213. // 146.39 - 62.83 === 83.55999999999999.
  3214. // See echarts/test/ut/spec/util/number.js#linearMap#accuracyError
  3215. // It is a little verbose for efficiency considering this method
  3216. // is a hotspot.
  3217. if (clamp) {
  3218. if (subDomain > 0) {
  3219. if (val <= domain[0]) {
  3220. return range[0];
  3221. } else if (val >= domain[1]) {
  3222. return range[1];
  3223. }
  3224. } else {
  3225. if (val >= domain[0]) {
  3226. return range[0];
  3227. } else if (val <= domain[1]) {
  3228. return range[1];
  3229. }
  3230. }
  3231. } else {
  3232. if (val === domain[0]) {
  3233. return range[0];
  3234. }
  3235. if (val === domain[1]) {
  3236. return range[1];
  3237. }
  3238. }
  3239. return (val - domain[0]) / subDomain * subRange + range[0];
  3240. }
  3241. /**
  3242. * Convert a percent string to absolute number.
  3243. * Returns NaN if percent is not a valid string or number
  3244. * @memberOf module:echarts/util/number
  3245. * @param {string|number} percent
  3246. * @param {number} all
  3247. * @return {number}
  3248. */
  3249. function parsePercent(percent, all) {
  3250. switch (percent) {
  3251. case 'center':
  3252. case 'middle':
  3253. percent = '50%';
  3254. break;
  3255. case 'left':
  3256. case 'top':
  3257. percent = '0%';
  3258. break;
  3259. case 'right':
  3260. case 'bottom':
  3261. percent = '100%';
  3262. break;
  3263. }
  3264. if (typeof percent === 'string') {
  3265. if (_trim(percent).match(/%$/)) {
  3266. return parseFloat(percent) / 100 * all;
  3267. }
  3268. return parseFloat(percent);
  3269. }
  3270. return percent == null ? NaN : +percent;
  3271. }
  3272. /**
  3273. * (1) Fix rounding error of float numbers.
  3274. * (2) Support return string to avoid scientific notation like '3.5e-7'.
  3275. *
  3276. * @param {number} x
  3277. * @param {number} [precision]
  3278. * @param {boolean} [returnStr]
  3279. * @return {number|string}
  3280. */
  3281. function round(x, precision, returnStr) {
  3282. if (precision == null) {
  3283. precision = 10;
  3284. } // Avoid range error
  3285. precision = Math.min(Math.max(0, precision), 20);
  3286. x = (+x).toFixed(precision);
  3287. return returnStr ? x : +x;
  3288. }
  3289. function asc(arr) {
  3290. arr.sort(function (a, b) {
  3291. return a - b;
  3292. });
  3293. return arr;
  3294. }
  3295. /**
  3296. * Get precision
  3297. * @param {number} val
  3298. */
  3299. function getPrecision(val) {
  3300. val = +val;
  3301. if (isNaN(val)) {
  3302. return 0;
  3303. } // It is much faster than methods converting number to string as follows
  3304. // var tmp = val.toString();
  3305. // return tmp.length - 1 - tmp.indexOf('.');
  3306. // especially when precision is low
  3307. var e = 1;
  3308. var count = 0;
  3309. while (Math.round(val * e) / e !== val) {
  3310. e *= 10;
  3311. count++;
  3312. }
  3313. return count;
  3314. }
  3315. /**
  3316. * @param {string|number} val
  3317. * @return {number}
  3318. */
  3319. function getPrecisionSafe(val) {
  3320. var str = val.toString(); // Consider scientific notation: '3.4e-12' '3.4e+12'
  3321. var eIndex = str.indexOf('e');
  3322. if (eIndex > 0) {
  3323. var precision = +str.slice(eIndex + 1);
  3324. return precision < 0 ? -precision : 0;
  3325. } else {
  3326. var dotIndex = str.indexOf('.');
  3327. return dotIndex < 0 ? 0 : str.length - 1 - dotIndex;
  3328. }
  3329. }
  3330. /**
  3331. * Minimal dicernible data precisioin according to a single pixel.
  3332. *
  3333. * @param {Array.<number>} dataExtent
  3334. * @param {Array.<number>} pixelExtent
  3335. * @return {number} precision
  3336. */
  3337. function getPixelPrecision(dataExtent, pixelExtent) {
  3338. var log = Math.log;
  3339. var LN10 = Math.LN10;
  3340. var dataQuantity = Math.floor(log(dataExtent[1] - dataExtent[0]) / LN10);
  3341. var sizeQuantity = Math.round(log(Math.abs(pixelExtent[1] - pixelExtent[0])) / LN10); // toFixed() digits argument must be between 0 and 20.
  3342. var precision = Math.min(Math.max(-dataQuantity + sizeQuantity, 0), 20);
  3343. return !isFinite(precision) ? 20 : precision;
  3344. }
  3345. /**
  3346. * Get a data of given precision, assuring the sum of percentages
  3347. * in valueList is 1.
  3348. * The largest remainer method is used.
  3349. * https://en.wikipedia.org/wiki/Largest_remainder_method
  3350. *
  3351. * @param {Array.<number>} valueList a list of all data
  3352. * @param {number} idx index of the data to be processed in valueList
  3353. * @param {number} precision integer number showing digits of precision
  3354. * @return {number} percent ranging from 0 to 100
  3355. */
  3356. function getPercentWithPrecision(valueList, idx, precision) {
  3357. if (!valueList[idx]) {
  3358. return 0;
  3359. }
  3360. var sum = zrUtil.reduce(valueList, function (acc, val) {
  3361. return acc + (isNaN(val) ? 0 : val);
  3362. }, 0);
  3363. if (sum === 0) {
  3364. return 0;
  3365. }
  3366. var digits = Math.pow(10, precision);
  3367. var votesPerQuota = zrUtil.map(valueList, function (val) {
  3368. return (isNaN(val) ? 0 : val) / sum * digits * 100;
  3369. });
  3370. var targetSeats = digits * 100;
  3371. var seats = zrUtil.map(votesPerQuota, function (votes) {
  3372. // Assign automatic seats.
  3373. return Math.floor(votes);
  3374. });
  3375. var currentSum = zrUtil.reduce(seats, function (acc, val) {
  3376. return acc + val;
  3377. }, 0);
  3378. var remainder = zrUtil.map(votesPerQuota, function (votes, idx) {
  3379. return votes - seats[idx];
  3380. }); // Has remainding votes.
  3381. while (currentSum < targetSeats) {
  3382. // Find next largest remainder.
  3383. var max = Number.NEGATIVE_INFINITY;
  3384. var maxId = null;
  3385. for (var i = 0, len = remainder.length; i < len; ++i) {
  3386. if (remainder[i] > max) {
  3387. max = remainder[i];
  3388. maxId = i;
  3389. }
  3390. } // Add a vote to max remainder.
  3391. ++seats[maxId];
  3392. remainder[maxId] = 0;
  3393. ++currentSum;
  3394. }
  3395. return seats[idx] / digits;
  3396. } // Number.MAX_SAFE_INTEGER, ie do not support.
  3397. var MAX_SAFE_INTEGER = 9007199254740991;
  3398. /**
  3399. * To 0 - 2 * PI, considering negative radian.
  3400. * @param {number} radian
  3401. * @return {number}
  3402. */
  3403. function remRadian(radian) {
  3404. var pi2 = Math.PI * 2;
  3405. return (radian % pi2 + pi2) % pi2;
  3406. }
  3407. /**
  3408. * @param {type} radian
  3409. * @return {boolean}
  3410. */
  3411. function isRadianAroundZero(val) {
  3412. return val > -RADIAN_EPSILON && val < RADIAN_EPSILON;
  3413. }
  3414. var TIME_REG = /^(?:(\d{4})(?:[-\/](\d{1,2})(?:[-\/](\d{1,2})(?:[T ](\d{1,2})(?::(\d\d)(?::(\d\d)(?:[.,](\d+))?)?)?(Z|[\+\-]\d\d:?\d\d)?)?)?)?)?$/; // jshint ignore:line
  3415. /**
  3416. * @param {string|Date|number} value These values can be accepted:
  3417. * + An instance of Date, represent a time in its own time zone.
  3418. * + Or string in a subset of ISO 8601, only including:
  3419. * + only year, month, date: '2012-03', '2012-03-01', '2012-03-01 05', '2012-03-01 05:06',
  3420. * + separated with T or space: '2012-03-01T12:22:33.123', '2012-03-01 12:22:33.123',
  3421. * + time zone: '2012-03-01T12:22:33Z', '2012-03-01T12:22:33+8000', '2012-03-01T12:22:33-05:00',
  3422. * all of which will be treated as local time if time zone is not specified
  3423. * (see <https://momentjs.com/>).
  3424. * + Or other string format, including (all of which will be treated as loacal time):
  3425. * '2012', '2012-3-1', '2012/3/1', '2012/03/01',
  3426. * '2009/6/12 2:00', '2009/6/12 2:05:08', '2009/6/12 2:05:08.123'
  3427. * + a timestamp, which represent a time in UTC.
  3428. * @return {Date} date
  3429. */
  3430. function parseDate(value) {
  3431. if (value instanceof Date) {
  3432. return value;
  3433. } else if (typeof value === 'string') {
  3434. // Different browsers parse date in different way, so we parse it manually.
  3435. // Some other issues:
  3436. // new Date('1970-01-01') is UTC,
  3437. // new Date('1970/01/01') and new Date('1970-1-01') is local.
  3438. // See issue #3623
  3439. var match = TIME_REG.exec(value);
  3440. if (!match) {
  3441. // return Invalid Date.
  3442. return new Date(NaN);
  3443. } // Use local time when no timezone offset specifed.
  3444. if (!match[8]) {
  3445. // match[n] can only be string or undefined.
  3446. // But take care of '12' + 1 => '121'.
  3447. return new Date(+match[1], +(match[2] || 1) - 1, +match[3] || 1, +match[4] || 0, +(match[5] || 0), +match[6] || 0, +match[7] || 0);
  3448. } // Timezoneoffset of Javascript Date has considered DST (Daylight Saving Time,
  3449. // https://tc39.github.io/ecma262/#sec-daylight-saving-time-adjustment).
  3450. // For example, system timezone is set as "Time Zone: America/Toronto",
  3451. // then these code will get different result:
  3452. // `new Date(1478411999999).getTimezoneOffset(); // get 240`
  3453. // `new Date(1478412000000).getTimezoneOffset(); // get 300`
  3454. // So we should not use `new Date`, but use `Date.UTC`.
  3455. else {
  3456. var hour = +match[4] || 0;
  3457. if (match[8].toUpperCase() !== 'Z') {
  3458. hour -= match[8].slice(0, 3);
  3459. }
  3460. return new Date(Date.UTC(+match[1], +(match[2] || 1) - 1, +match[3] || 1, hour, +(match[5] || 0), +match[6] || 0, +match[7] || 0));
  3461. }
  3462. } else if (value == null) {
  3463. return new Date(NaN);
  3464. }
  3465. return new Date(Math.round(value));
  3466. }
  3467. /**
  3468. * Quantity of a number. e.g. 0.1, 1, 10, 100
  3469. *
  3470. * @param {number} val
  3471. * @return {number}
  3472. */
  3473. function quantity(val) {
  3474. return Math.pow(10, quantityExponent(val));
  3475. }
  3476. function quantityExponent(val) {
  3477. return Math.floor(Math.log(val) / Math.LN10);
  3478. }
  3479. /**
  3480. * find a “nice” number approximately equal to x. Round the number if round = true,
  3481. * take ceiling if round = false. The primary observation is that the “nicest”
  3482. * numbers in decimal are 1, 2, and 5, and all power-of-ten multiples of these numbers.
  3483. *
  3484. * See "Nice Numbers for Graph Labels" of Graphic Gems.
  3485. *
  3486. * @param {number} val Non-negative value.
  3487. * @param {boolean} round
  3488. * @return {number}
  3489. */
  3490. function nice(val, round) {
  3491. var exponent = quantityExponent(val);
  3492. var exp10 = Math.pow(10, exponent);
  3493. var f = val / exp10; // 1 <= f < 10
  3494. var nf;
  3495. if (round) {
  3496. if (f < 1.5) {
  3497. nf = 1;
  3498. } else if (f < 2.5) {
  3499. nf = 2;
  3500. } else if (f < 4) {
  3501. nf = 3;
  3502. } else if (f < 7) {
  3503. nf = 5;
  3504. } else {
  3505. nf = 10;
  3506. }
  3507. } else {
  3508. if (f < 1) {
  3509. nf = 1;
  3510. } else if (f < 2) {
  3511. nf = 2;
  3512. } else if (f < 3) {
  3513. nf = 3;
  3514. } else if (f < 5) {
  3515. nf = 5;
  3516. } else {
  3517. nf = 10;
  3518. }
  3519. }
  3520. val = nf * exp10; // Fix 3 * 0.1 === 0.30000000000000004 issue (see IEEE 754).
  3521. // 20 is the uppper bound of toFixed.
  3522. return exponent >= -20 ? +val.toFixed(exponent < 0 ? -exponent : 0) : val;
  3523. }
  3524. /**
  3525. * Order intervals asc, and split them when overlap.
  3526. * expect(numberUtil.reformIntervals([
  3527. * {interval: [18, 62], close: [1, 1]},
  3528. * {interval: [-Infinity, -70], close: [0, 0]},
  3529. * {interval: [-70, -26], close: [1, 1]},
  3530. * {interval: [-26, 18], close: [1, 1]},
  3531. * {interval: [62, 150], close: [1, 1]},
  3532. * {interval: [106, 150], close: [1, 1]},
  3533. * {interval: [150, Infinity], close: [0, 0]}
  3534. * ])).toEqual([
  3535. * {interval: [-Infinity, -70], close: [0, 0]},
  3536. * {interval: [-70, -26], close: [1, 1]},
  3537. * {interval: [-26, 18], close: [0, 1]},
  3538. * {interval: [18, 62], close: [0, 1]},
  3539. * {interval: [62, 150], close: [0, 1]},
  3540. * {interval: [150, Infinity], close: [0, 0]}
  3541. * ]);
  3542. * @param {Array.<Object>} list, where `close` mean open or close
  3543. * of the interval, and Infinity can be used.
  3544. * @return {Array.<Object>} The origin list, which has been reformed.
  3545. */
  3546. function reformIntervals(list) {
  3547. list.sort(function (a, b) {
  3548. return littleThan(a, b, 0) ? -1 : 1;
  3549. });
  3550. var curr = -Infinity;
  3551. var currClose = 1;
  3552. for (var i = 0; i < list.length;) {
  3553. var interval = list[i].interval;
  3554. var close = list[i].close;
  3555. for (var lg = 0; lg < 2; lg++) {
  3556. if (interval[lg] <= curr) {
  3557. interval[lg] = curr;
  3558. close[lg] = !lg ? 1 - currClose : 1;
  3559. }
  3560. curr = interval[lg];
  3561. currClose = close[lg];
  3562. }
  3563. if (interval[0] === interval[1] && close[0] * close[1] !== 1) {
  3564. list.splice(i, 1);
  3565. } else {
  3566. i++;
  3567. }
  3568. }
  3569. return list;
  3570. function littleThan(a, b, lg) {
  3571. return a.interval[lg] < b.interval[lg] || a.interval[lg] === b.interval[lg] && (a.close[lg] - b.close[lg] === (!lg ? 1 : -1) || !lg && littleThan(a, b, 1));
  3572. }
  3573. }
  3574. /**
  3575. * parseFloat NaNs numeric-cast false positives (null|true|false|"")
  3576. * ...but misinterprets leading-number strings, particularly hex literals ("0x...")
  3577. * subtraction forces infinities to NaN
  3578. *
  3579. * @param {*} v
  3580. * @return {boolean}
  3581. */
  3582. function isNumeric(v) {
  3583. return v - parseFloat(v) >= 0;
  3584. }
  3585. exports.linearMap = linearMap;
  3586. exports.parsePercent = parsePercent;
  3587. exports.round = round;
  3588. exports.asc = asc;
  3589. exports.getPrecision = getPrecision;
  3590. exports.getPrecisionSafe = getPrecisionSafe;
  3591. exports.getPixelPrecision = getPixelPrecision;
  3592. exports.getPercentWithPrecision = getPercentWithPrecision;
  3593. exports.MAX_SAFE_INTEGER = MAX_SAFE_INTEGER;
  3594. exports.remRadian = remRadian;
  3595. exports.isRadianAroundZero = isRadianAroundZero;
  3596. exports.parseDate = parseDate;
  3597. exports.quantity = quantity;
  3598. exports.nice = nice;
  3599. exports.reformIntervals = reformIntervals;
  3600. exports.isNumeric = isNumeric;
  3601. /***/ }),
  3602. /* 10 */
  3603. /***/ (function(module, exports, __webpack_require__) {
  3604. var LRU = __webpack_require__(14);
  3605. var globalImageCache = new LRU(50);
  3606. /**
  3607. * @param {string|HTMLImageElement|HTMLCanvasElement|Canvas} newImageOrSrc
  3608. * @return {HTMLImageElement|HTMLCanvasElement|Canvas} image
  3609. */
  3610. function findExistImage(newImageOrSrc) {
  3611. if (typeof newImageOrSrc === 'string') {
  3612. var cachedImgObj = globalImageCache.get(newImageOrSrc);
  3613. return cachedImgObj && cachedImgObj.image;
  3614. } else {
  3615. return newImageOrSrc;
  3616. }
  3617. }
  3618. /**
  3619. * Caution: User should cache loaded images, but not just count on LRU.
  3620. * Consider if required images more than LRU size, will dead loop occur?
  3621. *
  3622. * @param {string|HTMLImageElement|HTMLCanvasElement|Canvas} newImageOrSrc
  3623. * @param {HTMLImageElement|HTMLCanvasElement|Canvas} image Existent image.
  3624. * @param {module:zrender/Element} [hostEl] For calling `dirty`.
  3625. * @param {Function} [cb] params: (image, cbPayload)
  3626. * @param {Object} [cbPayload] Payload on cb calling.
  3627. * @return {HTMLImageElement|HTMLCanvasElement|Canvas} image
  3628. */
  3629. function createOrUpdateImage(newImageOrSrc, image, hostEl, cb, cbPayload) {
  3630. if (!newImageOrSrc) {
  3631. return image;
  3632. } else if (typeof newImageOrSrc === 'string') {
  3633. // Image should not be loaded repeatly.
  3634. if (image && image.__zrImageSrc === newImageOrSrc || !hostEl) {
  3635. return image;
  3636. } // Only when there is no existent image or existent image src
  3637. // is different, this method is responsible for load.
  3638. var cachedImgObj = globalImageCache.get(newImageOrSrc);
  3639. var pendingWrap = {
  3640. hostEl: hostEl,
  3641. cb: cb,
  3642. cbPayload: cbPayload
  3643. };
  3644. if (cachedImgObj) {
  3645. image = cachedImgObj.image;
  3646. !isImageReady(image) && cachedImgObj.pending.push(pendingWrap);
  3647. } else {
  3648. !image && (image = new Image());
  3649. image.onload = imageOnLoad;
  3650. globalImageCache.put(newImageOrSrc, image.__cachedImgObj = {
  3651. image: image,
  3652. pending: [pendingWrap]
  3653. });
  3654. image.src = image.__zrImageSrc = newImageOrSrc;
  3655. }
  3656. return image;
  3657. } // newImageOrSrc is an HTMLImageElement or HTMLCanvasElement or Canvas
  3658. else {
  3659. return newImageOrSrc;
  3660. }
  3661. }
  3662. function imageOnLoad() {
  3663. var cachedImgObj = this.__cachedImgObj;
  3664. this.onload = this.__cachedImgObj = null;
  3665. for (var i = 0; i < cachedImgObj.pending.length; i++) {
  3666. var pendingWrap = cachedImgObj.pending[i];
  3667. var cb = pendingWrap.cb;
  3668. cb && cb(this, pendingWrap.cbPayload);
  3669. pendingWrap.hostEl.dirty();
  3670. }
  3671. cachedImgObj.pending.length = 0;
  3672. }
  3673. function isImageReady(image) {
  3674. return image && image.width && image.height;
  3675. }
  3676. exports.findExistImage = findExistImage;
  3677. exports.createOrUpdateImage = createOrUpdateImage;
  3678. exports.isImageReady = isImageReady;
  3679. /***/ }),
  3680. /* 11 */
  3681. /***/ (function(module, exports, __webpack_require__) {
  3682. var zrUtil = __webpack_require__(0);
  3683. // TODO Parse shadow style
  3684. // TODO Only shallow path support
  3685. function _default(properties) {
  3686. // Normalize
  3687. for (var i = 0; i < properties.length; i++) {
  3688. if (!properties[i][1]) {
  3689. properties[i][1] = properties[i][0];
  3690. }
  3691. }
  3692. return function (model, excludes, includes) {
  3693. var style = {};
  3694. for (var i = 0; i < properties.length; i++) {
  3695. var propName = properties[i][1];
  3696. if (excludes && zrUtil.indexOf(excludes, propName) >= 0 || includes && zrUtil.indexOf(includes, propName) < 0) {
  3697. continue;
  3698. }
  3699. var val = model.getShallow(propName);
  3700. if (val != null) {
  3701. style[properties[i][0]] = val;
  3702. }
  3703. }
  3704. return style;
  3705. };
  3706. }
  3707. module.exports = _default;
  3708. /***/ }),
  3709. /* 12 */
  3710. /***/ (function(module, exports, __webpack_require__) {
  3711. var zrUtil = __webpack_require__(0);
  3712. var Style = __webpack_require__(40);
  3713. var Element = __webpack_require__(16);
  3714. var RectText = __webpack_require__(48);
  3715. /**
  3716. * 可绘制的图形基类
  3717. * Base class of all displayable graphic objects
  3718. * @module zrender/graphic/Displayable
  3719. */
  3720. /**
  3721. * @alias module:zrender/graphic/Displayable
  3722. * @extends module:zrender/Element
  3723. * @extends module:zrender/graphic/mixin/RectText
  3724. */
  3725. function Displayable(opts) {
  3726. opts = opts || {};
  3727. Element.call(this, opts); // Extend properties
  3728. for (var name in opts) {
  3729. if (opts.hasOwnProperty(name) && name !== 'style') {
  3730. this[name] = opts[name];
  3731. }
  3732. }
  3733. /**
  3734. * @type {module:zrender/graphic/Style}
  3735. */
  3736. this.style = new Style(opts.style, this);
  3737. this._rect = null; // Shapes for cascade clipping.
  3738. this.__clipPaths = []; // FIXME Stateful must be mixined after style is setted
  3739. // Stateful.call(this, opts);
  3740. }
  3741. Displayable.prototype = {
  3742. constructor: Displayable,
  3743. type: 'displayable',
  3744. /**
  3745. * Displayable 是否为脏,Painter 中会根据该标记判断是否需要是否需要重新绘制
  3746. * Dirty flag. From which painter will determine if this displayable object needs brush
  3747. * @name module:zrender/graphic/Displayable#__dirty
  3748. * @type {boolean}
  3749. */
  3750. __dirty: true,
  3751. /**
  3752. * 图形是否可见,为true时不绘制图形,但是仍能触发鼠标事件
  3753. * If ignore drawing of the displayable object. Mouse event will still be triggered
  3754. * @name module:/zrender/graphic/Displayable#invisible
  3755. * @type {boolean}
  3756. * @default false
  3757. */
  3758. invisible: false,
  3759. /**
  3760. * @name module:/zrender/graphic/Displayable#z
  3761. * @type {number}
  3762. * @default 0
  3763. */
  3764. z: 0,
  3765. /**
  3766. * @name module:/zrender/graphic/Displayable#z
  3767. * @type {number}
  3768. * @default 0
  3769. */
  3770. z2: 0,
  3771. /**
  3772. * z层level,决定绘画在哪层canvas中
  3773. * @name module:/zrender/graphic/Displayable#zlevel
  3774. * @type {number}
  3775. * @default 0
  3776. */
  3777. zlevel: 0,
  3778. /**
  3779. * 是否可拖拽
  3780. * @name module:/zrender/graphic/Displayable#draggable
  3781. * @type {boolean}
  3782. * @default false
  3783. */
  3784. draggable: false,
  3785. /**
  3786. * 是否正在拖拽
  3787. * @name module:/zrender/graphic/Displayable#draggable
  3788. * @type {boolean}
  3789. * @default false
  3790. */
  3791. dragging: false,
  3792. /**
  3793. * 是否相应鼠标事件
  3794. * @name module:/zrender/graphic/Displayable#silent
  3795. * @type {boolean}
  3796. * @default false
  3797. */
  3798. silent: false,
  3799. /**
  3800. * If enable culling
  3801. * @type {boolean}
  3802. * @default false
  3803. */
  3804. culling: false,
  3805. /**
  3806. * Mouse cursor when hovered
  3807. * @name module:/zrender/graphic/Displayable#cursor
  3808. * @type {string}
  3809. */
  3810. cursor: 'pointer',
  3811. /**
  3812. * If hover area is bounding rect
  3813. * @name module:/zrender/graphic/Displayable#rectHover
  3814. * @type {string}
  3815. */
  3816. rectHover: false,
  3817. /**
  3818. * Render the element progressively when the value >= 0,
  3819. * usefull for large data.
  3820. * @type {number}
  3821. */
  3822. progressive: -1,
  3823. beforeBrush: function (ctx) {},
  3824. afterBrush: function (ctx) {},
  3825. /**
  3826. * 图形绘制方法
  3827. * @param {CanvasRenderingContext2D} ctx
  3828. */
  3829. // Interface
  3830. brush: function (ctx, prevEl) {},
  3831. /**
  3832. * 获取最小包围盒
  3833. * @return {module:zrender/core/BoundingRect}
  3834. */
  3835. // Interface
  3836. getBoundingRect: function () {},
  3837. /**
  3838. * 判断坐标 x, y 是否在图形上
  3839. * If displayable element contain coord x, y
  3840. * @param {number} x
  3841. * @param {number} y
  3842. * @return {boolean}
  3843. */
  3844. contain: function (x, y) {
  3845. return this.rectContain(x, y);
  3846. },
  3847. /**
  3848. * @param {Function} cb
  3849. * @param {} context
  3850. */
  3851. traverse: function (cb, context) {
  3852. cb.call(context, this);
  3853. },
  3854. /**
  3855. * 判断坐标 x, y 是否在图形的包围盒上
  3856. * If bounding rect of element contain coord x, y
  3857. * @param {number} x
  3858. * @param {number} y
  3859. * @return {boolean}
  3860. */
  3861. rectContain: function (x, y) {
  3862. var coord = this.transformCoordToLocal(x, y);
  3863. var rect = this.getBoundingRect();
  3864. return rect.contain(coord[0], coord[1]);
  3865. },
  3866. /**
  3867. * 标记图形元素为脏,并且在下一帧重绘
  3868. * Mark displayable element dirty and refresh next frame
  3869. */
  3870. dirty: function () {
  3871. this.__dirty = true;
  3872. this._rect = null;
  3873. this.__zr && this.__zr.refresh();
  3874. },
  3875. /**
  3876. * 图形是否会触发事件
  3877. * If displayable object binded any event
  3878. * @return {boolean}
  3879. */
  3880. // TODO, 通过 bind 绑定的事件
  3881. // isSilent: function () {
  3882. // return !(
  3883. // this.hoverable || this.draggable
  3884. // || this.onmousemove || this.onmouseover || this.onmouseout
  3885. // || this.onmousedown || this.onmouseup || this.onclick
  3886. // || this.ondragenter || this.ondragover || this.ondragleave
  3887. // || this.ondrop
  3888. // );
  3889. // },
  3890. /**
  3891. * Alias for animate('style')
  3892. * @param {boolean} loop
  3893. */
  3894. animateStyle: function (loop) {
  3895. return this.animate('style', loop);
  3896. },
  3897. attrKV: function (key, value) {
  3898. if (key !== 'style') {
  3899. Element.prototype.attrKV.call(this, key, value);
  3900. } else {
  3901. this.style.set(value);
  3902. }
  3903. },
  3904. /**
  3905. * @param {Object|string} key
  3906. * @param {*} value
  3907. */
  3908. setStyle: function (key, value) {
  3909. this.style.set(key, value);
  3910. this.dirty(false);
  3911. return this;
  3912. },
  3913. /**
  3914. * Use given style object
  3915. * @param {Object} obj
  3916. */
  3917. useStyle: function (obj) {
  3918. this.style = new Style(obj, this);
  3919. this.dirty(false);
  3920. return this;
  3921. }
  3922. };
  3923. zrUtil.inherits(Displayable, Element);
  3924. zrUtil.mixin(Displayable, RectText); // zrUtil.mixin(Displayable, Stateful);
  3925. var _default = Displayable;
  3926. module.exports = _default;
  3927. /***/ }),
  3928. /* 13 */
  3929. /***/ (function(module, exports, __webpack_require__) {
  3930. var zrUtil = __webpack_require__(0);
  3931. var textContain = __webpack_require__(5);
  3932. var numberUtil = __webpack_require__(9);
  3933. /**
  3934. * 每三位默认加,格式化
  3935. * @param {string|number} x
  3936. * @return {string}
  3937. */
  3938. function addCommas(x) {
  3939. if (isNaN(x)) {
  3940. return '-';
  3941. }
  3942. x = (x + '').split('.');
  3943. return x[0].replace(/(\d{1,3})(?=(?:\d{3})+(?!\d))/g, '$1,') + (x.length > 1 ? '.' + x[1] : '');
  3944. }
  3945. /**
  3946. * @param {string} str
  3947. * @param {boolean} [upperCaseFirst=false]
  3948. * @return {string} str
  3949. */
  3950. function toCamelCase(str, upperCaseFirst) {
  3951. str = (str || '').toLowerCase().replace(/-(.)/g, function (match, group1) {
  3952. return group1.toUpperCase();
  3953. });
  3954. if (upperCaseFirst && str) {
  3955. str = str.charAt(0).toUpperCase() + str.slice(1);
  3956. }
  3957. return str;
  3958. }
  3959. var normalizeCssArray = zrUtil.normalizeCssArray;
  3960. function encodeHTML(source) {
  3961. return String(source).replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;').replace(/'/g, '&#39;');
  3962. }
  3963. var TPL_VAR_ALIAS = ['a', 'b', 'c', 'd', 'e', 'f', 'g'];
  3964. var wrapVar = function (varName, seriesIdx) {
  3965. return '{' + varName + (seriesIdx == null ? '' : seriesIdx) + '}';
  3966. };
  3967. /**
  3968. * Template formatter
  3969. * @param {string} tpl
  3970. * @param {Array.<Object>|Object} paramsList
  3971. * @param {boolean} [encode=false]
  3972. * @return {string}
  3973. */
  3974. function formatTpl(tpl, paramsList, encode) {
  3975. if (!zrUtil.isArray(paramsList)) {
  3976. paramsList = [paramsList];
  3977. }
  3978. var seriesLen = paramsList.length;
  3979. if (!seriesLen) {
  3980. return '';
  3981. }
  3982. var $vars = paramsList[0].$vars || [];
  3983. for (var i = 0; i < $vars.length; i++) {
  3984. var alias = TPL_VAR_ALIAS[i];
  3985. var val = wrapVar(alias, 0);
  3986. tpl = tpl.replace(wrapVar(alias), encode ? encodeHTML(val) : val);
  3987. }
  3988. for (var seriesIdx = 0; seriesIdx < seriesLen; seriesIdx++) {
  3989. for (var k = 0; k < $vars.length; k++) {
  3990. var val = paramsList[seriesIdx][$vars[k]];
  3991. tpl = tpl.replace(wrapVar(TPL_VAR_ALIAS[k], seriesIdx), encode ? encodeHTML(val) : val);
  3992. }
  3993. }
  3994. return tpl;
  3995. }
  3996. /**
  3997. * simple Template formatter
  3998. *
  3999. * @param {string} tpl
  4000. * @param {Object} param
  4001. * @param {boolean} [encode=false]
  4002. * @return {string}
  4003. */
  4004. function formatTplSimple(tpl, param, encode) {
  4005. zrUtil.each(param, function (value, key) {
  4006. tpl = tpl.replace('{' + key + '}', encode ? encodeHTML(value) : value);
  4007. });
  4008. return tpl;
  4009. }
  4010. /**
  4011. * @param {string} color
  4012. * @param {string} [extraCssText]
  4013. * @return {string}
  4014. */
  4015. function getTooltipMarker(color, extraCssText) {
  4016. return color ? '<span style="display:inline-block;margin-right:5px;' + 'border-radius:10px;width:9px;height:9px;background-color:' + encodeHTML(color) + ';' + (extraCssText || '') + '"></span>' : '';
  4017. }
  4018. /**
  4019. * @param {string} str
  4020. * @return {string}
  4021. * @inner
  4022. */
  4023. var s2d = function (str) {
  4024. return str < 10 ? '0' + str : str;
  4025. };
  4026. /**
  4027. * ISO Date format
  4028. * @param {string} tpl
  4029. * @param {number} value
  4030. * @param {boolean} [isUTC=false] Default in local time.
  4031. * see `module:echarts/scale/Time`
  4032. * and `module:echarts/util/number#parseDate`.
  4033. * @inner
  4034. */
  4035. function formatTime(tpl, value, isUTC) {
  4036. if (tpl === 'week' || tpl === 'month' || tpl === 'quarter' || tpl === 'half-year' || tpl === 'year') {
  4037. tpl = 'MM-dd\nyyyy';
  4038. }
  4039. var date = numberUtil.parseDate(value);
  4040. var utc = isUTC ? 'UTC' : '';
  4041. var y = date['get' + utc + 'FullYear']();
  4042. var M = date['get' + utc + 'Month']() + 1;
  4043. var d = date['get' + utc + 'Date']();
  4044. var h = date['get' + utc + 'Hours']();
  4045. var m = date['get' + utc + 'Minutes']();
  4046. var s = date['get' + utc + 'Seconds']();
  4047. tpl = tpl.replace('MM', s2d(M)).replace('M', M).replace('yyyy', y).replace('yy', y % 100).replace('dd', s2d(d)).replace('d', d).replace('hh', s2d(h)).replace('h', h).replace('mm', s2d(m)).replace('m', m).replace('ss', s2d(s)).replace('s', s);
  4048. return tpl;
  4049. }
  4050. /**
  4051. * Capital first
  4052. * @param {string} str
  4053. * @return {string}
  4054. */
  4055. function capitalFirst(str) {
  4056. return str ? str.charAt(0).toUpperCase() + str.substr(1) : str;
  4057. }
  4058. var truncateText = textContain.truncateText;
  4059. var getTextRect = textContain.getBoundingRect;
  4060. exports.addCommas = addCommas;
  4061. exports.toCamelCase = toCamelCase;
  4062. exports.normalizeCssArray = normalizeCssArray;
  4063. exports.encodeHTML = encodeHTML;
  4064. exports.formatTpl = formatTpl;
  4065. exports.formatTplSimple = formatTplSimple;
  4066. exports.getTooltipMarker = getTooltipMarker;
  4067. exports.formatTime = formatTime;
  4068. exports.capitalFirst = capitalFirst;
  4069. exports.truncateText = truncateText;
  4070. exports.getTextRect = getTextRect;
  4071. /***/ }),
  4072. /* 14 */
  4073. /***/ (function(module, exports) {
  4074. // Simple LRU cache use doubly linked list
  4075. // @module zrender/core/LRU
  4076. /**
  4077. * Simple double linked list. Compared with array, it has O(1) remove operation.
  4078. * @constructor
  4079. */
  4080. var LinkedList = function () {
  4081. /**
  4082. * @type {module:zrender/core/LRU~Entry}
  4083. */
  4084. this.head = null;
  4085. /**
  4086. * @type {module:zrender/core/LRU~Entry}
  4087. */
  4088. this.tail = null;
  4089. this._len = 0;
  4090. };
  4091. var linkedListProto = LinkedList.prototype;
  4092. /**
  4093. * Insert a new value at the tail
  4094. * @param {} val
  4095. * @return {module:zrender/core/LRU~Entry}
  4096. */
  4097. linkedListProto.insert = function (val) {
  4098. var entry = new Entry(val);
  4099. this.insertEntry(entry);
  4100. return entry;
  4101. };
  4102. /**
  4103. * Insert an entry at the tail
  4104. * @param {module:zrender/core/LRU~Entry} entry
  4105. */
  4106. linkedListProto.insertEntry = function (entry) {
  4107. if (!this.head) {
  4108. this.head = this.tail = entry;
  4109. } else {
  4110. this.tail.next = entry;
  4111. entry.prev = this.tail;
  4112. entry.next = null;
  4113. this.tail = entry;
  4114. }
  4115. this._len++;
  4116. };
  4117. /**
  4118. * Remove entry.
  4119. * @param {module:zrender/core/LRU~Entry} entry
  4120. */
  4121. linkedListProto.remove = function (entry) {
  4122. var prev = entry.prev;
  4123. var next = entry.next;
  4124. if (prev) {
  4125. prev.next = next;
  4126. } else {
  4127. // Is head
  4128. this.head = next;
  4129. }
  4130. if (next) {
  4131. next.prev = prev;
  4132. } else {
  4133. // Is tail
  4134. this.tail = prev;
  4135. }
  4136. entry.next = entry.prev = null;
  4137. this._len--;
  4138. };
  4139. /**
  4140. * @return {number}
  4141. */
  4142. linkedListProto.len = function () {
  4143. return this._len;
  4144. };
  4145. /**
  4146. * Clear list
  4147. */
  4148. linkedListProto.clear = function () {
  4149. this.head = this.tail = null;
  4150. this._len = 0;
  4151. };
  4152. /**
  4153. * @constructor
  4154. * @param {} val
  4155. */
  4156. var Entry = function (val) {
  4157. /**
  4158. * @type {}
  4159. */
  4160. this.value = val;
  4161. /**
  4162. * @type {module:zrender/core/LRU~Entry}
  4163. */
  4164. this.next;
  4165. /**
  4166. * @type {module:zrender/core/LRU~Entry}
  4167. */
  4168. this.prev;
  4169. };
  4170. /**
  4171. * LRU Cache
  4172. * @constructor
  4173. * @alias module:zrender/core/LRU
  4174. */
  4175. var LRU = function (maxSize) {
  4176. this._list = new LinkedList();
  4177. this._map = {};
  4178. this._maxSize = maxSize || 10;
  4179. this._lastRemovedEntry = null;
  4180. };
  4181. var LRUProto = LRU.prototype;
  4182. /**
  4183. * @param {string} key
  4184. * @param {} value
  4185. * @return {} Removed value
  4186. */
  4187. LRUProto.put = function (key, value) {
  4188. var list = this._list;
  4189. var map = this._map;
  4190. var removed = null;
  4191. if (map[key] == null) {
  4192. var len = list.len(); // Reuse last removed entry
  4193. var entry = this._lastRemovedEntry;
  4194. if (len >= this._maxSize && len > 0) {
  4195. // Remove the least recently used
  4196. var leastUsedEntry = list.head;
  4197. list.remove(leastUsedEntry);
  4198. delete map[leastUsedEntry.key];
  4199. removed = leastUsedEntry.value;
  4200. this._lastRemovedEntry = leastUsedEntry;
  4201. }
  4202. if (entry) {
  4203. entry.value = value;
  4204. } else {
  4205. entry = new Entry(value);
  4206. }
  4207. entry.key = key;
  4208. list.insertEntry(entry);
  4209. map[key] = entry;
  4210. }
  4211. return removed;
  4212. };
  4213. /**
  4214. * @param {string} key
  4215. * @return {}
  4216. */
  4217. LRUProto.get = function (key) {
  4218. var entry = this._map[key];
  4219. var list = this._list;
  4220. if (entry != null) {
  4221. // Put the latest used entry in the tail
  4222. if (entry !== list.tail) {
  4223. list.remove(entry);
  4224. list.insertEntry(entry);
  4225. }
  4226. return entry.value;
  4227. }
  4228. };
  4229. /**
  4230. * Clear the cache
  4231. */
  4232. LRUProto.clear = function () {
  4233. this._list.clear();
  4234. this._map = {};
  4235. };
  4236. var _default = LRU;
  4237. module.exports = _default;
  4238. /***/ }),
  4239. /* 15 */
  4240. /***/ (function(module, exports) {
  4241. /**
  4242. * echarts设备环境识别
  4243. *
  4244. * @desc echarts基于Canvas,纯Javascript图表库,提供直观,生动,可交互,可个性化定制的数据统计图表。
  4245. * @author firede[firede@firede.us]
  4246. * @desc thanks zepto.
  4247. */
  4248. var env = {};
  4249. if (typeof navigator === 'undefined') {
  4250. // In node
  4251. env = {
  4252. browser: {},
  4253. os: {},
  4254. node: true,
  4255. // Assume canvas is supported
  4256. canvasSupported: true,
  4257. svgSupported: true
  4258. };
  4259. } else {
  4260. env = detect(navigator.userAgent);
  4261. }
  4262. var _default = env; // Zepto.js
  4263. // (c) 2010-2013 Thomas Fuchs
  4264. // Zepto.js may be freely distributed under the MIT license.
  4265. function detect(ua) {
  4266. var os = {};
  4267. var browser = {}; // var webkit = ua.match(/Web[kK]it[\/]{0,1}([\d.]+)/);
  4268. // var android = ua.match(/(Android);?[\s\/]+([\d.]+)?/);
  4269. // var ipad = ua.match(/(iPad).*OS\s([\d_]+)/);
  4270. // var ipod = ua.match(/(iPod)(.*OS\s([\d_]+))?/);
  4271. // var iphone = !ipad && ua.match(/(iPhone\sOS)\s([\d_]+)/);
  4272. // var webos = ua.match(/(webOS|hpwOS)[\s\/]([\d.]+)/);
  4273. // var touchpad = webos && ua.match(/TouchPad/);
  4274. // var kindle = ua.match(/Kindle\/([\d.]+)/);
  4275. // var silk = ua.match(/Silk\/([\d._]+)/);
  4276. // var blackberry = ua.match(/(BlackBerry).*Version\/([\d.]+)/);
  4277. // var bb10 = ua.match(/(BB10).*Version\/([\d.]+)/);
  4278. // var rimtabletos = ua.match(/(RIM\sTablet\sOS)\s([\d.]+)/);
  4279. // var playbook = ua.match(/PlayBook/);
  4280. // var chrome = ua.match(/Chrome\/([\d.]+)/) || ua.match(/CriOS\/([\d.]+)/);
  4281. var firefox = ua.match(/Firefox\/([\d.]+)/); // var safari = webkit && ua.match(/Mobile\//) && !chrome;
  4282. // var webview = ua.match(/(iPhone|iPod|iPad).*AppleWebKit(?!.*Safari)/) && !chrome;
  4283. var ie = ua.match(/MSIE\s([\d.]+)/) // IE 11 Trident/7.0; rv:11.0
  4284. || ua.match(/Trident\/.+?rv:(([\d.]+))/);
  4285. var edge = ua.match(/Edge\/([\d.]+)/); // IE 12 and 12+
  4286. var weChat = /micromessenger/i.test(ua); // Todo: clean this up with a better OS/browser seperation:
  4287. // - discern (more) between multiple browsers on android
  4288. // - decide if kindle fire in silk mode is android or not
  4289. // - Firefox on Android doesn't specify the Android version
  4290. // - possibly devide in os, device and browser hashes
  4291. // if (browser.webkit = !!webkit) browser.version = webkit[1];
  4292. // if (android) os.android = true, os.version = android[2];
  4293. // if (iphone && !ipod) os.ios = os.iphone = true, os.version = iphone[2].replace(/_/g, '.');
  4294. // if (ipad) os.ios = os.ipad = true, os.version = ipad[2].replace(/_/g, '.');
  4295. // if (ipod) os.ios = os.ipod = true, os.version = ipod[3] ? ipod[3].replace(/_/g, '.') : null;
  4296. // if (webos) os.webos = true, os.version = webos[2];
  4297. // if (touchpad) os.touchpad = true;
  4298. // if (blackberry) os.blackberry = true, os.version = blackberry[2];
  4299. // if (bb10) os.bb10 = true, os.version = bb10[2];
  4300. // if (rimtabletos) os.rimtabletos = true, os.version = rimtabletos[2];
  4301. // if (playbook) browser.playbook = true;
  4302. // if (kindle) os.kindle = true, os.version = kindle[1];
  4303. // if (silk) browser.silk = true, browser.version = silk[1];
  4304. // if (!silk && os.android && ua.match(/Kindle Fire/)) browser.silk = true;
  4305. // if (chrome) browser.chrome = true, browser.version = chrome[1];
  4306. if (firefox) {
  4307. browser.firefox = true;
  4308. browser.version = firefox[1];
  4309. } // if (safari && (ua.match(/Safari/) || !!os.ios)) browser.safari = true;
  4310. // if (webview) browser.webview = true;
  4311. if (ie) {
  4312. browser.ie = true;
  4313. browser.version = ie[1];
  4314. }
  4315. if (edge) {
  4316. browser.edge = true;
  4317. browser.version = edge[1];
  4318. } // It is difficult to detect WeChat in Win Phone precisely, because ua can
  4319. // not be set on win phone. So we do not consider Win Phone.
  4320. if (weChat) {
  4321. browser.weChat = true;
  4322. } // os.tablet = !!(ipad || playbook || (android && !ua.match(/Mobile/)) ||
  4323. // (firefox && ua.match(/Tablet/)) || (ie && !ua.match(/Phone/) && ua.match(/Touch/)));
  4324. // os.phone = !!(!os.tablet && !os.ipod && (android || iphone || webos ||
  4325. // (chrome && ua.match(/Android/)) || (chrome && ua.match(/CriOS\/([\d.]+)/)) ||
  4326. // (firefox && ua.match(/Mobile/)) || (ie && ua.match(/Touch/))));
  4327. return {
  4328. browser: browser,
  4329. os: os,
  4330. node: false,
  4331. // 原生canvas支持,改极端点了
  4332. // canvasSupported : !(browser.ie && parseFloat(browser.version) < 9)
  4333. canvasSupported: !!document.createElement('canvas').getContext,
  4334. svgSupported: typeof SVGRect !== 'undefined',
  4335. // @see <http://stackoverflow.com/questions/4817029/whats-the-best-way-to-detect-a-touch-screen-device-using-javascript>
  4336. // works on most browsers
  4337. // IE10/11 does not support touch event, and MS Edge supports them but not by
  4338. // default, so we dont check navigator.maxTouchPoints for them here.
  4339. touchEventsSupported: 'ontouchstart' in window && !browser.ie && !browser.edge,
  4340. // <http://caniuse.com/#search=pointer%20event>.
  4341. pointerEventsSupported: 'onpointerdown' in window // Firefox supports pointer but not by default, only MS browsers are reliable on pointer
  4342. // events currently. So we dont use that on other browsers unless tested sufficiently.
  4343. // Although IE 10 supports pointer event, it use old style and is different from the
  4344. // standard. So we exclude that. (IE 10 is hardly used on touch device)
  4345. && (browser.edge || browser.ie && browser.version >= 11)
  4346. };
  4347. }
  4348. module.exports = _default;
  4349. /***/ }),
  4350. /* 16 */
  4351. /***/ (function(module, exports, __webpack_require__) {
  4352. var guid = __webpack_require__(41);
  4353. var Eventful = __webpack_require__(42);
  4354. var Transformable = __webpack_require__(17);
  4355. var Animatable = __webpack_require__(43);
  4356. var zrUtil = __webpack_require__(0);
  4357. /**
  4358. * @alias module:zrender/Element
  4359. * @constructor
  4360. * @extends {module:zrender/mixin/Animatable}
  4361. * @extends {module:zrender/mixin/Transformable}
  4362. * @extends {module:zrender/mixin/Eventful}
  4363. */
  4364. var Element = function (opts) {
  4365. // jshint ignore:line
  4366. Transformable.call(this, opts);
  4367. Eventful.call(this, opts);
  4368. Animatable.call(this, opts);
  4369. /**
  4370. * 画布元素ID
  4371. * @type {string}
  4372. */
  4373. this.id = opts.id || guid();
  4374. };
  4375. Element.prototype = {
  4376. /**
  4377. * 元素类型
  4378. * Element type
  4379. * @type {string}
  4380. */
  4381. type: 'element',
  4382. /**
  4383. * 元素名字
  4384. * Element name
  4385. * @type {string}
  4386. */
  4387. name: '',
  4388. /**
  4389. * ZRender 实例对象,会在 element 添加到 zrender 实例中后自动赋值
  4390. * ZRender instance will be assigned when element is associated with zrender
  4391. * @name module:/zrender/Element#__zr
  4392. * @type {module:zrender/ZRender}
  4393. */
  4394. __zr: null,
  4395. /**
  4396. * 图形是否忽略,为true时忽略图形的绘制以及事件触发
  4397. * If ignore drawing and events of the element object
  4398. * @name module:/zrender/Element#ignore
  4399. * @type {boolean}
  4400. * @default false
  4401. */
  4402. ignore: false,
  4403. /**
  4404. * 用于裁剪的路径(shape),所有 Group 内的路径在绘制时都会被这个路径裁剪
  4405. * 该路径会继承被裁减对象的变换
  4406. * @type {module:zrender/graphic/Path}
  4407. * @see http://www.w3.org/TR/2dcontext/#clipping-region
  4408. * @readOnly
  4409. */
  4410. clipPath: null,
  4411. /**
  4412. * Drift element
  4413. * @param {number} dx dx on the global space
  4414. * @param {number} dy dy on the global space
  4415. */
  4416. drift: function (dx, dy) {
  4417. switch (this.draggable) {
  4418. case 'horizontal':
  4419. dy = 0;
  4420. break;
  4421. case 'vertical':
  4422. dx = 0;
  4423. break;
  4424. }
  4425. var m = this.transform;
  4426. if (!m) {
  4427. m = this.transform = [1, 0, 0, 1, 0, 0];
  4428. }
  4429. m[4] += dx;
  4430. m[5] += dy;
  4431. this.decomposeTransform();
  4432. this.dirty(false);
  4433. },
  4434. /**
  4435. * Hook before update
  4436. */
  4437. beforeUpdate: function () {},
  4438. /**
  4439. * Hook after update
  4440. */
  4441. afterUpdate: function () {},
  4442. /**
  4443. * Update each frame
  4444. */
  4445. update: function () {
  4446. this.updateTransform();
  4447. },
  4448. /**
  4449. * @param {Function} cb
  4450. * @param {} context
  4451. */
  4452. traverse: function (cb, context) {},
  4453. /**
  4454. * @protected
  4455. */
  4456. attrKV: function (key, value) {
  4457. if (key === 'position' || key === 'scale' || key === 'origin') {
  4458. // Copy the array
  4459. if (value) {
  4460. var target = this[key];
  4461. if (!target) {
  4462. target = this[key] = [];
  4463. }
  4464. target[0] = value[0];
  4465. target[1] = value[1];
  4466. }
  4467. } else {
  4468. this[key] = value;
  4469. }
  4470. },
  4471. /**
  4472. * Hide the element
  4473. */
  4474. hide: function () {
  4475. this.ignore = true;
  4476. this.__zr && this.__zr.refresh();
  4477. },
  4478. /**
  4479. * Show the element
  4480. */
  4481. show: function () {
  4482. this.ignore = false;
  4483. this.__zr && this.__zr.refresh();
  4484. },
  4485. /**
  4486. * @param {string|Object} key
  4487. * @param {*} value
  4488. */
  4489. attr: function (key, value) {
  4490. if (typeof key === 'string') {
  4491. this.attrKV(key, value);
  4492. } else if (zrUtil.isObject(key)) {
  4493. for (var name in key) {
  4494. if (key.hasOwnProperty(name)) {
  4495. this.attrKV(name, key[name]);
  4496. }
  4497. }
  4498. }
  4499. this.dirty(false);
  4500. return this;
  4501. },
  4502. /**
  4503. * @param {module:zrender/graphic/Path} clipPath
  4504. */
  4505. setClipPath: function (clipPath) {
  4506. var zr = this.__zr;
  4507. if (zr) {
  4508. clipPath.addSelfToZr(zr);
  4509. } // Remove previous clip path
  4510. if (this.clipPath && this.clipPath !== clipPath) {
  4511. this.removeClipPath();
  4512. }
  4513. this.clipPath = clipPath;
  4514. clipPath.__zr = zr;
  4515. clipPath.__clipTarget = this;
  4516. this.dirty(false);
  4517. },
  4518. /**
  4519. */
  4520. removeClipPath: function () {
  4521. var clipPath = this.clipPath;
  4522. if (clipPath) {
  4523. if (clipPath.__zr) {
  4524. clipPath.removeSelfFromZr(clipPath.__zr);
  4525. }
  4526. clipPath.__zr = null;
  4527. clipPath.__clipTarget = null;
  4528. this.clipPath = null;
  4529. this.dirty(false);
  4530. }
  4531. },
  4532. /**
  4533. * Add self from zrender instance.
  4534. * Not recursively because it will be invoked when element added to storage.
  4535. * @param {module:zrender/ZRender} zr
  4536. */
  4537. addSelfToZr: function (zr) {
  4538. this.__zr = zr; // 添加动画
  4539. var animators = this.animators;
  4540. if (animators) {
  4541. for (var i = 0; i < animators.length; i++) {
  4542. zr.animation.addAnimator(animators[i]);
  4543. }
  4544. }
  4545. if (this.clipPath) {
  4546. this.clipPath.addSelfToZr(zr);
  4547. }
  4548. },
  4549. /**
  4550. * Remove self from zrender instance.
  4551. * Not recursively because it will be invoked when element added to storage.
  4552. * @param {module:zrender/ZRender} zr
  4553. */
  4554. removeSelfFromZr: function (zr) {
  4555. this.__zr = null; // 移除动画
  4556. var animators = this.animators;
  4557. if (animators) {
  4558. for (var i = 0; i < animators.length; i++) {
  4559. zr.animation.removeAnimator(animators[i]);
  4560. }
  4561. }
  4562. if (this.clipPath) {
  4563. this.clipPath.removeSelfFromZr(zr);
  4564. }
  4565. }
  4566. };
  4567. zrUtil.mixin(Element, Animatable);
  4568. zrUtil.mixin(Element, Transformable);
  4569. zrUtil.mixin(Element, Eventful);
  4570. var _default = Element;
  4571. module.exports = _default;
  4572. /***/ }),
  4573. /* 17 */
  4574. /***/ (function(module, exports, __webpack_require__) {
  4575. var matrix = __webpack_require__(8);
  4576. var vector = __webpack_require__(2);
  4577. /**
  4578. * 提供变换扩展
  4579. * @module zrender/mixin/Transformable
  4580. * @author pissang (https://www.github.com/pissang)
  4581. */
  4582. var mIdentity = matrix.identity;
  4583. var EPSILON = 5e-5;
  4584. function isNotAroundZero(val) {
  4585. return val > EPSILON || val < -EPSILON;
  4586. }
  4587. /**
  4588. * @alias module:zrender/mixin/Transformable
  4589. * @constructor
  4590. */
  4591. var Transformable = function (opts) {
  4592. opts = opts || {}; // If there are no given position, rotation, scale
  4593. if (!opts.position) {
  4594. /**
  4595. * 平移
  4596. * @type {Array.<number>}
  4597. * @default [0, 0]
  4598. */
  4599. this.position = [0, 0];
  4600. }
  4601. if (opts.rotation == null) {
  4602. /**
  4603. * 旋转
  4604. * @type {Array.<number>}
  4605. * @default 0
  4606. */
  4607. this.rotation = 0;
  4608. }
  4609. if (!opts.scale) {
  4610. /**
  4611. * 缩放
  4612. * @type {Array.<number>}
  4613. * @default [1, 1]
  4614. */
  4615. this.scale = [1, 1];
  4616. }
  4617. /**
  4618. * 旋转和缩放的原点
  4619. * @type {Array.<number>}
  4620. * @default null
  4621. */
  4622. this.origin = this.origin || null;
  4623. };
  4624. var transformableProto = Transformable.prototype;
  4625. transformableProto.transform = null;
  4626. /**
  4627. * 判断是否需要有坐标变换
  4628. * 如果有坐标变换, 则从position, rotation, scale以及父节点的transform计算出自身的transform矩阵
  4629. */
  4630. transformableProto.needLocalTransform = function () {
  4631. return isNotAroundZero(this.rotation) || isNotAroundZero(this.position[0]) || isNotAroundZero(this.position[1]) || isNotAroundZero(this.scale[0] - 1) || isNotAroundZero(this.scale[1] - 1);
  4632. };
  4633. transformableProto.updateTransform = function () {
  4634. var parent = this.parent;
  4635. var parentHasTransform = parent && parent.transform;
  4636. var needLocalTransform = this.needLocalTransform();
  4637. var m = this.transform;
  4638. if (!(needLocalTransform || parentHasTransform)) {
  4639. m && mIdentity(m);
  4640. return;
  4641. }
  4642. m = m || matrix.create();
  4643. if (needLocalTransform) {
  4644. this.getLocalTransform(m);
  4645. } else {
  4646. mIdentity(m);
  4647. } // 应用父节点变换
  4648. if (parentHasTransform) {
  4649. if (needLocalTransform) {
  4650. matrix.mul(m, parent.transform, m);
  4651. } else {
  4652. matrix.copy(m, parent.transform);
  4653. }
  4654. } // 保存这个变换矩阵
  4655. this.transform = m;
  4656. this.invTransform = this.invTransform || matrix.create();
  4657. matrix.invert(this.invTransform, m);
  4658. };
  4659. transformableProto.getLocalTransform = function (m) {
  4660. return Transformable.getLocalTransform(this, m);
  4661. };
  4662. /**
  4663. * 将自己的transform应用到context上
  4664. * @param {CanvasRenderingContext2D} ctx
  4665. */
  4666. transformableProto.setTransform = function (ctx) {
  4667. var m = this.transform;
  4668. var dpr = ctx.dpr || 1;
  4669. if (m) {
  4670. ctx.setTransform(dpr * m[0], dpr * m[1], dpr * m[2], dpr * m[3], dpr * m[4], dpr * m[5]);
  4671. } else {
  4672. ctx.setTransform(dpr, 0, 0, dpr, 0, 0);
  4673. }
  4674. };
  4675. transformableProto.restoreTransform = function (ctx) {
  4676. var dpr = ctx.dpr || 1;
  4677. ctx.setTransform(dpr, 0, 0, dpr, 0, 0);
  4678. };
  4679. var tmpTransform = [];
  4680. /**
  4681. * 分解`transform`矩阵到`position`, `rotation`, `scale`
  4682. */
  4683. transformableProto.decomposeTransform = function () {
  4684. if (!this.transform) {
  4685. return;
  4686. }
  4687. var parent = this.parent;
  4688. var m = this.transform;
  4689. if (parent && parent.transform) {
  4690. // Get local transform and decompose them to position, scale, rotation
  4691. matrix.mul(tmpTransform, parent.invTransform, m);
  4692. m = tmpTransform;
  4693. }
  4694. var sx = m[0] * m[0] + m[1] * m[1];
  4695. var sy = m[2] * m[2] + m[3] * m[3];
  4696. var position = this.position;
  4697. var scale = this.scale;
  4698. if (isNotAroundZero(sx - 1)) {
  4699. sx = Math.sqrt(sx);
  4700. }
  4701. if (isNotAroundZero(sy - 1)) {
  4702. sy = Math.sqrt(sy);
  4703. }
  4704. if (m[0] < 0) {
  4705. sx = -sx;
  4706. }
  4707. if (m[3] < 0) {
  4708. sy = -sy;
  4709. }
  4710. position[0] = m[4];
  4711. position[1] = m[5];
  4712. scale[0] = sx;
  4713. scale[1] = sy;
  4714. this.rotation = Math.atan2(-m[1] / sy, m[0] / sx);
  4715. };
  4716. /**
  4717. * Get global scale
  4718. * @return {Array.<number>}
  4719. */
  4720. transformableProto.getGlobalScale = function () {
  4721. var m = this.transform;
  4722. if (!m) {
  4723. return [1, 1];
  4724. }
  4725. var sx = Math.sqrt(m[0] * m[0] + m[1] * m[1]);
  4726. var sy = Math.sqrt(m[2] * m[2] + m[3] * m[3]);
  4727. if (m[0] < 0) {
  4728. sx = -sx;
  4729. }
  4730. if (m[3] < 0) {
  4731. sy = -sy;
  4732. }
  4733. return [sx, sy];
  4734. };
  4735. /**
  4736. * 变换坐标位置到 shape 的局部坐标空间
  4737. * @method
  4738. * @param {number} x
  4739. * @param {number} y
  4740. * @return {Array.<number>}
  4741. */
  4742. transformableProto.transformCoordToLocal = function (x, y) {
  4743. var v2 = [x, y];
  4744. var invTransform = this.invTransform;
  4745. if (invTransform) {
  4746. vector.applyTransform(v2, v2, invTransform);
  4747. }
  4748. return v2;
  4749. };
  4750. /**
  4751. * 变换局部坐标位置到全局坐标空间
  4752. * @method
  4753. * @param {number} x
  4754. * @param {number} y
  4755. * @return {Array.<number>}
  4756. */
  4757. transformableProto.transformCoordToGlobal = function (x, y) {
  4758. var v2 = [x, y];
  4759. var transform = this.transform;
  4760. if (transform) {
  4761. vector.applyTransform(v2, v2, transform);
  4762. }
  4763. return v2;
  4764. };
  4765. /**
  4766. * @static
  4767. * @param {Object} target
  4768. * @param {Array.<number>} target.origin
  4769. * @param {number} target.rotation
  4770. * @param {Array.<number>} target.position
  4771. * @param {Array.<number>} [m]
  4772. */
  4773. Transformable.getLocalTransform = function (target, m) {
  4774. m = m || [];
  4775. mIdentity(m);
  4776. var origin = target.origin;
  4777. var scale = target.scale || [1, 1];
  4778. var rotation = target.rotation || 0;
  4779. var position = target.position || [0, 0];
  4780. if (origin) {
  4781. // Translate to origin
  4782. m[4] -= origin[0];
  4783. m[5] -= origin[1];
  4784. }
  4785. matrix.scale(m, m, scale);
  4786. if (rotation) {
  4787. matrix.rotate(m, m, rotation);
  4788. }
  4789. if (origin) {
  4790. // Translate back from origin
  4791. m[4] += origin[0];
  4792. m[5] += origin[1];
  4793. }
  4794. m[4] += position[0];
  4795. m[5] += position[1];
  4796. return m;
  4797. };
  4798. var _default = Transformable;
  4799. module.exports = _default;
  4800. /***/ }),
  4801. /* 18 */
  4802. /***/ (function(module, exports, __webpack_require__) {
  4803. var LRU = __webpack_require__(14);
  4804. var kCSSColorTable = {
  4805. 'transparent': [0, 0, 0, 0],
  4806. 'aliceblue': [240, 248, 255, 1],
  4807. 'antiquewhite': [250, 235, 215, 1],
  4808. 'aqua': [0, 255, 255, 1],
  4809. 'aquamarine': [127, 255, 212, 1],
  4810. 'azure': [240, 255, 255, 1],
  4811. 'beige': [245, 245, 220, 1],
  4812. 'bisque': [255, 228, 196, 1],
  4813. 'black': [0, 0, 0, 1],
  4814. 'blanchedalmond': [255, 235, 205, 1],
  4815. 'blue': [0, 0, 255, 1],
  4816. 'blueviolet': [138, 43, 226, 1],
  4817. 'brown': [165, 42, 42, 1],
  4818. 'burlywood': [222, 184, 135, 1],
  4819. 'cadetblue': [95, 158, 160, 1],
  4820. 'chartreuse': [127, 255, 0, 1],
  4821. 'chocolate': [210, 105, 30, 1],
  4822. 'coral': [255, 127, 80, 1],
  4823. 'cornflowerblue': [100, 149, 237, 1],
  4824. 'cornsilk': [255, 248, 220, 1],
  4825. 'crimson': [220, 20, 60, 1],
  4826. 'cyan': [0, 255, 255, 1],
  4827. 'darkblue': [0, 0, 139, 1],
  4828. 'darkcyan': [0, 139, 139, 1],
  4829. 'darkgoldenrod': [184, 134, 11, 1],
  4830. 'darkgray': [169, 169, 169, 1],
  4831. 'darkgreen': [0, 100, 0, 1],
  4832. 'darkgrey': [169, 169, 169, 1],
  4833. 'darkkhaki': [189, 183, 107, 1],
  4834. 'darkmagenta': [139, 0, 139, 1],
  4835. 'darkolivegreen': [85, 107, 47, 1],
  4836. 'darkorange': [255, 140, 0, 1],
  4837. 'darkorchid': [153, 50, 204, 1],
  4838. 'darkred': [139, 0, 0, 1],
  4839. 'darksalmon': [233, 150, 122, 1],
  4840. 'darkseagreen': [143, 188, 143, 1],
  4841. 'darkslateblue': [72, 61, 139, 1],
  4842. 'darkslategray': [47, 79, 79, 1],
  4843. 'darkslategrey': [47, 79, 79, 1],
  4844. 'darkturquoise': [0, 206, 209, 1],
  4845. 'darkviolet': [148, 0, 211, 1],
  4846. 'deeppink': [255, 20, 147, 1],
  4847. 'deepskyblue': [0, 191, 255, 1],
  4848. 'dimgray': [105, 105, 105, 1],
  4849. 'dimgrey': [105, 105, 105, 1],
  4850. 'dodgerblue': [30, 144, 255, 1],
  4851. 'firebrick': [178, 34, 34, 1],
  4852. 'floralwhite': [255, 250, 240, 1],
  4853. 'forestgreen': [34, 139, 34, 1],
  4854. 'fuchsia': [255, 0, 255, 1],
  4855. 'gainsboro': [220, 220, 220, 1],
  4856. 'ghostwhite': [248, 248, 255, 1],
  4857. 'gold': [255, 215, 0, 1],
  4858. 'goldenrod': [218, 165, 32, 1],
  4859. 'gray': [128, 128, 128, 1],
  4860. 'green': [0, 128, 0, 1],
  4861. 'greenyellow': [173, 255, 47, 1],
  4862. 'grey': [128, 128, 128, 1],
  4863. 'honeydew': [240, 255, 240, 1],
  4864. 'hotpink': [255, 105, 180, 1],
  4865. 'indianred': [205, 92, 92, 1],
  4866. 'indigo': [75, 0, 130, 1],
  4867. 'ivory': [255, 255, 240, 1],
  4868. 'khaki': [240, 230, 140, 1],
  4869. 'lavender': [230, 230, 250, 1],
  4870. 'lavenderblush': [255, 240, 245, 1],
  4871. 'lawngreen': [124, 252, 0, 1],
  4872. 'lemonchiffon': [255, 250, 205, 1],
  4873. 'lightblue': [173, 216, 230, 1],
  4874. 'lightcoral': [240, 128, 128, 1],
  4875. 'lightcyan': [224, 255, 255, 1],
  4876. 'lightgoldenrodyellow': [250, 250, 210, 1],
  4877. 'lightgray': [211, 211, 211, 1],
  4878. 'lightgreen': [144, 238, 144, 1],
  4879. 'lightgrey': [211, 211, 211, 1],
  4880. 'lightpink': [255, 182, 193, 1],
  4881. 'lightsalmon': [255, 160, 122, 1],
  4882. 'lightseagreen': [32, 178, 170, 1],
  4883. 'lightskyblue': [135, 206, 250, 1],
  4884. 'lightslategray': [119, 136, 153, 1],
  4885. 'lightslategrey': [119, 136, 153, 1],
  4886. 'lightsteelblue': [176, 196, 222, 1],
  4887. 'lightyellow': [255, 255, 224, 1],
  4888. 'lime': [0, 255, 0, 1],
  4889. 'limegreen': [50, 205, 50, 1],
  4890. 'linen': [250, 240, 230, 1],
  4891. 'magenta': [255, 0, 255, 1],
  4892. 'maroon': [128, 0, 0, 1],
  4893. 'mediumaquamarine': [102, 205, 170, 1],
  4894. 'mediumblue': [0, 0, 205, 1],
  4895. 'mediumorchid': [186, 85, 211, 1],
  4896. 'mediumpurple': [147, 112, 219, 1],
  4897. 'mediumseagreen': [60, 179, 113, 1],
  4898. 'mediumslateblue': [123, 104, 238, 1],
  4899. 'mediumspringgreen': [0, 250, 154, 1],
  4900. 'mediumturquoise': [72, 209, 204, 1],
  4901. 'mediumvioletred': [199, 21, 133, 1],
  4902. 'midnightblue': [25, 25, 112, 1],
  4903. 'mintcream': [245, 255, 250, 1],
  4904. 'mistyrose': [255, 228, 225, 1],
  4905. 'moccasin': [255, 228, 181, 1],
  4906. 'navajowhite': [255, 222, 173, 1],
  4907. 'navy': [0, 0, 128, 1],
  4908. 'oldlace': [253, 245, 230, 1],
  4909. 'olive': [128, 128, 0, 1],
  4910. 'olivedrab': [107, 142, 35, 1],
  4911. 'orange': [255, 165, 0, 1],
  4912. 'orangered': [255, 69, 0, 1],
  4913. 'orchid': [218, 112, 214, 1],
  4914. 'palegoldenrod': [238, 232, 170, 1],
  4915. 'palegreen': [152, 251, 152, 1],
  4916. 'paleturquoise': [175, 238, 238, 1],
  4917. 'palevioletred': [219, 112, 147, 1],
  4918. 'papayawhip': [255, 239, 213, 1],
  4919. 'peachpuff': [255, 218, 185, 1],
  4920. 'peru': [205, 133, 63, 1],
  4921. 'pink': [255, 192, 203, 1],
  4922. 'plum': [221, 160, 221, 1],
  4923. 'powderblue': [176, 224, 230, 1],
  4924. 'purple': [128, 0, 128, 1],
  4925. 'red': [255, 0, 0, 1],
  4926. 'rosybrown': [188, 143, 143, 1],
  4927. 'royalblue': [65, 105, 225, 1],
  4928. 'saddlebrown': [139, 69, 19, 1],
  4929. 'salmon': [250, 128, 114, 1],
  4930. 'sandybrown': [244, 164, 96, 1],
  4931. 'seagreen': [46, 139, 87, 1],
  4932. 'seashell': [255, 245, 238, 1],
  4933. 'sienna': [160, 82, 45, 1],
  4934. 'silver': [192, 192, 192, 1],
  4935. 'skyblue': [135, 206, 235, 1],
  4936. 'slateblue': [106, 90, 205, 1],
  4937. 'slategray': [112, 128, 144, 1],
  4938. 'slategrey': [112, 128, 144, 1],
  4939. 'snow': [255, 250, 250, 1],
  4940. 'springgreen': [0, 255, 127, 1],
  4941. 'steelblue': [70, 130, 180, 1],
  4942. 'tan': [210, 180, 140, 1],
  4943. 'teal': [0, 128, 128, 1],
  4944. 'thistle': [216, 191, 216, 1],
  4945. 'tomato': [255, 99, 71, 1],
  4946. 'turquoise': [64, 224, 208, 1],
  4947. 'violet': [238, 130, 238, 1],
  4948. 'wheat': [245, 222, 179, 1],
  4949. 'white': [255, 255, 255, 1],
  4950. 'whitesmoke': [245, 245, 245, 1],
  4951. 'yellow': [255, 255, 0, 1],
  4952. 'yellowgreen': [154, 205, 50, 1]
  4953. };
  4954. function clampCssByte(i) {
  4955. // Clamp to integer 0 .. 255.
  4956. i = Math.round(i); // Seems to be what Chrome does (vs truncation).
  4957. return i < 0 ? 0 : i > 255 ? 255 : i;
  4958. }
  4959. function clampCssAngle(i) {
  4960. // Clamp to integer 0 .. 360.
  4961. i = Math.round(i); // Seems to be what Chrome does (vs truncation).
  4962. return i < 0 ? 0 : i > 360 ? 360 : i;
  4963. }
  4964. function clampCssFloat(f) {
  4965. // Clamp to float 0.0 .. 1.0.
  4966. return f < 0 ? 0 : f > 1 ? 1 : f;
  4967. }
  4968. function parseCssInt(str) {
  4969. // int or percentage.
  4970. if (str.length && str.charAt(str.length - 1) === '%') {
  4971. return clampCssByte(parseFloat(str) / 100 * 255);
  4972. }
  4973. return clampCssByte(parseInt(str, 10));
  4974. }
  4975. function parseCssFloat(str) {
  4976. // float or percentage.
  4977. if (str.length && str.charAt(str.length - 1) === '%') {
  4978. return clampCssFloat(parseFloat(str) / 100);
  4979. }
  4980. return clampCssFloat(parseFloat(str));
  4981. }
  4982. function cssHueToRgb(m1, m2, h) {
  4983. if (h < 0) {
  4984. h += 1;
  4985. } else if (h > 1) {
  4986. h -= 1;
  4987. }
  4988. if (h * 6 < 1) {
  4989. return m1 + (m2 - m1) * h * 6;
  4990. }
  4991. if (h * 2 < 1) {
  4992. return m2;
  4993. }
  4994. if (h * 3 < 2) {
  4995. return m1 + (m2 - m1) * (2 / 3 - h) * 6;
  4996. }
  4997. return m1;
  4998. }
  4999. function lerpNumber(a, b, p) {
  5000. return a + (b - a) * p;
  5001. }
  5002. function setRgba(out, r, g, b, a) {
  5003. out[0] = r;
  5004. out[1] = g;
  5005. out[2] = b;
  5006. out[3] = a;
  5007. return out;
  5008. }
  5009. function copyRgba(out, a) {
  5010. out[0] = a[0];
  5011. out[1] = a[1];
  5012. out[2] = a[2];
  5013. out[3] = a[3];
  5014. return out;
  5015. }
  5016. var colorCache = new LRU(20);
  5017. var lastRemovedArr = null;
  5018. function putToCache(colorStr, rgbaArr) {
  5019. // Reuse removed array
  5020. if (lastRemovedArr) {
  5021. copyRgba(lastRemovedArr, rgbaArr);
  5022. }
  5023. lastRemovedArr = colorCache.put(colorStr, lastRemovedArr || rgbaArr.slice());
  5024. }
  5025. /**
  5026. * @param {string} colorStr
  5027. * @param {Array.<number>} out
  5028. * @return {Array.<number>}
  5029. * @memberOf module:zrender/util/color
  5030. */
  5031. function parse(colorStr, rgbaArr) {
  5032. if (!colorStr) {
  5033. return;
  5034. }
  5035. rgbaArr = rgbaArr || [];
  5036. var cached = colorCache.get(colorStr);
  5037. if (cached) {
  5038. return copyRgba(rgbaArr, cached);
  5039. } // colorStr may be not string
  5040. colorStr = colorStr + ''; // Remove all whitespace, not compliant, but should just be more accepting.
  5041. var str = colorStr.replace(/ /g, '').toLowerCase(); // Color keywords (and transparent) lookup.
  5042. if (str in kCSSColorTable) {
  5043. copyRgba(rgbaArr, kCSSColorTable[str]);
  5044. putToCache(colorStr, rgbaArr);
  5045. return rgbaArr;
  5046. } // #abc and #abc123 syntax.
  5047. if (str.charAt(0) === '#') {
  5048. if (str.length === 4) {
  5049. var iv = parseInt(str.substr(1), 16); // TODO(deanm): Stricter parsing.
  5050. if (!(iv >= 0 && iv <= 0xfff)) {
  5051. setRgba(rgbaArr, 0, 0, 0, 1);
  5052. return; // Covers NaN.
  5053. }
  5054. setRgba(rgbaArr, (iv & 0xf00) >> 4 | (iv & 0xf00) >> 8, iv & 0xf0 | (iv & 0xf0) >> 4, iv & 0xf | (iv & 0xf) << 4, 1);
  5055. putToCache(colorStr, rgbaArr);
  5056. return rgbaArr;
  5057. } else if (str.length === 7) {
  5058. var iv = parseInt(str.substr(1), 16); // TODO(deanm): Stricter parsing.
  5059. if (!(iv >= 0 && iv <= 0xffffff)) {
  5060. setRgba(rgbaArr, 0, 0, 0, 1);
  5061. return; // Covers NaN.
  5062. }
  5063. setRgba(rgbaArr, (iv & 0xff0000) >> 16, (iv & 0xff00) >> 8, iv & 0xff, 1);
  5064. putToCache(colorStr, rgbaArr);
  5065. return rgbaArr;
  5066. }
  5067. return;
  5068. }
  5069. var op = str.indexOf('('),
  5070. ep = str.indexOf(')');
  5071. if (op !== -1 && ep + 1 === str.length) {
  5072. var fname = str.substr(0, op);
  5073. var params = str.substr(op + 1, ep - (op + 1)).split(',');
  5074. var alpha = 1; // To allow case fallthrough.
  5075. switch (fname) {
  5076. case 'rgba':
  5077. if (params.length !== 4) {
  5078. setRgba(rgbaArr, 0, 0, 0, 1);
  5079. return;
  5080. }
  5081. alpha = parseCssFloat(params.pop());
  5082. // jshint ignore:line
  5083. // Fall through.
  5084. case 'rgb':
  5085. if (params.length !== 3) {
  5086. setRgba(rgbaArr, 0, 0, 0, 1);
  5087. return;
  5088. }
  5089. setRgba(rgbaArr, parseCssInt(params[0]), parseCssInt(params[1]), parseCssInt(params[2]), alpha);
  5090. putToCache(colorStr, rgbaArr);
  5091. return rgbaArr;
  5092. case 'hsla':
  5093. if (params.length !== 4) {
  5094. setRgba(rgbaArr, 0, 0, 0, 1);
  5095. return;
  5096. }
  5097. params[3] = parseCssFloat(params[3]);
  5098. hsla2rgba(params, rgbaArr);
  5099. putToCache(colorStr, rgbaArr);
  5100. return rgbaArr;
  5101. case 'hsl':
  5102. if (params.length !== 3) {
  5103. setRgba(rgbaArr, 0, 0, 0, 1);
  5104. return;
  5105. }
  5106. hsla2rgba(params, rgbaArr);
  5107. putToCache(colorStr, rgbaArr);
  5108. return rgbaArr;
  5109. default:
  5110. return;
  5111. }
  5112. }
  5113. setRgba(rgbaArr, 0, 0, 0, 1);
  5114. return;
  5115. }
  5116. /**
  5117. * @param {Array.<number>} hsla
  5118. * @param {Array.<number>} rgba
  5119. * @return {Array.<number>} rgba
  5120. */
  5121. function hsla2rgba(hsla, rgba) {
  5122. var h = (parseFloat(hsla[0]) % 360 + 360) % 360 / 360; // 0 .. 1
  5123. // NOTE(deanm): According to the CSS spec s/l should only be
  5124. // percentages, but we don't bother and let float or percentage.
  5125. var s = parseCssFloat(hsla[1]);
  5126. var l = parseCssFloat(hsla[2]);
  5127. var m2 = l <= 0.5 ? l * (s + 1) : l + s - l * s;
  5128. var m1 = l * 2 - m2;
  5129. rgba = rgba || [];
  5130. setRgba(rgba, clampCssByte(cssHueToRgb(m1, m2, h + 1 / 3) * 255), clampCssByte(cssHueToRgb(m1, m2, h) * 255), clampCssByte(cssHueToRgb(m1, m2, h - 1 / 3) * 255), 1);
  5131. if (hsla.length === 4) {
  5132. rgba[3] = hsla[3];
  5133. }
  5134. return rgba;
  5135. }
  5136. /**
  5137. * @param {Array.<number>} rgba
  5138. * @return {Array.<number>} hsla
  5139. */
  5140. function rgba2hsla(rgba) {
  5141. if (!rgba) {
  5142. return;
  5143. } // RGB from 0 to 255
  5144. var R = rgba[0] / 255;
  5145. var G = rgba[1] / 255;
  5146. var B = rgba[2] / 255;
  5147. var vMin = Math.min(R, G, B); // Min. value of RGB
  5148. var vMax = Math.max(R, G, B); // Max. value of RGB
  5149. var delta = vMax - vMin; // Delta RGB value
  5150. var L = (vMax + vMin) / 2;
  5151. var H;
  5152. var S; // HSL results from 0 to 1
  5153. if (delta === 0) {
  5154. H = 0;
  5155. S = 0;
  5156. } else {
  5157. if (L < 0.5) {
  5158. S = delta / (vMax + vMin);
  5159. } else {
  5160. S = delta / (2 - vMax - vMin);
  5161. }
  5162. var deltaR = ((vMax - R) / 6 + delta / 2) / delta;
  5163. var deltaG = ((vMax - G) / 6 + delta / 2) / delta;
  5164. var deltaB = ((vMax - B) / 6 + delta / 2) / delta;
  5165. if (R === vMax) {
  5166. H = deltaB - deltaG;
  5167. } else if (G === vMax) {
  5168. H = 1 / 3 + deltaR - deltaB;
  5169. } else if (B === vMax) {
  5170. H = 2 / 3 + deltaG - deltaR;
  5171. }
  5172. if (H < 0) {
  5173. H += 1;
  5174. }
  5175. if (H > 1) {
  5176. H -= 1;
  5177. }
  5178. }
  5179. var hsla = [H * 360, S, L];
  5180. if (rgba[3] != null) {
  5181. hsla.push(rgba[3]);
  5182. }
  5183. return hsla;
  5184. }
  5185. /**
  5186. * @param {string} color
  5187. * @param {number} level
  5188. * @return {string}
  5189. * @memberOf module:zrender/util/color
  5190. */
  5191. function lift(color, level) {
  5192. var colorArr = parse(color);
  5193. if (colorArr) {
  5194. for (var i = 0; i < 3; i++) {
  5195. if (level < 0) {
  5196. colorArr[i] = colorArr[i] * (1 - level) | 0;
  5197. } else {
  5198. colorArr[i] = (255 - colorArr[i]) * level + colorArr[i] | 0;
  5199. }
  5200. }
  5201. return stringify(colorArr, colorArr.length === 4 ? 'rgba' : 'rgb');
  5202. }
  5203. }
  5204. /**
  5205. * @param {string} color
  5206. * @return {string}
  5207. * @memberOf module:zrender/util/color
  5208. */
  5209. function toHex(color) {
  5210. var colorArr = parse(color);
  5211. if (colorArr) {
  5212. return ((1 << 24) + (colorArr[0] << 16) + (colorArr[1] << 8) + +colorArr[2]).toString(16).slice(1);
  5213. }
  5214. }
  5215. /**
  5216. * Map value to color. Faster than lerp methods because color is represented by rgba array.
  5217. * @param {number} normalizedValue A float between 0 and 1.
  5218. * @param {Array.<Array.<number>>} colors List of rgba color array
  5219. * @param {Array.<number>} [out] Mapped gba color array
  5220. * @return {Array.<number>} will be null/undefined if input illegal.
  5221. */
  5222. function fastLerp(normalizedValue, colors, out) {
  5223. if (!(colors && colors.length) || !(normalizedValue >= 0 && normalizedValue <= 1)) {
  5224. return;
  5225. }
  5226. out = out || [];
  5227. var value = normalizedValue * (colors.length - 1);
  5228. var leftIndex = Math.floor(value);
  5229. var rightIndex = Math.ceil(value);
  5230. var leftColor = colors[leftIndex];
  5231. var rightColor = colors[rightIndex];
  5232. var dv = value - leftIndex;
  5233. out[0] = clampCssByte(lerpNumber(leftColor[0], rightColor[0], dv));
  5234. out[1] = clampCssByte(lerpNumber(leftColor[1], rightColor[1], dv));
  5235. out[2] = clampCssByte(lerpNumber(leftColor[2], rightColor[2], dv));
  5236. out[3] = clampCssFloat(lerpNumber(leftColor[3], rightColor[3], dv));
  5237. return out;
  5238. }
  5239. /**
  5240. * @deprecated
  5241. */
  5242. var fastMapToColor = fastLerp;
  5243. /**
  5244. * @param {number} normalizedValue A float between 0 and 1.
  5245. * @param {Array.<string>} colors Color list.
  5246. * @param {boolean=} fullOutput Default false.
  5247. * @return {(string|Object)} Result color. If fullOutput,
  5248. * return {color: ..., leftIndex: ..., rightIndex: ..., value: ...},
  5249. * @memberOf module:zrender/util/color
  5250. */
  5251. function lerp(normalizedValue, colors, fullOutput) {
  5252. if (!(colors && colors.length) || !(normalizedValue >= 0 && normalizedValue <= 1)) {
  5253. return;
  5254. }
  5255. var value = normalizedValue * (colors.length - 1);
  5256. var leftIndex = Math.floor(value);
  5257. var rightIndex = Math.ceil(value);
  5258. var leftColor = parse(colors[leftIndex]);
  5259. var rightColor = parse(colors[rightIndex]);
  5260. var dv = value - leftIndex;
  5261. var color = stringify([clampCssByte(lerpNumber(leftColor[0], rightColor[0], dv)), clampCssByte(lerpNumber(leftColor[1], rightColor[1], dv)), clampCssByte(lerpNumber(leftColor[2], rightColor[2], dv)), clampCssFloat(lerpNumber(leftColor[3], rightColor[3], dv))], 'rgba');
  5262. return fullOutput ? {
  5263. color: color,
  5264. leftIndex: leftIndex,
  5265. rightIndex: rightIndex,
  5266. value: value
  5267. } : color;
  5268. }
  5269. /**
  5270. * @deprecated
  5271. */
  5272. var mapToColor = lerp;
  5273. /**
  5274. * @param {string} color
  5275. * @param {number=} h 0 ~ 360, ignore when null.
  5276. * @param {number=} s 0 ~ 1, ignore when null.
  5277. * @param {number=} l 0 ~ 1, ignore when null.
  5278. * @return {string} Color string in rgba format.
  5279. * @memberOf module:zrender/util/color
  5280. */
  5281. function modifyHSL(color, h, s, l) {
  5282. color = parse(color);
  5283. if (color) {
  5284. color = rgba2hsla(color);
  5285. h != null && (color[0] = clampCssAngle(h));
  5286. s != null && (color[1] = parseCssFloat(s));
  5287. l != null && (color[2] = parseCssFloat(l));
  5288. return stringify(hsla2rgba(color), 'rgba');
  5289. }
  5290. }
  5291. /**
  5292. * @param {string} color
  5293. * @param {number=} alpha 0 ~ 1
  5294. * @return {string} Color string in rgba format.
  5295. * @memberOf module:zrender/util/color
  5296. */
  5297. function modifyAlpha(color, alpha) {
  5298. color = parse(color);
  5299. if (color && alpha != null) {
  5300. color[3] = clampCssFloat(alpha);
  5301. return stringify(color, 'rgba');
  5302. }
  5303. }
  5304. /**
  5305. * @param {Array.<number>} arrColor like [12,33,44,0.4]
  5306. * @param {string} type 'rgba', 'hsva', ...
  5307. * @return {string} Result color. (If input illegal, return undefined).
  5308. */
  5309. function stringify(arrColor, type) {
  5310. if (!arrColor || !arrColor.length) {
  5311. return;
  5312. }
  5313. var colorStr = arrColor[0] + ',' + arrColor[1] + ',' + arrColor[2];
  5314. if (type === 'rgba' || type === 'hsva' || type === 'hsla') {
  5315. colorStr += ',' + arrColor[3];
  5316. }
  5317. return type + '(' + colorStr + ')';
  5318. }
  5319. exports.parse = parse;
  5320. exports.lift = lift;
  5321. exports.toHex = toHex;
  5322. exports.fastLerp = fastLerp;
  5323. exports.fastMapToColor = fastMapToColor;
  5324. exports.lerp = lerp;
  5325. exports.mapToColor = mapToColor;
  5326. exports.modifyHSL = modifyHSL;
  5327. exports.modifyAlpha = modifyAlpha;
  5328. exports.stringify = stringify;
  5329. /***/ }),
  5330. /* 19 */
  5331. /***/ (function(module, exports) {
  5332. var dpr = 1; // If in browser environment
  5333. if (typeof window !== 'undefined') {
  5334. dpr = Math.max(window.devicePixelRatio || 1, 1);
  5335. }
  5336. /**
  5337. * config默认配置项
  5338. * @exports zrender/config
  5339. * @author Kener (@Kener-林峰, kener.linfeng@gmail.com)
  5340. */
  5341. /**
  5342. * debug日志选项:catchBrushException为true下有效
  5343. * 0 : 不生成debug数据,发布用
  5344. * 1 : 异常抛出,调试用
  5345. * 2 : 控制台输出,调试用
  5346. */
  5347. var debugMode = 0; // retina 屏幕优化
  5348. var devicePixelRatio = dpr;
  5349. exports.debugMode = debugMode;
  5350. exports.devicePixelRatio = devicePixelRatio;
  5351. /***/ }),
  5352. /* 20 */
  5353. /***/ (function(module, exports, __webpack_require__) {
  5354. var _util = __webpack_require__(0);
  5355. var retrieve2 = _util.retrieve2;
  5356. var retrieve3 = _util.retrieve3;
  5357. var each = _util.each;
  5358. var normalizeCssArray = _util.normalizeCssArray;
  5359. var isString = _util.isString;
  5360. var isObject = _util.isObject;
  5361. var textContain = __webpack_require__(5);
  5362. var roundRectHelper = __webpack_require__(21);
  5363. var imageHelper = __webpack_require__(10);
  5364. // TODO: Have not support 'start', 'end' yet.
  5365. var VALID_TEXT_ALIGN = {
  5366. left: 1,
  5367. right: 1,
  5368. center: 1
  5369. };
  5370. var VALID_TEXT_VERTICAL_ALIGN = {
  5371. top: 1,
  5372. bottom: 1,
  5373. middle: 1
  5374. };
  5375. /**
  5376. * @param {module:zrender/graphic/Style} style
  5377. * @return {module:zrender/graphic/Style} The input style.
  5378. */
  5379. function normalizeTextStyle(style) {
  5380. normalizeStyle(style);
  5381. each(style.rich, normalizeStyle);
  5382. return style;
  5383. }
  5384. function normalizeStyle(style) {
  5385. if (style) {
  5386. style.font = textContain.makeFont(style);
  5387. var textAlign = style.textAlign;
  5388. textAlign === 'middle' && (textAlign = 'center');
  5389. style.textAlign = textAlign == null || VALID_TEXT_ALIGN[textAlign] ? textAlign : 'left'; // Compatible with textBaseline.
  5390. var textVerticalAlign = style.textVerticalAlign || style.textBaseline;
  5391. textVerticalAlign === 'center' && (textVerticalAlign = 'middle');
  5392. style.textVerticalAlign = textVerticalAlign == null || VALID_TEXT_VERTICAL_ALIGN[textVerticalAlign] ? textVerticalAlign : 'top';
  5393. var textPadding = style.textPadding;
  5394. if (textPadding) {
  5395. style.textPadding = normalizeCssArray(style.textPadding);
  5396. }
  5397. }
  5398. }
  5399. /**
  5400. * @param {CanvasRenderingContext2D} ctx
  5401. * @param {string} text
  5402. * @param {module:zrender/graphic/Style} style
  5403. * @param {Object|boolean} [rect] {x, y, width, height}
  5404. * If set false, rect text is not used.
  5405. */
  5406. function renderText(hostEl, ctx, text, style, rect) {
  5407. style.rich ? renderRichText(hostEl, ctx, text, style, rect) : renderPlainText(hostEl, ctx, text, style, rect);
  5408. }
  5409. function renderPlainText(hostEl, ctx, text, style, rect) {
  5410. var font = setCtx(ctx, 'font', style.font || textContain.DEFAULT_FONT);
  5411. var textPadding = style.textPadding;
  5412. var contentBlock = hostEl.__textCotentBlock;
  5413. if (!contentBlock || hostEl.__dirty) {
  5414. contentBlock = hostEl.__textCotentBlock = textContain.parsePlainText(text, font, textPadding, style.truncate);
  5415. }
  5416. var outerHeight = contentBlock.outerHeight;
  5417. var textLines = contentBlock.lines;
  5418. var lineHeight = contentBlock.lineHeight;
  5419. var boxPos = getBoxPosition(outerHeight, style, rect);
  5420. var baseX = boxPos.baseX;
  5421. var baseY = boxPos.baseY;
  5422. var textAlign = boxPos.textAlign;
  5423. var textVerticalAlign = boxPos.textVerticalAlign; // Origin of textRotation should be the base point of text drawing.
  5424. applyTextRotation(ctx, style, rect, baseX, baseY);
  5425. var boxY = textContain.adjustTextY(baseY, outerHeight, textVerticalAlign);
  5426. var textX = baseX;
  5427. var textY = boxY;
  5428. var needDrawBg = needDrawBackground(style);
  5429. if (needDrawBg || textPadding) {
  5430. // Consider performance, do not call getTextWidth util necessary.
  5431. var textWidth = textContain.getWidth(text, font);
  5432. var outerWidth = textWidth;
  5433. textPadding && (outerWidth += textPadding[1] + textPadding[3]);
  5434. var boxX = textContain.adjustTextX(baseX, outerWidth, textAlign);
  5435. needDrawBg && drawBackground(hostEl, ctx, style, boxX, boxY, outerWidth, outerHeight);
  5436. if (textPadding) {
  5437. textX = getTextXForPadding(baseX, textAlign, textPadding);
  5438. textY += textPadding[0];
  5439. }
  5440. }
  5441. setCtx(ctx, 'textAlign', textAlign || 'left'); // Force baseline to be "middle". Otherwise, if using "top", the
  5442. // text will offset downward a little bit in font "Microsoft YaHei".
  5443. setCtx(ctx, 'textBaseline', 'middle'); // Always set shadowBlur and shadowOffset to avoid leak from displayable.
  5444. setCtx(ctx, 'shadowBlur', style.textShadowBlur || 0);
  5445. setCtx(ctx, 'shadowColor', style.textShadowColor || 'transparent');
  5446. setCtx(ctx, 'shadowOffsetX', style.textShadowOffsetX || 0);
  5447. setCtx(ctx, 'shadowOffsetY', style.textShadowOffsetY || 0); // `textBaseline` is set as 'middle'.
  5448. textY += lineHeight / 2;
  5449. var textStrokeWidth = style.textStrokeWidth;
  5450. var textStroke = getStroke(style.textStroke, textStrokeWidth);
  5451. var textFill = getFill(style.textFill);
  5452. if (textStroke) {
  5453. setCtx(ctx, 'lineWidth', textStrokeWidth);
  5454. setCtx(ctx, 'strokeStyle', textStroke);
  5455. }
  5456. if (textFill) {
  5457. setCtx(ctx, 'fillStyle', textFill);
  5458. }
  5459. for (var i = 0; i < textLines.length; i++) {
  5460. // Fill after stroke so the outline will not cover the main part.
  5461. textStroke && ctx.strokeText(textLines[i], textX, textY);
  5462. textFill && ctx.fillText(textLines[i], textX, textY);
  5463. textY += lineHeight;
  5464. }
  5465. }
  5466. function renderRichText(hostEl, ctx, text, style, rect) {
  5467. var contentBlock = hostEl.__textCotentBlock;
  5468. if (!contentBlock || hostEl.__dirty) {
  5469. contentBlock = hostEl.__textCotentBlock = textContain.parseRichText(text, style);
  5470. }
  5471. drawRichText(hostEl, ctx, contentBlock, style, rect);
  5472. }
  5473. function drawRichText(hostEl, ctx, contentBlock, style, rect) {
  5474. var contentWidth = contentBlock.width;
  5475. var outerWidth = contentBlock.outerWidth;
  5476. var outerHeight = contentBlock.outerHeight;
  5477. var textPadding = style.textPadding;
  5478. var boxPos = getBoxPosition(outerHeight, style, rect);
  5479. var baseX = boxPos.baseX;
  5480. var baseY = boxPos.baseY;
  5481. var textAlign = boxPos.textAlign;
  5482. var textVerticalAlign = boxPos.textVerticalAlign; // Origin of textRotation should be the base point of text drawing.
  5483. applyTextRotation(ctx, style, rect, baseX, baseY);
  5484. var boxX = textContain.adjustTextX(baseX, outerWidth, textAlign);
  5485. var boxY = textContain.adjustTextY(baseY, outerHeight, textVerticalAlign);
  5486. var xLeft = boxX;
  5487. var lineTop = boxY;
  5488. if (textPadding) {
  5489. xLeft += textPadding[3];
  5490. lineTop += textPadding[0];
  5491. }
  5492. var xRight = xLeft + contentWidth;
  5493. needDrawBackground(style) && drawBackground(hostEl, ctx, style, boxX, boxY, outerWidth, outerHeight);
  5494. for (var i = 0; i < contentBlock.lines.length; i++) {
  5495. var line = contentBlock.lines[i];
  5496. var tokens = line.tokens;
  5497. var tokenCount = tokens.length;
  5498. var lineHeight = line.lineHeight;
  5499. var usedWidth = line.width;
  5500. var leftIndex = 0;
  5501. var lineXLeft = xLeft;
  5502. var lineXRight = xRight;
  5503. var rightIndex = tokenCount - 1;
  5504. var token;
  5505. while (leftIndex < tokenCount && (token = tokens[leftIndex], !token.textAlign || token.textAlign === 'left')) {
  5506. placeToken(hostEl, ctx, token, style, lineHeight, lineTop, lineXLeft, 'left');
  5507. usedWidth -= token.width;
  5508. lineXLeft += token.width;
  5509. leftIndex++;
  5510. }
  5511. while (rightIndex >= 0 && (token = tokens[rightIndex], token.textAlign === 'right')) {
  5512. placeToken(hostEl, ctx, token, style, lineHeight, lineTop, lineXRight, 'right');
  5513. usedWidth -= token.width;
  5514. lineXRight -= token.width;
  5515. rightIndex--;
  5516. } // The other tokens are placed as textAlign 'center' if there is enough space.
  5517. lineXLeft += (contentWidth - (lineXLeft - xLeft) - (xRight - lineXRight) - usedWidth) / 2;
  5518. while (leftIndex <= rightIndex) {
  5519. token = tokens[leftIndex]; // Consider width specified by user, use 'center' rather than 'left'.
  5520. placeToken(hostEl, ctx, token, style, lineHeight, lineTop, lineXLeft + token.width / 2, 'center');
  5521. lineXLeft += token.width;
  5522. leftIndex++;
  5523. }
  5524. lineTop += lineHeight;
  5525. }
  5526. }
  5527. function applyTextRotation(ctx, style, rect, x, y) {
  5528. // textRotation only apply in RectText.
  5529. if (rect && style.textRotation) {
  5530. var origin = style.textOrigin;
  5531. if (origin === 'center') {
  5532. x = rect.width / 2 + rect.x;
  5533. y = rect.height / 2 + rect.y;
  5534. } else if (origin) {
  5535. x = origin[0] + rect.x;
  5536. y = origin[1] + rect.y;
  5537. }
  5538. ctx.translate(x, y); // Positive: anticlockwise
  5539. ctx.rotate(-style.textRotation);
  5540. ctx.translate(-x, -y);
  5541. }
  5542. }
  5543. function placeToken(hostEl, ctx, token, style, lineHeight, lineTop, x, textAlign) {
  5544. var tokenStyle = style.rich[token.styleName] || {}; // 'ctx.textBaseline' is always set as 'middle', for sake of
  5545. // the bias of "Microsoft YaHei".
  5546. var textVerticalAlign = token.textVerticalAlign;
  5547. var y = lineTop + lineHeight / 2;
  5548. if (textVerticalAlign === 'top') {
  5549. y = lineTop + token.height / 2;
  5550. } else if (textVerticalAlign === 'bottom') {
  5551. y = lineTop + lineHeight - token.height / 2;
  5552. }
  5553. !token.isLineHolder && needDrawBackground(tokenStyle) && drawBackground(hostEl, ctx, tokenStyle, textAlign === 'right' ? x - token.width : textAlign === 'center' ? x - token.width / 2 : x, y - token.height / 2, token.width, token.height);
  5554. var textPadding = token.textPadding;
  5555. if (textPadding) {
  5556. x = getTextXForPadding(x, textAlign, textPadding);
  5557. y -= token.height / 2 - textPadding[2] - token.textHeight / 2;
  5558. }
  5559. setCtx(ctx, 'shadowBlur', retrieve3(tokenStyle.textShadowBlur, style.textShadowBlur, 0));
  5560. setCtx(ctx, 'shadowColor', tokenStyle.textShadowColor || style.textShadowColor || 'transparent');
  5561. setCtx(ctx, 'shadowOffsetX', retrieve3(tokenStyle.textShadowOffsetX, style.textShadowOffsetX, 0));
  5562. setCtx(ctx, 'shadowOffsetY', retrieve3(tokenStyle.textShadowOffsetY, style.textShadowOffsetY, 0));
  5563. setCtx(ctx, 'textAlign', textAlign); // Force baseline to be "middle". Otherwise, if using "top", the
  5564. // text will offset downward a little bit in font "Microsoft YaHei".
  5565. setCtx(ctx, 'textBaseline', 'middle');
  5566. setCtx(ctx, 'font', token.font || textContain.DEFAULT_FONT);
  5567. var textStroke = getStroke(tokenStyle.textStroke || style.textStroke, textStrokeWidth);
  5568. var textFill = getFill(tokenStyle.textFill || style.textFill);
  5569. var textStrokeWidth = retrieve2(tokenStyle.textStrokeWidth, style.textStrokeWidth); // Fill after stroke so the outline will not cover the main part.
  5570. if (textStroke) {
  5571. setCtx(ctx, 'lineWidth', textStrokeWidth);
  5572. setCtx(ctx, 'strokeStyle', textStroke);
  5573. ctx.strokeText(token.text, x, y);
  5574. }
  5575. if (textFill) {
  5576. setCtx(ctx, 'fillStyle', textFill);
  5577. ctx.fillText(token.text, x, y);
  5578. }
  5579. }
  5580. function needDrawBackground(style) {
  5581. return style.textBackgroundColor || style.textBorderWidth && style.textBorderColor;
  5582. } // style: {textBackgroundColor, textBorderWidth, textBorderColor, textBorderRadius}
  5583. // shape: {x, y, width, height}
  5584. function drawBackground(hostEl, ctx, style, x, y, width, height) {
  5585. var textBackgroundColor = style.textBackgroundColor;
  5586. var textBorderWidth = style.textBorderWidth;
  5587. var textBorderColor = style.textBorderColor;
  5588. var isPlainBg = isString(textBackgroundColor);
  5589. setCtx(ctx, 'shadowBlur', style.textBoxShadowBlur || 0);
  5590. setCtx(ctx, 'shadowColor', style.textBoxShadowColor || 'transparent');
  5591. setCtx(ctx, 'shadowOffsetX', style.textBoxShadowOffsetX || 0);
  5592. setCtx(ctx, 'shadowOffsetY', style.textBoxShadowOffsetY || 0);
  5593. if (isPlainBg || textBorderWidth && textBorderColor) {
  5594. ctx.beginPath();
  5595. var textBorderRadius = style.textBorderRadius;
  5596. if (!textBorderRadius) {
  5597. ctx.rect(x, y, width, height);
  5598. } else {
  5599. roundRectHelper.buildPath(ctx, {
  5600. x: x,
  5601. y: y,
  5602. width: width,
  5603. height: height,
  5604. r: textBorderRadius
  5605. });
  5606. }
  5607. ctx.closePath();
  5608. }
  5609. if (isPlainBg) {
  5610. setCtx(ctx, 'fillStyle', textBackgroundColor);
  5611. ctx.fill();
  5612. } else if (isObject(textBackgroundColor)) {
  5613. var image = textBackgroundColor.image;
  5614. image = imageHelper.createOrUpdateImage(image, null, hostEl, onBgImageLoaded, textBackgroundColor);
  5615. if (image && imageHelper.isImageReady(image)) {
  5616. ctx.drawImage(image, x, y, width, height);
  5617. }
  5618. }
  5619. if (textBorderWidth && textBorderColor) {
  5620. setCtx(ctx, 'lineWidth', textBorderWidth);
  5621. setCtx(ctx, 'strokeStyle', textBorderColor);
  5622. ctx.stroke();
  5623. }
  5624. }
  5625. function onBgImageLoaded(image, textBackgroundColor) {
  5626. // Replace image, so that `contain/text.js#parseRichText`
  5627. // will get correct result in next tick.
  5628. textBackgroundColor.image = image;
  5629. }
  5630. function getBoxPosition(blockHeiht, style, rect) {
  5631. var baseX = style.x || 0;
  5632. var baseY = style.y || 0;
  5633. var textAlign = style.textAlign;
  5634. var textVerticalAlign = style.textVerticalAlign; // Text position represented by coord
  5635. if (rect) {
  5636. var textPosition = style.textPosition;
  5637. if (textPosition instanceof Array) {
  5638. // Percent
  5639. baseX = rect.x + parsePercent(textPosition[0], rect.width);
  5640. baseY = rect.y + parsePercent(textPosition[1], rect.height);
  5641. } else {
  5642. var res = textContain.adjustTextPositionOnRect(textPosition, rect, style.textDistance);
  5643. baseX = res.x;
  5644. baseY = res.y; // Default align and baseline when has textPosition
  5645. textAlign = textAlign || res.textAlign;
  5646. textVerticalAlign = textVerticalAlign || res.textVerticalAlign;
  5647. } // textOffset is only support in RectText, otherwise
  5648. // we have to adjust boundingRect for textOffset.
  5649. var textOffset = style.textOffset;
  5650. if (textOffset) {
  5651. baseX += textOffset[0];
  5652. baseY += textOffset[1];
  5653. }
  5654. }
  5655. return {
  5656. baseX: baseX,
  5657. baseY: baseY,
  5658. textAlign: textAlign,
  5659. textVerticalAlign: textVerticalAlign
  5660. };
  5661. }
  5662. function setCtx(ctx, prop, value) {
  5663. // FIXME ??? performance try
  5664. // if (ctx.__currentValues[prop] !== value) {
  5665. // ctx[prop] = ctx.__currentValues[prop] = value;
  5666. ctx[prop] = value; // }
  5667. return ctx[prop];
  5668. }
  5669. /**
  5670. * @param {string} [stroke] If specified, do not check style.textStroke.
  5671. * @param {string} [lineWidth] If specified, do not check style.textStroke.
  5672. * @param {number} style
  5673. */
  5674. function getStroke(stroke, lineWidth) {
  5675. return stroke == null || lineWidth <= 0 || stroke === 'transparent' || stroke === 'none' ? null // TODO pattern and gradient?
  5676. : stroke.image || stroke.colorStops ? '#000' : stroke;
  5677. }
  5678. function getFill(fill) {
  5679. return fill == null || fill === 'none' ? null // TODO pattern and gradient?
  5680. : fill.image || fill.colorStops ? '#000' : fill;
  5681. }
  5682. function parsePercent(value, maxValue) {
  5683. if (typeof value === 'string') {
  5684. if (value.lastIndexOf('%') >= 0) {
  5685. return parseFloat(value) / 100 * maxValue;
  5686. }
  5687. return parseFloat(value);
  5688. }
  5689. return value;
  5690. }
  5691. function getTextXForPadding(x, textAlign, textPadding) {
  5692. return textAlign === 'right' ? x - textPadding[1] : textAlign === 'center' ? x + textPadding[3] / 2 - textPadding[1] / 2 : x + textPadding[3];
  5693. }
  5694. /**
  5695. * @param {string} text
  5696. * @param {module:zrender/Style} style
  5697. * @return {boolean}
  5698. */
  5699. function needDrawText(text, style) {
  5700. return text != null && (text || style.textBackgroundColor || style.textBorderWidth && style.textBorderColor || style.textPadding);
  5701. }
  5702. exports.normalizeTextStyle = normalizeTextStyle;
  5703. exports.renderText = renderText;
  5704. exports.getStroke = getStroke;
  5705. exports.getFill = getFill;
  5706. exports.needDrawText = needDrawText;
  5707. /***/ }),
  5708. /* 21 */
  5709. /***/ (function(module, exports) {
  5710. function buildPath(ctx, shape) {
  5711. var x = shape.x;
  5712. var y = shape.y;
  5713. var width = shape.width;
  5714. var height = shape.height;
  5715. var r = shape.r;
  5716. var r1;
  5717. var r2;
  5718. var r3;
  5719. var r4; // Convert width and height to positive for better borderRadius
  5720. if (width < 0) {
  5721. x = x + width;
  5722. width = -width;
  5723. }
  5724. if (height < 0) {
  5725. y = y + height;
  5726. height = -height;
  5727. }
  5728. if (typeof r === 'number') {
  5729. r1 = r2 = r3 = r4 = r;
  5730. } else if (r instanceof Array) {
  5731. if (r.length === 1) {
  5732. r1 = r2 = r3 = r4 = r[0];
  5733. } else if (r.length === 2) {
  5734. r1 = r3 = r[0];
  5735. r2 = r4 = r[1];
  5736. } else if (r.length === 3) {
  5737. r1 = r[0];
  5738. r2 = r4 = r[1];
  5739. r3 = r[2];
  5740. } else {
  5741. r1 = r[0];
  5742. r2 = r[1];
  5743. r3 = r[2];
  5744. r4 = r[3];
  5745. }
  5746. } else {
  5747. r1 = r2 = r3 = r4 = 0;
  5748. }
  5749. var total;
  5750. if (r1 + r2 > width) {
  5751. total = r1 + r2;
  5752. r1 *= width / total;
  5753. r2 *= width / total;
  5754. }
  5755. if (r3 + r4 > width) {
  5756. total = r3 + r4;
  5757. r3 *= width / total;
  5758. r4 *= width / total;
  5759. }
  5760. if (r2 + r3 > height) {
  5761. total = r2 + r3;
  5762. r2 *= height / total;
  5763. r3 *= height / total;
  5764. }
  5765. if (r1 + r4 > height) {
  5766. total = r1 + r4;
  5767. r1 *= height / total;
  5768. r4 *= height / total;
  5769. }
  5770. ctx.moveTo(x + r1, y);
  5771. ctx.lineTo(x + width - r2, y);
  5772. r2 !== 0 && ctx.quadraticCurveTo(x + width, y, x + width, y + r2);
  5773. ctx.lineTo(x + width, y + height - r3);
  5774. r3 !== 0 && ctx.quadraticCurveTo(x + width, y + height, x + width - r3, y + height);
  5775. ctx.lineTo(x + r4, y + height);
  5776. r4 !== 0 && ctx.quadraticCurveTo(x, y + height, x, y + height - r4);
  5777. ctx.lineTo(x, y + r1);
  5778. r1 !== 0 && ctx.quadraticCurveTo(x, y, x + r1, y);
  5779. }
  5780. exports.buildPath = buildPath;
  5781. /***/ }),
  5782. /* 22 */
  5783. /***/ (function(module, exports) {
  5784. var PI2 = Math.PI * 2;
  5785. function normalizeRadian(angle) {
  5786. angle %= PI2;
  5787. if (angle < 0) {
  5788. angle += PI2;
  5789. }
  5790. return angle;
  5791. }
  5792. exports.normalizeRadian = normalizeRadian;
  5793. /***/ }),
  5794. /* 23 */
  5795. /***/ (function(module, exports, __webpack_require__) {
  5796. var smoothSpline = __webpack_require__(66);
  5797. var smoothBezier = __webpack_require__(67);
  5798. function buildPath(ctx, shape, closePath) {
  5799. var points = shape.points;
  5800. var smooth = shape.smooth;
  5801. if (points && points.length >= 2) {
  5802. if (smooth && smooth !== 'spline') {
  5803. var controlPoints = smoothBezier(points, smooth, closePath, shape.smoothConstraint);
  5804. ctx.moveTo(points[0][0], points[0][1]);
  5805. var len = points.length;
  5806. for (var i = 0; i < (closePath ? len : len - 1); i++) {
  5807. var cp1 = controlPoints[i * 2];
  5808. var cp2 = controlPoints[i * 2 + 1];
  5809. var p = points[(i + 1) % len];
  5810. ctx.bezierCurveTo(cp1[0], cp1[1], cp2[0], cp2[1], p[0], p[1]);
  5811. }
  5812. } else {
  5813. if (smooth === 'spline') {
  5814. points = smoothSpline(points, closePath);
  5815. }
  5816. ctx.moveTo(points[0][0], points[0][1]);
  5817. for (var i = 1, l = points.length; i < l; i++) {
  5818. ctx.lineTo(points[i][0], points[i][1]);
  5819. }
  5820. }
  5821. closePath && ctx.closePath();
  5822. }
  5823. }
  5824. exports.buildPath = buildPath;
  5825. /***/ }),
  5826. /* 24 */
  5827. /***/ (function(module, exports) {
  5828. /**
  5829. * @param {Array.<Object>} colorStops
  5830. */
  5831. var Gradient = function (colorStops) {
  5832. this.colorStops = colorStops || [];
  5833. };
  5834. Gradient.prototype = {
  5835. constructor: Gradient,
  5836. addColorStop: function (offset, color) {
  5837. this.colorStops.push({
  5838. offset: offset,
  5839. color: color
  5840. });
  5841. }
  5842. };
  5843. var _default = Gradient;
  5844. module.exports = _default;
  5845. /***/ }),
  5846. /* 25 */
  5847. /***/ (function(module, exports, __webpack_require__) {
  5848. module.exports = __webpack_require__(26);
  5849. /***/ }),
  5850. /* 26 */
  5851. /***/ (function(module, exports, __webpack_require__) {
  5852. var echarts = __webpack_require__(7);
  5853. var layoutUtil = __webpack_require__(27);
  5854. __webpack_require__(28);
  5855. __webpack_require__(77);
  5856. var wordCloudLayoutHelper = __webpack_require__(78);
  5857. if (!wordCloudLayoutHelper.isSupported) {
  5858. throw new Error('Sorry your browser not support wordCloud');
  5859. }
  5860. // https://github.com/timdream/wordcloud2.js/blob/c236bee60436e048949f9becc4f0f67bd832dc5c/index.js#L233
  5861. function updateCanvasMask(maskCanvas) {
  5862. var ctx = maskCanvas.getContext('2d');
  5863. var imageData = ctx.getImageData(
  5864. 0, 0, maskCanvas.width, maskCanvas.height);
  5865. var newImageData = ctx.createImageData(imageData);
  5866. var toneSum = 0;
  5867. var toneCnt = 0;
  5868. for (var i = 0; i < imageData.data.length; i += 4) {
  5869. var alpha = imageData.data[i + 3];
  5870. if (alpha > 128) {
  5871. var tone = imageData.data[i]
  5872. + imageData.data[i + 1]
  5873. + imageData.data[i + 2];
  5874. toneSum += tone;
  5875. ++toneCnt;
  5876. }
  5877. }
  5878. var threshold = toneSum / toneCnt;
  5879. for (var i = 0; i < imageData.data.length; i += 4) {
  5880. var tone = imageData.data[i]
  5881. + imageData.data[i + 1]
  5882. + imageData.data[i + 2];
  5883. var alpha = imageData.data[i + 3];
  5884. if (alpha < 128 || tone > threshold) {
  5885. // Area not to draw
  5886. newImageData.data[i] = 0;
  5887. newImageData.data[i + 1] = 0;
  5888. newImageData.data[i + 2] = 0;
  5889. newImageData.data[i + 3] = 0;
  5890. }
  5891. else {
  5892. // Area to draw
  5893. // The color must be same with backgroundColor
  5894. newImageData.data[i] = 255;
  5895. newImageData.data[i + 1] = 255;
  5896. newImageData.data[i + 2] = 255;
  5897. newImageData.data[i + 3] = 255;
  5898. }
  5899. }
  5900. ctx.putImageData(newImageData, 0, 0);
  5901. }
  5902. echarts.registerLayout(function (ecModel, api) {
  5903. ecModel.eachSeriesByType('wordCloud', function (seriesModel) {
  5904. var gridRect = layoutUtil.getLayoutRect(
  5905. seriesModel.getBoxLayoutParams(), {
  5906. width: api.getWidth(),
  5907. height: api.getHeight()
  5908. }
  5909. );
  5910. var data = seriesModel.getData();
  5911. var canvas = document.createElement('canvas');
  5912. canvas.width = gridRect.width;
  5913. canvas.height = gridRect.height;
  5914. var ctx = canvas.getContext('2d');
  5915. var maskImage = seriesModel.get('maskImage');
  5916. if (maskImage) {
  5917. try {
  5918. ctx.drawImage(maskImage, 0, 0, canvas.width, canvas.height);
  5919. updateCanvasMask(canvas);
  5920. }
  5921. catch (e) {
  5922. console.error('Invalid mask image');
  5923. console.error(e.toString());
  5924. }
  5925. }
  5926. var sizeRange = seriesModel.get('sizeRange');
  5927. var rotationRange = seriesModel.get('rotationRange');
  5928. var valueExtent = data.getDataExtent('value');
  5929. var DEGREE_TO_RAD = Math.PI / 180;
  5930. var gridSize = seriesModel.get('gridSize');
  5931. wordCloudLayoutHelper(canvas, {
  5932. list: data.mapArray('value', function (value, idx) {
  5933. var itemModel = data.getItemModel(idx);
  5934. return [
  5935. data.getName(idx),
  5936. itemModel.get('textStyle.normal.textSize', true)
  5937. || echarts.number.linearMap(value, valueExtent, sizeRange),
  5938. idx
  5939. ];
  5940. }).sort(function (a, b) {
  5941. // Sort from large to small in case there is no more room for more words
  5942. return b[1] - a[1];
  5943. }),
  5944. fontFamily: seriesModel.get('textStyle.normal.fontFamily')
  5945. || seriesModel.get('textStyle.emphasis.fontFamily')
  5946. || ecModel.get('textStyle.fontFamily'),
  5947. fontWeight: seriesModel.get('textStyle.normal.fontWeight')
  5948. || seriesModel.get('textStyle.emphasis.fontWeight')
  5949. || ecModel.get('textStyle.fontWeight'),
  5950. gridSize: gridSize,
  5951. ellipticity: gridRect.height / gridRect.width,
  5952. minRotation: rotationRange[0] * DEGREE_TO_RAD,
  5953. maxRotation: rotationRange[1] * DEGREE_TO_RAD,
  5954. clearCanvas: !maskImage,
  5955. rotateRatio: 1,
  5956. rotationStep: seriesModel.get('rotationStep') * DEGREE_TO_RAD,
  5957. drawOutOfBound: seriesModel.get('drawOutOfBound'),
  5958. shuffle: false,
  5959. shape: seriesModel.get('shape')
  5960. });
  5961. function onWordCloudDrawn(e) {
  5962. var item = e.detail.item;
  5963. if (e.detail.drawn && seriesModel.layoutInstance.ondraw) {
  5964. e.detail.drawn.gx += gridRect.x / gridSize;
  5965. e.detail.drawn.gy += gridRect.y / gridSize;
  5966. seriesModel.layoutInstance.ondraw(
  5967. item[0], item[1], item[2], e.detail.drawn
  5968. );
  5969. }
  5970. }
  5971. canvas.addEventListener('wordclouddrawn', onWordCloudDrawn);
  5972. if (seriesModel.layoutInstance) {
  5973. // Dispose previous
  5974. seriesModel.layoutInstance.dispose();
  5975. }
  5976. seriesModel.layoutInstance = {
  5977. ondraw: null,
  5978. dispose: function () {
  5979. canvas.removeEventListener('wordclouddrawn', onWordCloudDrawn);
  5980. // Abort
  5981. canvas.addEventListener('wordclouddrawn', function (e) {
  5982. // Prevent default to cancle the event and stop the loop
  5983. e.preventDefault();
  5984. });
  5985. }
  5986. };
  5987. });
  5988. });
  5989. echarts.registerPreprocessor(function (option) {
  5990. var series = (option || {}).series;
  5991. !echarts.util.isArray(series) && (series = series ? [series] : []);
  5992. var compats = ['shadowColor', 'shadowBlur', 'shadowOffsetX', 'shadowOffsetY'];
  5993. echarts.util.each(series, function (seriesItem) {
  5994. if (seriesItem && seriesItem.type === 'wordCloud') {
  5995. var textStyle = seriesItem.textStyle || {};
  5996. compatTextStyle(textStyle.normal);
  5997. compatTextStyle(textStyle.emphasis);
  5998. }
  5999. });
  6000. function compatTextStyle(textStyle) {
  6001. textStyle && echarts.util.each(compats, function (key) {
  6002. if (textStyle.hasOwnProperty(key)) {
  6003. textStyle['text' + echarts.format.capitalFirst(key)] = textStyle[key];
  6004. }
  6005. });
  6006. }
  6007. });
  6008. /***/ }),
  6009. /* 27 */
  6010. /***/ (function(module, exports, __webpack_require__) {
  6011. var zrUtil = __webpack_require__(0);
  6012. var BoundingRect = __webpack_require__(3);
  6013. var _number = __webpack_require__(9);
  6014. var parsePercent = _number.parsePercent;
  6015. var formatUtil = __webpack_require__(13);
  6016. // Layout helpers for each component positioning
  6017. var each = zrUtil.each;
  6018. /**
  6019. * @public
  6020. */
  6021. var LOCATION_PARAMS = ['left', 'right', 'top', 'bottom', 'width', 'height'];
  6022. /**
  6023. * @public
  6024. */
  6025. var HV_NAMES = [['width', 'left', 'right'], ['height', 'top', 'bottom']];
  6026. function boxLayout(orient, group, gap, maxWidth, maxHeight) {
  6027. var x = 0;
  6028. var y = 0;
  6029. if (maxWidth == null) {
  6030. maxWidth = Infinity;
  6031. }
  6032. if (maxHeight == null) {
  6033. maxHeight = Infinity;
  6034. }
  6035. var currentLineMaxSize = 0;
  6036. group.eachChild(function (child, idx) {
  6037. var position = child.position;
  6038. var rect = child.getBoundingRect();
  6039. var nextChild = group.childAt(idx + 1);
  6040. var nextChildRect = nextChild && nextChild.getBoundingRect();
  6041. var nextX;
  6042. var nextY;
  6043. if (orient === 'horizontal') {
  6044. var moveX = rect.width + (nextChildRect ? -nextChildRect.x + rect.x : 0);
  6045. nextX = x + moveX; // Wrap when width exceeds maxWidth or meet a `newline` group
  6046. // FIXME compare before adding gap?
  6047. if (nextX > maxWidth || child.newline) {
  6048. x = 0;
  6049. nextX = moveX;
  6050. y += currentLineMaxSize + gap;
  6051. currentLineMaxSize = rect.height;
  6052. } else {
  6053. // FIXME: consider rect.y is not `0`?
  6054. currentLineMaxSize = Math.max(currentLineMaxSize, rect.height);
  6055. }
  6056. } else {
  6057. var moveY = rect.height + (nextChildRect ? -nextChildRect.y + rect.y : 0);
  6058. nextY = y + moveY; // Wrap when width exceeds maxHeight or meet a `newline` group
  6059. if (nextY > maxHeight || child.newline) {
  6060. x += currentLineMaxSize + gap;
  6061. y = 0;
  6062. nextY = moveY;
  6063. currentLineMaxSize = rect.width;
  6064. } else {
  6065. currentLineMaxSize = Math.max(currentLineMaxSize, rect.width);
  6066. }
  6067. }
  6068. if (child.newline) {
  6069. return;
  6070. }
  6071. position[0] = x;
  6072. position[1] = y;
  6073. orient === 'horizontal' ? x = nextX + gap : y = nextY + gap;
  6074. });
  6075. }
  6076. /**
  6077. * VBox or HBox layouting
  6078. * @param {string} orient
  6079. * @param {module:zrender/container/Group} group
  6080. * @param {number} gap
  6081. * @param {number} [width=Infinity]
  6082. * @param {number} [height=Infinity]
  6083. */
  6084. var box = boxLayout;
  6085. /**
  6086. * VBox layouting
  6087. * @param {module:zrender/container/Group} group
  6088. * @param {number} gap
  6089. * @param {number} [width=Infinity]
  6090. * @param {number} [height=Infinity]
  6091. */
  6092. var vbox = zrUtil.curry(boxLayout, 'vertical');
  6093. /**
  6094. * HBox layouting
  6095. * @param {module:zrender/container/Group} group
  6096. * @param {number} gap
  6097. * @param {number} [width=Infinity]
  6098. * @param {number} [height=Infinity]
  6099. */
  6100. var hbox = zrUtil.curry(boxLayout, 'horizontal');
  6101. /**
  6102. * If x or x2 is not specified or 'center' 'left' 'right',
  6103. * the width would be as long as possible.
  6104. * If y or y2 is not specified or 'middle' 'top' 'bottom',
  6105. * the height would be as long as possible.
  6106. *
  6107. * @param {Object} positionInfo
  6108. * @param {number|string} [positionInfo.x]
  6109. * @param {number|string} [positionInfo.y]
  6110. * @param {number|string} [positionInfo.x2]
  6111. * @param {number|string} [positionInfo.y2]
  6112. * @param {Object} containerRect {width, height}
  6113. * @param {string|number} margin
  6114. * @return {Object} {width, height}
  6115. */
  6116. function getAvailableSize(positionInfo, containerRect, margin) {
  6117. var containerWidth = containerRect.width;
  6118. var containerHeight = containerRect.height;
  6119. var x = parsePercent(positionInfo.x, containerWidth);
  6120. var y = parsePercent(positionInfo.y, containerHeight);
  6121. var x2 = parsePercent(positionInfo.x2, containerWidth);
  6122. var y2 = parsePercent(positionInfo.y2, containerHeight);
  6123. (isNaN(x) || isNaN(parseFloat(positionInfo.x))) && (x = 0);
  6124. (isNaN(x2) || isNaN(parseFloat(positionInfo.x2))) && (x2 = containerWidth);
  6125. (isNaN(y) || isNaN(parseFloat(positionInfo.y))) && (y = 0);
  6126. (isNaN(y2) || isNaN(parseFloat(positionInfo.y2))) && (y2 = containerHeight);
  6127. margin = formatUtil.normalizeCssArray(margin || 0);
  6128. return {
  6129. width: Math.max(x2 - x - margin[1] - margin[3], 0),
  6130. height: Math.max(y2 - y - margin[0] - margin[2], 0)
  6131. };
  6132. }
  6133. /**
  6134. * Parse position info.
  6135. *
  6136. * @param {Object} positionInfo
  6137. * @param {number|string} [positionInfo.left]
  6138. * @param {number|string} [positionInfo.top]
  6139. * @param {number|string} [positionInfo.right]
  6140. * @param {number|string} [positionInfo.bottom]
  6141. * @param {number|string} [positionInfo.width]
  6142. * @param {number|string} [positionInfo.height]
  6143. * @param {number|string} [positionInfo.aspect] Aspect is width / height
  6144. * @param {Object} containerRect
  6145. * @param {string|number} [margin]
  6146. *
  6147. * @return {module:zrender/core/BoundingRect}
  6148. */
  6149. function getLayoutRect(positionInfo, containerRect, margin) {
  6150. margin = formatUtil.normalizeCssArray(margin || 0);
  6151. var containerWidth = containerRect.width;
  6152. var containerHeight = containerRect.height;
  6153. var left = parsePercent(positionInfo.left, containerWidth);
  6154. var top = parsePercent(positionInfo.top, containerHeight);
  6155. var right = parsePercent(positionInfo.right, containerWidth);
  6156. var bottom = parsePercent(positionInfo.bottom, containerHeight);
  6157. var width = parsePercent(positionInfo.width, containerWidth);
  6158. var height = parsePercent(positionInfo.height, containerHeight);
  6159. var verticalMargin = margin[2] + margin[0];
  6160. var horizontalMargin = margin[1] + margin[3];
  6161. var aspect = positionInfo.aspect; // If width is not specified, calculate width from left and right
  6162. if (isNaN(width)) {
  6163. width = containerWidth - right - horizontalMargin - left;
  6164. }
  6165. if (isNaN(height)) {
  6166. height = containerHeight - bottom - verticalMargin - top;
  6167. }
  6168. if (aspect != null) {
  6169. // If width and height are not given
  6170. // 1. Graph should not exceeds the container
  6171. // 2. Aspect must be keeped
  6172. // 3. Graph should take the space as more as possible
  6173. // FIXME
  6174. // Margin is not considered, because there is no case that both
  6175. // using margin and aspect so far.
  6176. if (isNaN(width) && isNaN(height)) {
  6177. if (aspect > containerWidth / containerHeight) {
  6178. width = containerWidth * 0.8;
  6179. } else {
  6180. height = containerHeight * 0.8;
  6181. }
  6182. } // Calculate width or height with given aspect
  6183. if (isNaN(width)) {
  6184. width = aspect * height;
  6185. }
  6186. if (isNaN(height)) {
  6187. height = width / aspect;
  6188. }
  6189. } // If left is not specified, calculate left from right and width
  6190. if (isNaN(left)) {
  6191. left = containerWidth - right - width - horizontalMargin;
  6192. }
  6193. if (isNaN(top)) {
  6194. top = containerHeight - bottom - height - verticalMargin;
  6195. } // Align left and top
  6196. switch (positionInfo.left || positionInfo.right) {
  6197. case 'center':
  6198. left = containerWidth / 2 - width / 2 - margin[3];
  6199. break;
  6200. case 'right':
  6201. left = containerWidth - width - horizontalMargin;
  6202. break;
  6203. }
  6204. switch (positionInfo.top || positionInfo.bottom) {
  6205. case 'middle':
  6206. case 'center':
  6207. top = containerHeight / 2 - height / 2 - margin[0];
  6208. break;
  6209. case 'bottom':
  6210. top = containerHeight - height - verticalMargin;
  6211. break;
  6212. } // If something is wrong and left, top, width, height are calculated as NaN
  6213. left = left || 0;
  6214. top = top || 0;
  6215. if (isNaN(width)) {
  6216. // Width may be NaN if only one value is given except width
  6217. width = containerWidth - horizontalMargin - left - (right || 0);
  6218. }
  6219. if (isNaN(height)) {
  6220. // Height may be NaN if only one value is given except height
  6221. height = containerHeight - verticalMargin - top - (bottom || 0);
  6222. }
  6223. var rect = new BoundingRect(left + margin[3], top + margin[0], width, height);
  6224. rect.margin = margin;
  6225. return rect;
  6226. }
  6227. /**
  6228. * Position a zr element in viewport
  6229. * Group position is specified by either
  6230. * {left, top}, {right, bottom}
  6231. * If all properties exists, right and bottom will be igonred.
  6232. *
  6233. * Logic:
  6234. * 1. Scale (against origin point in parent coord)
  6235. * 2. Rotate (against origin point in parent coord)
  6236. * 3. Traslate (with el.position by this method)
  6237. * So this method only fixes the last step 'Traslate', which does not affect
  6238. * scaling and rotating.
  6239. *
  6240. * If be called repeatly with the same input el, the same result will be gotten.
  6241. *
  6242. * @param {module:zrender/Element} el Should have `getBoundingRect` method.
  6243. * @param {Object} positionInfo
  6244. * @param {number|string} [positionInfo.left]
  6245. * @param {number|string} [positionInfo.top]
  6246. * @param {number|string} [positionInfo.right]
  6247. * @param {number|string} [positionInfo.bottom]
  6248. * @param {number|string} [positionInfo.width] Only for opt.boundingModel: 'raw'
  6249. * @param {number|string} [positionInfo.height] Only for opt.boundingModel: 'raw'
  6250. * @param {Object} containerRect
  6251. * @param {string|number} margin
  6252. * @param {Object} [opt]
  6253. * @param {Array.<number>} [opt.hv=[1,1]] Only horizontal or only vertical.
  6254. * @param {Array.<number>} [opt.boundingMode='all']
  6255. * Specify how to calculate boundingRect when locating.
  6256. * 'all': Position the boundingRect that is transformed and uioned
  6257. * both itself and its descendants.
  6258. * This mode simplies confine the elements in the bounding
  6259. * of their container (e.g., using 'right: 0').
  6260. * 'raw': Position the boundingRect that is not transformed and only itself.
  6261. * This mode is useful when you want a element can overflow its
  6262. * container. (Consider a rotated circle needs to be located in a corner.)
  6263. * In this mode positionInfo.width/height can only be number.
  6264. */
  6265. function positionElement(el, positionInfo, containerRect, margin, opt) {
  6266. var h = !opt || !opt.hv || opt.hv[0];
  6267. var v = !opt || !opt.hv || opt.hv[1];
  6268. var boundingMode = opt && opt.boundingMode || 'all';
  6269. if (!h && !v) {
  6270. return;
  6271. }
  6272. var rect;
  6273. if (boundingMode === 'raw') {
  6274. rect = el.type === 'group' ? new BoundingRect(0, 0, +positionInfo.width || 0, +positionInfo.height || 0) : el.getBoundingRect();
  6275. } else {
  6276. rect = el.getBoundingRect();
  6277. if (el.needLocalTransform()) {
  6278. var transform = el.getLocalTransform(); // Notice: raw rect may be inner object of el,
  6279. // which should not be modified.
  6280. rect = rect.clone();
  6281. rect.applyTransform(transform);
  6282. }
  6283. } // The real width and height can not be specified but calculated by the given el.
  6284. positionInfo = getLayoutRect(zrUtil.defaults({
  6285. width: rect.width,
  6286. height: rect.height
  6287. }, positionInfo), containerRect, margin); // Because 'tranlate' is the last step in transform
  6288. // (see zrender/core/Transformable#getLocalTransfrom),
  6289. // we can just only modify el.position to get final result.
  6290. var elPos = el.position;
  6291. var dx = h ? positionInfo.x - rect.x : 0;
  6292. var dy = v ? positionInfo.y - rect.y : 0;
  6293. el.attr('position', boundingMode === 'raw' ? [dx, dy] : [elPos[0] + dx, elPos[1] + dy]);
  6294. }
  6295. /**
  6296. * @param {Object} option Contains some of the properties in HV_NAMES.
  6297. * @param {number} hvIdx 0: horizontal; 1: vertical.
  6298. */
  6299. function sizeCalculable(option, hvIdx) {
  6300. return option[HV_NAMES[hvIdx][0]] != null || option[HV_NAMES[hvIdx][1]] != null && option[HV_NAMES[hvIdx][2]] != null;
  6301. }
  6302. /**
  6303. * Consider Case:
  6304. * When defulat option has {left: 0, width: 100}, and we set {right: 0}
  6305. * through setOption or media query, using normal zrUtil.merge will cause
  6306. * {right: 0} does not take effect.
  6307. *
  6308. * @example
  6309. * ComponentModel.extend({
  6310. * init: function () {
  6311. * ...
  6312. * var inputPositionParams = layout.getLayoutParams(option);
  6313. * this.mergeOption(inputPositionParams);
  6314. * },
  6315. * mergeOption: function (newOption) {
  6316. * newOption && zrUtil.merge(thisOption, newOption, true);
  6317. * layout.mergeLayoutParam(thisOption, newOption);
  6318. * }
  6319. * });
  6320. *
  6321. * @param {Object} targetOption
  6322. * @param {Object} newOption
  6323. * @param {Object|string} [opt]
  6324. * @param {boolean|Array.<boolean>} [opt.ignoreSize=false] Used for the components
  6325. * that width (or height) should not be calculated by left and right (or top and bottom).
  6326. */
  6327. function mergeLayoutParam(targetOption, newOption, opt) {
  6328. !zrUtil.isObject(opt) && (opt = {});
  6329. var ignoreSize = opt.ignoreSize;
  6330. !zrUtil.isArray(ignoreSize) && (ignoreSize = [ignoreSize, ignoreSize]);
  6331. var hResult = merge(HV_NAMES[0], 0);
  6332. var vResult = merge(HV_NAMES[1], 1);
  6333. copy(HV_NAMES[0], targetOption, hResult);
  6334. copy(HV_NAMES[1], targetOption, vResult);
  6335. function merge(names, hvIdx) {
  6336. var newParams = {};
  6337. var newValueCount = 0;
  6338. var merged = {};
  6339. var mergedValueCount = 0;
  6340. var enoughParamNumber = 2;
  6341. each(names, function (name) {
  6342. merged[name] = targetOption[name];
  6343. });
  6344. each(names, function (name) {
  6345. // Consider case: newOption.width is null, which is
  6346. // set by user for removing width setting.
  6347. hasProp(newOption, name) && (newParams[name] = merged[name] = newOption[name]);
  6348. hasValue(newParams, name) && newValueCount++;
  6349. hasValue(merged, name) && mergedValueCount++;
  6350. });
  6351. if (ignoreSize[hvIdx]) {
  6352. // Only one of left/right is premitted to exist.
  6353. if (hasValue(newOption, names[1])) {
  6354. merged[names[2]] = null;
  6355. } else if (hasValue(newOption, names[2])) {
  6356. merged[names[1]] = null;
  6357. }
  6358. return merged;
  6359. } // Case: newOption: {width: ..., right: ...},
  6360. // or targetOption: {right: ...} and newOption: {width: ...},
  6361. // There is no conflict when merged only has params count
  6362. // little than enoughParamNumber.
  6363. if (mergedValueCount === enoughParamNumber || !newValueCount) {
  6364. return merged;
  6365. } // Case: newOption: {width: ..., right: ...},
  6366. // Than we can make sure user only want those two, and ignore
  6367. // all origin params in targetOption.
  6368. else if (newValueCount >= enoughParamNumber) {
  6369. return newParams;
  6370. } else {
  6371. // Chose another param from targetOption by priority.
  6372. for (var i = 0; i < names.length; i++) {
  6373. var name = names[i];
  6374. if (!hasProp(newParams, name) && hasProp(targetOption, name)) {
  6375. newParams[name] = targetOption[name];
  6376. break;
  6377. }
  6378. }
  6379. return newParams;
  6380. }
  6381. }
  6382. function hasProp(obj, name) {
  6383. return obj.hasOwnProperty(name);
  6384. }
  6385. function hasValue(obj, name) {
  6386. return obj[name] != null && obj[name] !== 'auto';
  6387. }
  6388. function copy(names, target, source) {
  6389. each(names, function (name) {
  6390. target[name] = source[name];
  6391. });
  6392. }
  6393. }
  6394. /**
  6395. * Retrieve 'left', 'right', 'top', 'bottom', 'width', 'height' from object.
  6396. * @param {Object} source
  6397. * @return {Object} Result contains those props.
  6398. */
  6399. function getLayoutParams(source) {
  6400. return copyLayoutParams({}, source);
  6401. }
  6402. /**
  6403. * Retrieve 'left', 'right', 'top', 'bottom', 'width', 'height' from object.
  6404. * @param {Object} source
  6405. * @return {Object} Result contains those props.
  6406. */
  6407. function copyLayoutParams(target, source) {
  6408. source && target && each(LOCATION_PARAMS, function (name) {
  6409. source.hasOwnProperty(name) && (target[name] = source[name]);
  6410. });
  6411. return target;
  6412. }
  6413. exports.LOCATION_PARAMS = LOCATION_PARAMS;
  6414. exports.HV_NAMES = HV_NAMES;
  6415. exports.box = box;
  6416. exports.vbox = vbox;
  6417. exports.hbox = hbox;
  6418. exports.getAvailableSize = getAvailableSize;
  6419. exports.getLayoutRect = getLayoutRect;
  6420. exports.positionElement = positionElement;
  6421. exports.sizeCalculable = sizeCalculable;
  6422. exports.mergeLayoutParam = mergeLayoutParam;
  6423. exports.getLayoutParams = getLayoutParams;
  6424. exports.copyLayoutParams = copyLayoutParams;
  6425. /***/ }),
  6426. /* 28 */
  6427. /***/ (function(module, exports, __webpack_require__) {
  6428. var completeDimensions = __webpack_require__(29);
  6429. var echarts = __webpack_require__(7);
  6430. echarts.extendSeriesModel({
  6431. type: 'series.wordCloud',
  6432. visualColorAccessPath: 'textStyle.normal.color',
  6433. optionUpdated: function () {
  6434. var option = this.option;
  6435. option.gridSize = Math.max(Math.floor(option.gridSize), 4);
  6436. },
  6437. getInitialData: function (option, ecModel) {
  6438. var dimensions = completeDimensions(['value'], option.data);
  6439. var list = new echarts.List(dimensions, this);
  6440. list.initData(option.data);
  6441. return list;
  6442. },
  6443. // Most of options are from https://github.com/timdream/wordcloud2.js/blob/gh-pages/API.md
  6444. defaultOption: {
  6445. maskImage: null,
  6446. // Shape can be 'circle', 'cardioid', 'diamond', 'triangle-forward', 'triangle', 'pentagon', 'star'
  6447. shape: 'circle',
  6448. left: 'center',
  6449. top: 'center',
  6450. width: '70%',
  6451. height: '80%',
  6452. sizeRange: [12, 60],
  6453. rotationRange: [-90, 90],
  6454. rotationStep: 45,
  6455. gridSize: 8,
  6456. drawOutOfBound: false,
  6457. textStyle: {
  6458. normal: {
  6459. fontWeight: 'normal'
  6460. }
  6461. }
  6462. }
  6463. });
  6464. /***/ }),
  6465. /* 29 */
  6466. /***/ (function(module, exports, __webpack_require__) {
  6467. var zrUtil = __webpack_require__(0);
  6468. var _model = __webpack_require__(30);
  6469. var normalizeToArray = _model.normalizeToArray;
  6470. /**
  6471. * Complete dimensions by data (guess dimension).
  6472. */
  6473. var each = zrUtil.each;
  6474. var isString = zrUtil.isString;
  6475. var defaults = zrUtil.defaults;
  6476. var OTHER_DIMS = {
  6477. tooltip: 1,
  6478. label: 1,
  6479. itemName: 1
  6480. };
  6481. /**
  6482. * Complete the dimensions array, by user defined `dimension` and `encode`,
  6483. * and guessing from the data structure.
  6484. * If no 'value' dimension specified, the first no-named dimension will be
  6485. * named as 'value'.
  6486. *
  6487. * @param {Array.<string>} sysDims Necessary dimensions, like ['x', 'y'], which
  6488. * provides not only dim template, but also default order.
  6489. * `name` of each item provides default coord name.
  6490. * [{dimsDef: []}, ...] can be specified to give names.
  6491. * @param {Array} data Data list. [[1, 2, 3], [2, 3, 4]].
  6492. * @param {Object} [opt]
  6493. * @param {Array.<Object|string>} [opt.dimsDef] option.series.dimensions User defined dimensions
  6494. * For example: ['asdf', {name, type}, ...].
  6495. * @param {Object} [opt.encodeDef] option.series.encode {x: 2, y: [3, 1], tooltip: [1, 2], label: 3}
  6496. * @param {string} [opt.extraPrefix] Prefix of name when filling the left dimensions.
  6497. * @param {string} [opt.extraFromZero] If specified, extra dim names will be:
  6498. * extraPrefix + 0, extraPrefix + extraBaseIndex + 1 ...
  6499. * If not specified, extra dim names will be:
  6500. * extraPrefix, extraPrefix + 0, extraPrefix + 1 ...
  6501. * @param {number} [opt.dimCount] If not specified, guess by the first data item.
  6502. * @return {Array.<Object>} [{
  6503. * name: string mandatory,
  6504. * coordDim: string mandatory,
  6505. * coordDimIndex: number mandatory,
  6506. * type: string optional,
  6507. * tooltipName: string optional,
  6508. * otherDims: {
  6509. * tooltip: number optional,
  6510. * label: number optional
  6511. * },
  6512. * isExtraCoord: boolean true or undefined.
  6513. * other props ...
  6514. * }]
  6515. */
  6516. function completeDimensions(sysDims, data, opt) {
  6517. data = data || [];
  6518. opt = opt || {};
  6519. sysDims = (sysDims || []).slice();
  6520. var dimsDef = (opt.dimsDef || []).slice();
  6521. var encodeDef = zrUtil.createHashMap(opt.encodeDef);
  6522. var dataDimNameMap = zrUtil.createHashMap();
  6523. var coordDimNameMap = zrUtil.createHashMap(); // var valueCandidate;
  6524. var result = [];
  6525. var dimCount = opt.dimCount;
  6526. if (dimCount == null) {
  6527. var value0 = retrieveValue(data[0]);
  6528. dimCount = Math.max(zrUtil.isArray(value0) && value0.length || 1, sysDims.length, dimsDef.length);
  6529. each(sysDims, function (sysDimItem) {
  6530. var sysDimItemDimsDef = sysDimItem.dimsDef;
  6531. sysDimItemDimsDef && (dimCount = Math.max(dimCount, sysDimItemDimsDef.length));
  6532. });
  6533. } // Apply user defined dims (`name` and `type`) and init result.
  6534. for (var i = 0; i < dimCount; i++) {
  6535. var dimDefItem = isString(dimsDef[i]) ? {
  6536. name: dimsDef[i]
  6537. } : dimsDef[i] || {};
  6538. var userDimName = dimDefItem.name;
  6539. var resultItem = result[i] = {
  6540. otherDims: {}
  6541. }; // Name will be applied later for avoiding duplication.
  6542. if (userDimName != null && dataDimNameMap.get(userDimName) == null) {
  6543. // Only if `series.dimensions` is defined in option, tooltipName
  6544. // will be set, and dimension will be diplayed vertically in
  6545. // tooltip by default.
  6546. resultItem.name = resultItem.tooltipName = userDimName;
  6547. dataDimNameMap.set(userDimName, i);
  6548. }
  6549. dimDefItem.type != null && (resultItem.type = dimDefItem.type);
  6550. } // Set `coordDim` and `coordDimIndex` by `encodeDef` and normalize `encodeDef`.
  6551. encodeDef.each(function (dataDims, coordDim) {
  6552. dataDims = encodeDef.set(coordDim, normalizeToArray(dataDims).slice());
  6553. each(dataDims, function (resultDimIdx, coordDimIndex) {
  6554. // The input resultDimIdx can be dim name or index.
  6555. isString(resultDimIdx) && (resultDimIdx = dataDimNameMap.get(resultDimIdx));
  6556. if (resultDimIdx != null && resultDimIdx < dimCount) {
  6557. dataDims[coordDimIndex] = resultDimIdx;
  6558. applyDim(result[resultDimIdx], coordDim, coordDimIndex);
  6559. }
  6560. });
  6561. }); // Apply templetes and default order from `sysDims`.
  6562. var availDimIdx = 0;
  6563. each(sysDims, function (sysDimItem, sysDimIndex) {
  6564. var coordDim;
  6565. var sysDimItem;
  6566. var sysDimItemDimsDef;
  6567. var sysDimItemOtherDims;
  6568. if (isString(sysDimItem)) {
  6569. coordDim = sysDimItem;
  6570. sysDimItem = {};
  6571. } else {
  6572. coordDim = sysDimItem.name;
  6573. sysDimItem = zrUtil.clone(sysDimItem); // `coordDimIndex` should not be set directly.
  6574. sysDimItemDimsDef = sysDimItem.dimsDef;
  6575. sysDimItemOtherDims = sysDimItem.otherDims;
  6576. sysDimItem.name = sysDimItem.coordDim = sysDimItem.coordDimIndex = sysDimItem.dimsDef = sysDimItem.otherDims = null;
  6577. }
  6578. var dataDims = normalizeToArray(encodeDef.get(coordDim)); // dimensions provides default dim sequences.
  6579. if (!dataDims.length) {
  6580. for (var i = 0; i < (sysDimItemDimsDef && sysDimItemDimsDef.length || 1); i++) {
  6581. while (availDimIdx < result.length && result[availDimIdx].coordDim != null) {
  6582. availDimIdx++;
  6583. }
  6584. availDimIdx < result.length && dataDims.push(availDimIdx++);
  6585. }
  6586. } // Apply templates.
  6587. each(dataDims, function (resultDimIdx, coordDimIndex) {
  6588. var resultItem = result[resultDimIdx];
  6589. applyDim(defaults(resultItem, sysDimItem), coordDim, coordDimIndex);
  6590. if (resultItem.name == null && sysDimItemDimsDef) {
  6591. resultItem.name = resultItem.tooltipName = sysDimItemDimsDef[coordDimIndex];
  6592. }
  6593. sysDimItemOtherDims && defaults(resultItem.otherDims, sysDimItemOtherDims);
  6594. });
  6595. }); // Make sure the first extra dim is 'value'.
  6596. var extra = opt.extraPrefix || 'value'; // Set dim `name` and other `coordDim` and other props.
  6597. for (var resultDimIdx = 0; resultDimIdx < dimCount; resultDimIdx++) {
  6598. var resultItem = result[resultDimIdx] = result[resultDimIdx] || {};
  6599. var coordDim = resultItem.coordDim;
  6600. coordDim == null && (resultItem.coordDim = genName(extra, coordDimNameMap, opt.extraFromZero), resultItem.coordDimIndex = 0, resultItem.isExtraCoord = true);
  6601. resultItem.name == null && (resultItem.name = genName(resultItem.coordDim, dataDimNameMap));
  6602. resultItem.type == null && guessOrdinal(data, resultDimIdx) && (resultItem.type = 'ordinal');
  6603. }
  6604. return result;
  6605. function applyDim(resultItem, coordDim, coordDimIndex) {
  6606. if (OTHER_DIMS[coordDim]) {
  6607. resultItem.otherDims[coordDim] = coordDimIndex;
  6608. } else {
  6609. resultItem.coordDim = coordDim;
  6610. resultItem.coordDimIndex = coordDimIndex;
  6611. coordDimNameMap.set(coordDim, true);
  6612. }
  6613. }
  6614. function genName(name, map, fromZero) {
  6615. if (fromZero || map.get(name) != null) {
  6616. var i = 0;
  6617. while (map.get(name + i) != null) {
  6618. i++;
  6619. }
  6620. name += i;
  6621. }
  6622. map.set(name, true);
  6623. return name;
  6624. }
  6625. } // The rule should not be complex, otherwise user might not
  6626. // be able to known where the data is wrong.
  6627. var guessOrdinal = completeDimensions.guessOrdinal = function (data, dimIndex) {
  6628. for (var i = 0, len = data.length; i < len; i++) {
  6629. var value = retrieveValue(data[i]);
  6630. if (!zrUtil.isArray(value)) {
  6631. return false;
  6632. }
  6633. var value = value[dimIndex]; // Consider usage convenience, '1', '2' will be treated as "number".
  6634. // `isFinit('')` get `true`.
  6635. if (value != null && isFinite(value) && value !== '') {
  6636. return false;
  6637. } else if (isString(value) && value !== '-') {
  6638. return true;
  6639. }
  6640. }
  6641. return false;
  6642. };
  6643. function retrieveValue(o) {
  6644. return zrUtil.isArray(o) ? o : zrUtil.isObject(o) ? o.value : o;
  6645. }
  6646. var _default = completeDimensions;
  6647. module.exports = _default;
  6648. /***/ }),
  6649. /* 30 */
  6650. /***/ (function(module, exports, __webpack_require__) {
  6651. var zrUtil = __webpack_require__(0);
  6652. var formatUtil = __webpack_require__(13);
  6653. var nubmerUtil = __webpack_require__(9);
  6654. var Model = __webpack_require__(31);
  6655. var each = zrUtil.each;
  6656. var isObject = zrUtil.isObject;
  6657. /**
  6658. * If value is not array, then translate it to array.
  6659. * @param {*} value
  6660. * @return {Array} [value] or value
  6661. */
  6662. function normalizeToArray(value) {
  6663. return value instanceof Array ? value : value == null ? [] : [value];
  6664. }
  6665. /**
  6666. * Sync default option between normal and emphasis like `position` and `show`
  6667. * In case some one will write code like
  6668. * label: {
  6669. * normal: {
  6670. * show: false,
  6671. * position: 'outside',
  6672. * fontSize: 18
  6673. * },
  6674. * emphasis: {
  6675. * show: true
  6676. * }
  6677. * }
  6678. * @param {Object} opt
  6679. * @param {Array.<string>} subOpts
  6680. */
  6681. function defaultEmphasis(opt, subOpts) {
  6682. if (opt) {
  6683. var emphasisOpt = opt.emphasis = opt.emphasis || {};
  6684. var normalOpt = opt.normal = opt.normal || {}; // Default emphasis option from normal
  6685. for (var i = 0, len = subOpts.length; i < len; i++) {
  6686. var subOptName = subOpts[i];
  6687. if (!emphasisOpt.hasOwnProperty(subOptName) && normalOpt.hasOwnProperty(subOptName)) {
  6688. emphasisOpt[subOptName] = normalOpt[subOptName];
  6689. }
  6690. }
  6691. }
  6692. }
  6693. var TEXT_STYLE_OPTIONS = ['fontStyle', 'fontWeight', 'fontSize', 'fontFamily', 'rich', 'tag', 'color', 'textBorderColor', 'textBorderWidth', 'width', 'height', 'lineHeight', 'align', 'verticalAlign', 'baseline', 'shadowColor', 'shadowBlur', 'shadowOffsetX', 'shadowOffsetY', 'textShadowColor', 'textShadowBlur', 'textShadowOffsetX', 'textShadowOffsetY', 'backgroundColor', 'borderColor', 'borderWidth', 'borderRadius', 'padding']; // modelUtil.LABEL_OPTIONS = modelUtil.TEXT_STYLE_OPTIONS.concat([
  6694. // 'position', 'offset', 'rotate', 'origin', 'show', 'distance', 'formatter',
  6695. // 'fontStyle', 'fontWeight', 'fontSize', 'fontFamily',
  6696. // // FIXME: deprecated, check and remove it.
  6697. // 'textStyle'
  6698. // ]);
  6699. /**
  6700. * data could be [12, 2323, {value: 223}, [1221, 23], {value: [2, 23]}]
  6701. * This helper method retieves value from data.
  6702. * @param {string|number|Date|Array|Object} dataItem
  6703. * @return {number|string|Date|Array.<number|string|Date>}
  6704. */
  6705. function getDataItemValue(dataItem) {
  6706. // Performance sensitive.
  6707. return dataItem && (dataItem.value == null ? dataItem : dataItem.value);
  6708. }
  6709. /**
  6710. * data could be [12, 2323, {value: 223}, [1221, 23], {value: [2, 23]}]
  6711. * This helper method determine if dataItem has extra option besides value
  6712. * @param {string|number|Date|Array|Object} dataItem
  6713. */
  6714. function isDataItemOption(dataItem) {
  6715. return isObject(dataItem) && !(dataItem instanceof Array); // // markLine data can be array
  6716. // && !(dataItem[0] && isObject(dataItem[0]) && !(dataItem[0] instanceof Array));
  6717. }
  6718. /**
  6719. * This helper method convert value in data.
  6720. * @param {string|number|Date} value
  6721. * @param {Object|string} [dimInfo] If string (like 'x'), dimType defaults 'number'.
  6722. */
  6723. function converDataValue(value, dimInfo) {
  6724. // Performance sensitive.
  6725. var dimType = dimInfo && dimInfo.type;
  6726. if (dimType === 'ordinal') {
  6727. return value;
  6728. }
  6729. if (dimType === 'time' // spead up when using timestamp
  6730. && typeof value !== 'number' && value != null && value !== '-') {
  6731. value = +nubmerUtil.parseDate(value);
  6732. } // dimType defaults 'number'.
  6733. // If dimType is not ordinal and value is null or undefined or NaN or '-',
  6734. // parse to NaN.
  6735. return value == null || value === '' ? NaN : +value; // If string (like '-'), using '+' parse to NaN
  6736. }
  6737. /**
  6738. * Create a model proxy to be used in tooltip for edge data, markLine data, markPoint data.
  6739. * @param {module:echarts/data/List} data
  6740. * @param {Object} opt
  6741. * @param {string} [opt.seriesIndex]
  6742. * @param {Object} [opt.name]
  6743. * @param {Object} [opt.mainType]
  6744. * @param {Object} [opt.subType]
  6745. */
  6746. function createDataFormatModel(data, opt) {
  6747. var model = new Model();
  6748. zrUtil.mixin(model, dataFormatMixin);
  6749. model.seriesIndex = opt.seriesIndex;
  6750. model.name = opt.name || '';
  6751. model.mainType = opt.mainType;
  6752. model.subType = opt.subType;
  6753. model.getData = function () {
  6754. return data;
  6755. };
  6756. return model;
  6757. } // PENDING A little ugly
  6758. var dataFormatMixin = {
  6759. /**
  6760. * Get params for formatter
  6761. * @param {number} dataIndex
  6762. * @param {string} [dataType]
  6763. * @return {Object}
  6764. */
  6765. getDataParams: function (dataIndex, dataType) {
  6766. var data = this.getData(dataType);
  6767. var rawValue = this.getRawValue(dataIndex, dataType);
  6768. var rawDataIndex = data.getRawIndex(dataIndex);
  6769. var name = data.getName(dataIndex, true);
  6770. var itemOpt = data.getRawDataItem(dataIndex);
  6771. var color = data.getItemVisual(dataIndex, 'color');
  6772. return {
  6773. componentType: this.mainType,
  6774. componentSubType: this.subType,
  6775. seriesType: this.mainType === 'series' ? this.subType : null,
  6776. seriesIndex: this.seriesIndex,
  6777. seriesId: this.id,
  6778. seriesName: this.name,
  6779. name: name,
  6780. dataIndex: rawDataIndex,
  6781. data: itemOpt,
  6782. dataType: dataType,
  6783. value: rawValue,
  6784. color: color,
  6785. marker: formatUtil.getTooltipMarker(color),
  6786. // Param name list for mapping `a`, `b`, `c`, `d`, `e`
  6787. $vars: ['seriesName', 'name', 'value']
  6788. };
  6789. },
  6790. /**
  6791. * Format label
  6792. * @param {number} dataIndex
  6793. * @param {string} [status='normal'] 'normal' or 'emphasis'
  6794. * @param {string} [dataType]
  6795. * @param {number} [dimIndex]
  6796. * @param {string} [labelProp='label']
  6797. * @return {string}
  6798. */
  6799. getFormattedLabel: function (dataIndex, status, dataType, dimIndex, labelProp) {
  6800. status = status || 'normal';
  6801. var data = this.getData(dataType);
  6802. var itemModel = data.getItemModel(dataIndex);
  6803. var params = this.getDataParams(dataIndex, dataType);
  6804. if (dimIndex != null && params.value instanceof Array) {
  6805. params.value = params.value[dimIndex];
  6806. }
  6807. var formatter = itemModel.get([labelProp || 'label', status, 'formatter']);
  6808. if (typeof formatter === 'function') {
  6809. params.status = status;
  6810. return formatter(params);
  6811. } else if (typeof formatter === 'string') {
  6812. return formatUtil.formatTpl(formatter, params);
  6813. }
  6814. },
  6815. /**
  6816. * Get raw value in option
  6817. * @param {number} idx
  6818. * @param {string} [dataType]
  6819. * @return {Object}
  6820. */
  6821. getRawValue: function (idx, dataType) {
  6822. var data = this.getData(dataType);
  6823. var dataItem = data.getRawDataItem(idx);
  6824. if (dataItem != null) {
  6825. return isObject(dataItem) && !(dataItem instanceof Array) ? dataItem.value : dataItem;
  6826. }
  6827. },
  6828. /**
  6829. * Should be implemented.
  6830. * @param {number} dataIndex
  6831. * @param {boolean} [multipleSeries=false]
  6832. * @param {number} [dataType]
  6833. * @return {string} tooltip string
  6834. */
  6835. formatTooltip: zrUtil.noop
  6836. };
  6837. /**
  6838. * Mapping to exists for merge.
  6839. *
  6840. * @public
  6841. * @param {Array.<Object>|Array.<module:echarts/model/Component>} exists
  6842. * @param {Object|Array.<Object>} newCptOptions
  6843. * @return {Array.<Object>} Result, like [{exist: ..., option: ...}, {}],
  6844. * index of which is the same as exists.
  6845. */
  6846. function mappingToExists(exists, newCptOptions) {
  6847. // Mapping by the order by original option (but not order of
  6848. // new option) in merge mode. Because we should ensure
  6849. // some specified index (like xAxisIndex) is consistent with
  6850. // original option, which is easy to understand, espatially in
  6851. // media query. And in most case, merge option is used to
  6852. // update partial option but not be expected to change order.
  6853. newCptOptions = (newCptOptions || []).slice();
  6854. var result = zrUtil.map(exists || [], function (obj, index) {
  6855. return {
  6856. exist: obj
  6857. };
  6858. }); // Mapping by id or name if specified.
  6859. each(newCptOptions, function (cptOption, index) {
  6860. if (!isObject(cptOption)) {
  6861. return;
  6862. } // id has highest priority.
  6863. for (var i = 0; i < result.length; i++) {
  6864. if (!result[i].option // Consider name: two map to one.
  6865. && cptOption.id != null && result[i].exist.id === cptOption.id + '') {
  6866. result[i].option = cptOption;
  6867. newCptOptions[index] = null;
  6868. return;
  6869. }
  6870. }
  6871. for (var i = 0; i < result.length; i++) {
  6872. var exist = result[i].exist;
  6873. if (!result[i].option // Consider name: two map to one.
  6874. // Can not match when both ids exist but different.
  6875. && (exist.id == null || cptOption.id == null) && cptOption.name != null && !isIdInner(cptOption) && !isIdInner(exist) && exist.name === cptOption.name + '') {
  6876. result[i].option = cptOption;
  6877. newCptOptions[index] = null;
  6878. return;
  6879. }
  6880. }
  6881. }); // Otherwise mapping by index.
  6882. each(newCptOptions, function (cptOption, index) {
  6883. if (!isObject(cptOption)) {
  6884. return;
  6885. }
  6886. var i = 0;
  6887. for (; i < result.length; i++) {
  6888. var exist = result[i].exist;
  6889. if (!result[i].option // Existing model that already has id should be able to
  6890. // mapped to (because after mapping performed model may
  6891. // be assigned with a id, whish should not affect next
  6892. // mapping), except those has inner id.
  6893. && !isIdInner(exist) // Caution:
  6894. // Do not overwrite id. But name can be overwritten,
  6895. // because axis use name as 'show label text'.
  6896. // 'exist' always has id and name and we dont
  6897. // need to check it.
  6898. && cptOption.id == null) {
  6899. result[i].option = cptOption;
  6900. break;
  6901. }
  6902. }
  6903. if (i >= result.length) {
  6904. result.push({
  6905. option: cptOption
  6906. });
  6907. }
  6908. });
  6909. return result;
  6910. }
  6911. /**
  6912. * Make id and name for mapping result (result of mappingToExists)
  6913. * into `keyInfo` field.
  6914. *
  6915. * @public
  6916. * @param {Array.<Object>} Result, like [{exist: ..., option: ...}, {}],
  6917. * which order is the same as exists.
  6918. * @return {Array.<Object>} The input.
  6919. */
  6920. function makeIdAndName(mapResult) {
  6921. // We use this id to hash component models and view instances
  6922. // in echarts. id can be specified by user, or auto generated.
  6923. // The id generation rule ensures new view instance are able
  6924. // to mapped to old instance when setOption are called in
  6925. // no-merge mode. So we generate model id by name and plus
  6926. // type in view id.
  6927. // name can be duplicated among components, which is convenient
  6928. // to specify multi components (like series) by one name.
  6929. // Ensure that each id is distinct.
  6930. var idMap = zrUtil.createHashMap();
  6931. each(mapResult, function (item, index) {
  6932. var existCpt = item.exist;
  6933. existCpt && idMap.set(existCpt.id, item);
  6934. });
  6935. each(mapResult, function (item, index) {
  6936. var opt = item.option;
  6937. zrUtil.assert(!opt || opt.id == null || !idMap.get(opt.id) || idMap.get(opt.id) === item, 'id duplicates: ' + (opt && opt.id));
  6938. opt && opt.id != null && idMap.set(opt.id, item);
  6939. !item.keyInfo && (item.keyInfo = {});
  6940. }); // Make name and id.
  6941. each(mapResult, function (item, index) {
  6942. var existCpt = item.exist;
  6943. var opt = item.option;
  6944. var keyInfo = item.keyInfo;
  6945. if (!isObject(opt)) {
  6946. return;
  6947. } // name can be overwitten. Consider case: axis.name = '20km'.
  6948. // But id generated by name will not be changed, which affect
  6949. // only in that case: setOption with 'not merge mode' and view
  6950. // instance will be recreated, which can be accepted.
  6951. keyInfo.name = opt.name != null ? opt.name + '' : existCpt ? existCpt.name : '\0-'; // name may be displayed on screen, so use '-'.
  6952. if (existCpt) {
  6953. keyInfo.id = existCpt.id;
  6954. } else if (opt.id != null) {
  6955. keyInfo.id = opt.id + '';
  6956. } else {
  6957. // Consider this situatoin:
  6958. // optionA: [{name: 'a'}, {name: 'a'}, {..}]
  6959. // optionB [{..}, {name: 'a'}, {name: 'a'}]
  6960. // Series with the same name between optionA and optionB
  6961. // should be mapped.
  6962. var idNum = 0;
  6963. do {
  6964. keyInfo.id = '\0' + keyInfo.name + '\0' + idNum++;
  6965. } while (idMap.get(keyInfo.id));
  6966. }
  6967. idMap.set(keyInfo.id, item);
  6968. });
  6969. }
  6970. /**
  6971. * @public
  6972. * @param {Object} cptOption
  6973. * @return {boolean}
  6974. */
  6975. function isIdInner(cptOption) {
  6976. return isObject(cptOption) && cptOption.id && (cptOption.id + '').indexOf('\0_ec_\0') === 0;
  6977. }
  6978. /**
  6979. * A helper for removing duplicate items between batchA and batchB,
  6980. * and in themselves, and categorize by series.
  6981. *
  6982. * @param {Array.<Object>} batchA Like: [{seriesId: 2, dataIndex: [32, 4, 5]}, ...]
  6983. * @param {Array.<Object>} batchB Like: [{seriesId: 2, dataIndex: [32, 4, 5]}, ...]
  6984. * @return {Array.<Array.<Object>, Array.<Object>>} result: [resultBatchA, resultBatchB]
  6985. */
  6986. function compressBatches(batchA, batchB) {
  6987. var mapA = {};
  6988. var mapB = {};
  6989. makeMap(batchA || [], mapA);
  6990. makeMap(batchB || [], mapB, mapA);
  6991. return [mapToArray(mapA), mapToArray(mapB)];
  6992. function makeMap(sourceBatch, map, otherMap) {
  6993. for (var i = 0, len = sourceBatch.length; i < len; i++) {
  6994. var seriesId = sourceBatch[i].seriesId;
  6995. var dataIndices = normalizeToArray(sourceBatch[i].dataIndex);
  6996. var otherDataIndices = otherMap && otherMap[seriesId];
  6997. for (var j = 0, lenj = dataIndices.length; j < lenj; j++) {
  6998. var dataIndex = dataIndices[j];
  6999. if (otherDataIndices && otherDataIndices[dataIndex]) {
  7000. otherDataIndices[dataIndex] = null;
  7001. } else {
  7002. (map[seriesId] || (map[seriesId] = {}))[dataIndex] = 1;
  7003. }
  7004. }
  7005. }
  7006. }
  7007. function mapToArray(map, isData) {
  7008. var result = [];
  7009. for (var i in map) {
  7010. if (map.hasOwnProperty(i) && map[i] != null) {
  7011. if (isData) {
  7012. result.push(+i);
  7013. } else {
  7014. var dataIndices = mapToArray(map[i], true);
  7015. dataIndices.length && result.push({
  7016. seriesId: i,
  7017. dataIndex: dataIndices
  7018. });
  7019. }
  7020. }
  7021. }
  7022. return result;
  7023. }
  7024. }
  7025. /**
  7026. * @param {module:echarts/data/List} data
  7027. * @param {Object} payload Contains dataIndex (means rawIndex) / dataIndexInside / name
  7028. * each of which can be Array or primary type.
  7029. * @return {number|Array.<number>} dataIndex If not found, return undefined/null.
  7030. */
  7031. function queryDataIndex(data, payload) {
  7032. if (payload.dataIndexInside != null) {
  7033. return payload.dataIndexInside;
  7034. } else if (payload.dataIndex != null) {
  7035. return zrUtil.isArray(payload.dataIndex) ? zrUtil.map(payload.dataIndex, function (value) {
  7036. return data.indexOfRawIndex(value);
  7037. }) : data.indexOfRawIndex(payload.dataIndex);
  7038. } else if (payload.name != null) {
  7039. return zrUtil.isArray(payload.name) ? zrUtil.map(payload.name, function (value) {
  7040. return data.indexOfName(value);
  7041. }) : data.indexOfName(payload.name);
  7042. }
  7043. }
  7044. /**
  7045. * Enable property storage to any host object.
  7046. * Notice: Serialization is not supported.
  7047. *
  7048. * For example:
  7049. * var get = modelUitl.makeGetter();
  7050. *
  7051. * function some(hostObj) {
  7052. * get(hostObj)._someProperty = 1212;
  7053. * ...
  7054. * }
  7055. *
  7056. * @return {Function}
  7057. */
  7058. var makeGetter = function () {
  7059. var index = 0;
  7060. return function () {
  7061. var key = '\0__ec_prop_getter_' + index++;
  7062. return function (hostObj) {
  7063. return hostObj[key] || (hostObj[key] = {});
  7064. };
  7065. };
  7066. }();
  7067. /**
  7068. * @param {module:echarts/model/Global} ecModel
  7069. * @param {string|Object} finder
  7070. * If string, e.g., 'geo', means {geoIndex: 0}.
  7071. * If Object, could contain some of these properties below:
  7072. * {
  7073. * seriesIndex, seriesId, seriesName,
  7074. * geoIndex, geoId, geoName,
  7075. * bmapIndex, bmapId, bmapName,
  7076. * xAxisIndex, xAxisId, xAxisName,
  7077. * yAxisIndex, yAxisId, yAxisName,
  7078. * gridIndex, gridId, gridName,
  7079. * ... (can be extended)
  7080. * }
  7081. * Each properties can be number|string|Array.<number>|Array.<string>
  7082. * For example, a finder could be
  7083. * {
  7084. * seriesIndex: 3,
  7085. * geoId: ['aa', 'cc'],
  7086. * gridName: ['xx', 'rr']
  7087. * }
  7088. * xxxIndex can be set as 'all' (means all xxx) or 'none' (means not specify)
  7089. * If nothing or null/undefined specified, return nothing.
  7090. * @param {Object} [opt]
  7091. * @param {string} [opt.defaultMainType]
  7092. * @param {Array.<string>} [opt.includeMainTypes]
  7093. * @return {Object} result like:
  7094. * {
  7095. * seriesModels: [seriesModel1, seriesModel2],
  7096. * seriesModel: seriesModel1, // The first model
  7097. * geoModels: [geoModel1, geoModel2],
  7098. * geoModel: geoModel1, // The first model
  7099. * ...
  7100. * }
  7101. */
  7102. function parseFinder(ecModel, finder, opt) {
  7103. if (zrUtil.isString(finder)) {
  7104. var obj = {};
  7105. obj[finder + 'Index'] = 0;
  7106. finder = obj;
  7107. }
  7108. var defaultMainType = opt && opt.defaultMainType;
  7109. if (defaultMainType && !has(finder, defaultMainType + 'Index') && !has(finder, defaultMainType + 'Id') && !has(finder, defaultMainType + 'Name')) {
  7110. finder[defaultMainType + 'Index'] = 0;
  7111. }
  7112. var result = {};
  7113. each(finder, function (value, key) {
  7114. var value = finder[key]; // Exclude 'dataIndex' and other illgal keys.
  7115. if (key === 'dataIndex' || key === 'dataIndexInside') {
  7116. result[key] = value;
  7117. return;
  7118. }
  7119. var parsedKey = key.match(/^(\w+)(Index|Id|Name)$/) || [];
  7120. var mainType = parsedKey[1];
  7121. var queryType = (parsedKey[2] || '').toLowerCase();
  7122. if (!mainType || !queryType || value == null || queryType === 'index' && value === 'none' || opt && opt.includeMainTypes && zrUtil.indexOf(opt.includeMainTypes, mainType) < 0) {
  7123. return;
  7124. }
  7125. var queryParam = {
  7126. mainType: mainType
  7127. };
  7128. if (queryType !== 'index' || value !== 'all') {
  7129. queryParam[queryType] = value;
  7130. }
  7131. var models = ecModel.queryComponents(queryParam);
  7132. result[mainType + 'Models'] = models;
  7133. result[mainType + 'Model'] = models[0];
  7134. });
  7135. return result;
  7136. }
  7137. /**
  7138. * @see {module:echarts/data/helper/completeDimensions}
  7139. * @param {module:echarts/data/List} data
  7140. * @param {string|number} dataDim
  7141. * @return {string}
  7142. */
  7143. function dataDimToCoordDim(data, dataDim) {
  7144. var dimensions = data.dimensions;
  7145. dataDim = data.getDimension(dataDim);
  7146. for (var i = 0; i < dimensions.length; i++) {
  7147. var dimItem = data.getDimensionInfo(dimensions[i]);
  7148. if (dimItem.name === dataDim) {
  7149. return dimItem.coordDim;
  7150. }
  7151. }
  7152. }
  7153. /**
  7154. * @see {module:echarts/data/helper/completeDimensions}
  7155. * @param {module:echarts/data/List} data
  7156. * @param {string} coordDim
  7157. * @return {Array.<string>} data dimensions on the coordDim.
  7158. */
  7159. function coordDimToDataDim(data, coordDim) {
  7160. var dataDim = [];
  7161. each(data.dimensions, function (dimName) {
  7162. var dimItem = data.getDimensionInfo(dimName);
  7163. if (dimItem.coordDim === coordDim) {
  7164. dataDim[dimItem.coordDimIndex] = dimItem.name;
  7165. }
  7166. });
  7167. return dataDim;
  7168. }
  7169. /**
  7170. * @see {module:echarts/data/helper/completeDimensions}
  7171. * @param {module:echarts/data/List} data
  7172. * @param {string} otherDim Can be `otherDims`
  7173. * like 'label' or 'tooltip'.
  7174. * @return {Array.<string>} data dimensions on the otherDim.
  7175. */
  7176. function otherDimToDataDim(data, otherDim) {
  7177. var dataDim = [];
  7178. each(data.dimensions, function (dimName) {
  7179. var dimItem = data.getDimensionInfo(dimName);
  7180. var otherDims = dimItem.otherDims;
  7181. var dimIndex = otherDims[otherDim];
  7182. if (dimIndex != null && dimIndex !== false) {
  7183. dataDim[dimIndex] = dimItem.name;
  7184. }
  7185. });
  7186. return dataDim;
  7187. }
  7188. function has(obj, prop) {
  7189. return obj && obj.hasOwnProperty(prop);
  7190. }
  7191. exports.normalizeToArray = normalizeToArray;
  7192. exports.defaultEmphasis = defaultEmphasis;
  7193. exports.TEXT_STYLE_OPTIONS = TEXT_STYLE_OPTIONS;
  7194. exports.getDataItemValue = getDataItemValue;
  7195. exports.isDataItemOption = isDataItemOption;
  7196. exports.converDataValue = converDataValue;
  7197. exports.createDataFormatModel = createDataFormatModel;
  7198. exports.dataFormatMixin = dataFormatMixin;
  7199. exports.mappingToExists = mappingToExists;
  7200. exports.makeIdAndName = makeIdAndName;
  7201. exports.isIdInner = isIdInner;
  7202. exports.compressBatches = compressBatches;
  7203. exports.queryDataIndex = queryDataIndex;
  7204. exports.makeGetter = makeGetter;
  7205. exports.parseFinder = parseFinder;
  7206. exports.dataDimToCoordDim = dataDimToCoordDim;
  7207. exports.coordDimToDataDim = coordDimToDataDim;
  7208. exports.otherDimToDataDim = otherDimToDataDim;
  7209. /***/ }),
  7210. /* 31 */
  7211. /***/ (function(module, exports, __webpack_require__) {
  7212. var zrUtil = __webpack_require__(0);
  7213. var env = __webpack_require__(15);
  7214. var clazzUtil = __webpack_require__(32);
  7215. var lineStyleMixin = __webpack_require__(35);
  7216. var areaStyleMixin = __webpack_require__(36);
  7217. var textStyleMixin = __webpack_require__(37);
  7218. var itemStyleMixin = __webpack_require__(76);
  7219. /**
  7220. * @module echarts/model/Model
  7221. */
  7222. var mixin = zrUtil.mixin;
  7223. /**
  7224. * @alias module:echarts/model/Model
  7225. * @constructor
  7226. * @param {Object} option
  7227. * @param {module:echarts/model/Model} [parentModel]
  7228. * @param {module:echarts/model/Global} [ecModel]
  7229. */
  7230. function Model(option, parentModel, ecModel) {
  7231. /**
  7232. * @type {module:echarts/model/Model}
  7233. * @readOnly
  7234. */
  7235. this.parentModel = parentModel;
  7236. /**
  7237. * @type {module:echarts/model/Global}
  7238. * @readOnly
  7239. */
  7240. this.ecModel = ecModel;
  7241. /**
  7242. * @type {Object}
  7243. * @protected
  7244. */
  7245. this.option = option; // Simple optimization
  7246. // if (this.init) {
  7247. // if (arguments.length <= 4) {
  7248. // this.init(option, parentModel, ecModel, extraOpt);
  7249. // }
  7250. // else {
  7251. // this.init.apply(this, arguments);
  7252. // }
  7253. // }
  7254. }
  7255. Model.prototype = {
  7256. constructor: Model,
  7257. /**
  7258. * Model 的初始化函数
  7259. * @param {Object} option
  7260. */
  7261. init: null,
  7262. /**
  7263. * 从新的 Option merge
  7264. */
  7265. mergeOption: function (option) {
  7266. zrUtil.merge(this.option, option, true);
  7267. },
  7268. /**
  7269. * @param {string|Array.<string>} path
  7270. * @param {boolean} [ignoreParent=false]
  7271. * @return {*}
  7272. */
  7273. get: function (path, ignoreParent) {
  7274. if (path == null) {
  7275. return this.option;
  7276. }
  7277. return doGet(this.option, this.parsePath(path), !ignoreParent && getParent(this, path));
  7278. },
  7279. /**
  7280. * @param {string} key
  7281. * @param {boolean} [ignoreParent=false]
  7282. * @return {*}
  7283. */
  7284. getShallow: function (key, ignoreParent) {
  7285. var option = this.option;
  7286. var val = option == null ? option : option[key];
  7287. var parentModel = !ignoreParent && getParent(this, key);
  7288. if (val == null && parentModel) {
  7289. val = parentModel.getShallow(key);
  7290. }
  7291. return val;
  7292. },
  7293. /**
  7294. * @param {string|Array.<string>} [path]
  7295. * @param {module:echarts/model/Model} [parentModel]
  7296. * @return {module:echarts/model/Model}
  7297. */
  7298. getModel: function (path, parentModel) {
  7299. var obj = path == null ? this.option : doGet(this.option, path = this.parsePath(path));
  7300. var thisParentModel;
  7301. parentModel = parentModel || (thisParentModel = getParent(this, path)) && thisParentModel.getModel(path);
  7302. return new Model(obj, parentModel, this.ecModel);
  7303. },
  7304. /**
  7305. * If model has option
  7306. */
  7307. isEmpty: function () {
  7308. return this.option == null;
  7309. },
  7310. restoreData: function () {},
  7311. // Pending
  7312. clone: function () {
  7313. var Ctor = this.constructor;
  7314. return new Ctor(zrUtil.clone(this.option));
  7315. },
  7316. setReadOnly: function (properties) {
  7317. clazzUtil.setReadOnly(this, properties);
  7318. },
  7319. // If path is null/undefined, return null/undefined.
  7320. parsePath: function (path) {
  7321. if (typeof path === 'string') {
  7322. path = path.split('.');
  7323. }
  7324. return path;
  7325. },
  7326. /**
  7327. * @param {Function} getParentMethod
  7328. * param {Array.<string>|string} path
  7329. * return {module:echarts/model/Model}
  7330. */
  7331. customizeGetParent: function (getParentMethod) {
  7332. clazzUtil.set(this, 'getParent', getParentMethod);
  7333. },
  7334. isAnimationEnabled: function () {
  7335. if (!env.node) {
  7336. if (this.option.animation != null) {
  7337. return !!this.option.animation;
  7338. } else if (this.parentModel) {
  7339. return this.parentModel.isAnimationEnabled();
  7340. }
  7341. }
  7342. }
  7343. };
  7344. function doGet(obj, pathArr, parentModel) {
  7345. for (var i = 0; i < pathArr.length; i++) {
  7346. // Ignore empty
  7347. if (!pathArr[i]) {
  7348. continue;
  7349. } // obj could be number/string/... (like 0)
  7350. obj = obj && typeof obj === 'object' ? obj[pathArr[i]] : null;
  7351. if (obj == null) {
  7352. break;
  7353. }
  7354. }
  7355. if (obj == null && parentModel) {
  7356. obj = parentModel.get(pathArr);
  7357. }
  7358. return obj;
  7359. } // `path` can be null/undefined
  7360. function getParent(model, path) {
  7361. var getParentMethod = clazzUtil.get(model, 'getParent');
  7362. return getParentMethod ? getParentMethod.call(model, path) : model.parentModel;
  7363. } // Enable Model.extend.
  7364. clazzUtil.enableClassExtend(Model);
  7365. mixin(Model, lineStyleMixin);
  7366. mixin(Model, areaStyleMixin);
  7367. mixin(Model, textStyleMixin);
  7368. mixin(Model, itemStyleMixin);
  7369. var _default = Model;
  7370. module.exports = _default;
  7371. /***/ }),
  7372. /* 32 */
  7373. /***/ (function(module, exports, __webpack_require__) {
  7374. var _config = __webpack_require__(33);
  7375. var __DEV__ = _config.__DEV__;
  7376. var zrUtil = __webpack_require__(0);
  7377. var TYPE_DELIMITER = '.';
  7378. var IS_CONTAINER = '___EC__COMPONENT__CONTAINER___';
  7379. var MEMBER_PRIFIX = '\0ec_\0';
  7380. /**
  7381. * Hide private class member.
  7382. * The same behavior as `host[name] = value;` (can be right-value)
  7383. * @public
  7384. */
  7385. function set(host, name, value) {
  7386. return host[MEMBER_PRIFIX + name] = value;
  7387. }
  7388. /**
  7389. * Hide private class member.
  7390. * The same behavior as `host[name];`
  7391. * @public
  7392. */
  7393. function get(host, name) {
  7394. return host[MEMBER_PRIFIX + name];
  7395. }
  7396. /**
  7397. * For hidden private class member.
  7398. * The same behavior as `host.hasOwnProperty(name);`
  7399. * @public
  7400. */
  7401. function hasOwn(host, name) {
  7402. return host.hasOwnProperty(MEMBER_PRIFIX + name);
  7403. }
  7404. /**
  7405. * Notice, parseClassType('') should returns {main: '', sub: ''}
  7406. * @public
  7407. */
  7408. function parseClassType(componentType) {
  7409. var ret = {
  7410. main: '',
  7411. sub: ''
  7412. };
  7413. if (componentType) {
  7414. componentType = componentType.split(TYPE_DELIMITER);
  7415. ret.main = componentType[0] || '';
  7416. ret.sub = componentType[1] || '';
  7417. }
  7418. return ret;
  7419. }
  7420. /**
  7421. * @public
  7422. */
  7423. function checkClassType(componentType) {
  7424. zrUtil.assert(/^[a-zA-Z0-9_]+([.][a-zA-Z0-9_]+)?$/.test(componentType), 'componentType "' + componentType + '" illegal');
  7425. }
  7426. /**
  7427. * @public
  7428. */
  7429. function enableClassExtend(RootClass, mandatoryMethods) {
  7430. RootClass.$constructor = RootClass;
  7431. RootClass.extend = function (proto) {
  7432. var superClass = this;
  7433. var ExtendedClass = function () {
  7434. if (!proto.$constructor) {
  7435. superClass.apply(this, arguments);
  7436. } else {
  7437. proto.$constructor.apply(this, arguments);
  7438. }
  7439. };
  7440. zrUtil.extend(ExtendedClass.prototype, proto);
  7441. ExtendedClass.extend = this.extend;
  7442. ExtendedClass.superCall = superCall;
  7443. ExtendedClass.superApply = superApply;
  7444. zrUtil.inherits(ExtendedClass, this);
  7445. ExtendedClass.superClass = superClass;
  7446. return ExtendedClass;
  7447. };
  7448. } // superCall should have class info, which can not be fetch from 'this'.
  7449. // Consider this case:
  7450. // class A has method f,
  7451. // class B inherits class A, overrides method f, f call superApply('f'),
  7452. // class C inherits class B, do not overrides method f,
  7453. // then when method of class C is called, dead loop occured.
  7454. function superCall(context, methodName) {
  7455. var args = zrUtil.slice(arguments, 2);
  7456. return this.superClass.prototype[methodName].apply(context, args);
  7457. }
  7458. function superApply(context, methodName, args) {
  7459. return this.superClass.prototype[methodName].apply(context, args);
  7460. }
  7461. /**
  7462. * @param {Object} entity
  7463. * @param {Object} options
  7464. * @param {boolean} [options.registerWhenExtend]
  7465. * @public
  7466. */
  7467. function enableClassManagement(entity, options) {
  7468. options = options || {};
  7469. /**
  7470. * Component model classes
  7471. * key: componentType,
  7472. * value:
  7473. * componentClass, when componentType is 'xxx'
  7474. * or Object.<subKey, componentClass>, when componentType is 'xxx.yy'
  7475. * @type {Object}
  7476. */
  7477. var storage = {};
  7478. entity.registerClass = function (Clazz, componentType) {
  7479. if (componentType) {
  7480. checkClassType(componentType);
  7481. componentType = parseClassType(componentType);
  7482. if (!componentType.sub) {
  7483. storage[componentType.main] = Clazz;
  7484. } else if (componentType.sub !== IS_CONTAINER) {
  7485. var container = makeContainer(componentType);
  7486. container[componentType.sub] = Clazz;
  7487. }
  7488. }
  7489. return Clazz;
  7490. };
  7491. entity.getClass = function (componentMainType, subType, throwWhenNotFound) {
  7492. var Clazz = storage[componentMainType];
  7493. if (Clazz && Clazz[IS_CONTAINER]) {
  7494. Clazz = subType ? Clazz[subType] : null;
  7495. }
  7496. if (throwWhenNotFound && !Clazz) {
  7497. throw new Error(!subType ? componentMainType + '.' + 'type should be specified.' : 'Component ' + componentMainType + '.' + (subType || '') + ' not exists. Load it first.');
  7498. }
  7499. return Clazz;
  7500. };
  7501. entity.getClassesByMainType = function (componentType) {
  7502. componentType = parseClassType(componentType);
  7503. var result = [];
  7504. var obj = storage[componentType.main];
  7505. if (obj && obj[IS_CONTAINER]) {
  7506. zrUtil.each(obj, function (o, type) {
  7507. type !== IS_CONTAINER && result.push(o);
  7508. });
  7509. } else {
  7510. result.push(obj);
  7511. }
  7512. return result;
  7513. };
  7514. entity.hasClass = function (componentType) {
  7515. // Just consider componentType.main.
  7516. componentType = parseClassType(componentType);
  7517. return !!storage[componentType.main];
  7518. };
  7519. /**
  7520. * @return {Array.<string>} Like ['aa', 'bb'], but can not be ['aa.xx']
  7521. */
  7522. entity.getAllClassMainTypes = function () {
  7523. var types = [];
  7524. zrUtil.each(storage, function (obj, type) {
  7525. types.push(type);
  7526. });
  7527. return types;
  7528. };
  7529. /**
  7530. * If a main type is container and has sub types
  7531. * @param {string} mainType
  7532. * @return {boolean}
  7533. */
  7534. entity.hasSubTypes = function (componentType) {
  7535. componentType = parseClassType(componentType);
  7536. var obj = storage[componentType.main];
  7537. return obj && obj[IS_CONTAINER];
  7538. };
  7539. entity.parseClassType = parseClassType;
  7540. function makeContainer(componentType) {
  7541. var container = storage[componentType.main];
  7542. if (!container || !container[IS_CONTAINER]) {
  7543. container = storage[componentType.main] = {};
  7544. container[IS_CONTAINER] = true;
  7545. }
  7546. return container;
  7547. }
  7548. if (options.registerWhenExtend) {
  7549. var originalExtend = entity.extend;
  7550. if (originalExtend) {
  7551. entity.extend = function (proto) {
  7552. var ExtendedClass = originalExtend.call(this, proto);
  7553. return entity.registerClass(ExtendedClass, proto.type);
  7554. };
  7555. }
  7556. }
  7557. return entity;
  7558. }
  7559. /**
  7560. * @param {string|Array.<string>} properties
  7561. */
  7562. function setReadOnly(obj, properties) {// FIXME It seems broken in IE8 simulation of IE11
  7563. // if (!zrUtil.isArray(properties)) {
  7564. // properties = properties != null ? [properties] : [];
  7565. // }
  7566. // zrUtil.each(properties, function (prop) {
  7567. // var value = obj[prop];
  7568. // Object.defineProperty
  7569. // && Object.defineProperty(obj, prop, {
  7570. // value: value, writable: false
  7571. // });
  7572. // zrUtil.isArray(obj[prop])
  7573. // && Object.freeze
  7574. // && Object.freeze(obj[prop]);
  7575. // });
  7576. }
  7577. exports.set = set;
  7578. exports.get = get;
  7579. exports.hasOwn = hasOwn;
  7580. exports.parseClassType = parseClassType;
  7581. exports.enableClassExtend = enableClassExtend;
  7582. exports.enableClassManagement = enableClassManagement;
  7583. exports.setReadOnly = setReadOnly;
  7584. /***/ }),
  7585. /* 33 */
  7586. /***/ (function(module, exports, __webpack_require__) {
  7587. /* WEBPACK VAR INJECTION */(function(global) {// (1) The code `if (__DEV__) ...` can be removed by build tool.
  7588. // (2) If intend to use `__DEV__`, this module should be imported. Use a global
  7589. // variable `__DEV__` may cause that miss the declaration (see #6535), or the
  7590. // declaration is behind of the using position (for example in `Model.extent`,
  7591. // And tools like rollup can not analysis the dependency if not import).
  7592. var dev; // In browser
  7593. if (typeof window !== 'undefined') {
  7594. dev = window.__DEV__;
  7595. } // In node
  7596. else if (typeof global !== 'undefined') {
  7597. dev = global.__DEV__;
  7598. }
  7599. if (typeof dev === 'undefined') {
  7600. dev = true;
  7601. }
  7602. var __DEV__ = dev;
  7603. exports.__DEV__ = __DEV__;
  7604. /* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(34)))
  7605. /***/ }),
  7606. /* 34 */
  7607. /***/ (function(module, exports) {
  7608. var g;
  7609. // This works in non-strict mode
  7610. g = (function() {
  7611. return this;
  7612. })();
  7613. try {
  7614. // This works if eval is allowed (see CSP)
  7615. g = g || Function("return this")() || (1,eval)("this");
  7616. } catch(e) {
  7617. // This works if the window reference is available
  7618. if(typeof window === "object")
  7619. g = window;
  7620. }
  7621. // g can still be undefined, but nothing to do about it...
  7622. // We return undefined, instead of nothing here, so it's
  7623. // easier to handle this case. if(!global) { ...}
  7624. module.exports = g;
  7625. /***/ }),
  7626. /* 35 */
  7627. /***/ (function(module, exports, __webpack_require__) {
  7628. var makeStyleMapper = __webpack_require__(11);
  7629. var getLineStyle = makeStyleMapper([['lineWidth', 'width'], ['stroke', 'color'], ['opacity'], ['shadowBlur'], ['shadowOffsetX'], ['shadowOffsetY'], ['shadowColor']]);
  7630. var _default = {
  7631. getLineStyle: function (excludes) {
  7632. var style = getLineStyle(this, excludes);
  7633. var lineDash = this.getLineDash(style.lineWidth);
  7634. lineDash && (style.lineDash = lineDash);
  7635. return style;
  7636. },
  7637. getLineDash: function (lineWidth) {
  7638. if (lineWidth == null) {
  7639. lineWidth = 1;
  7640. }
  7641. var lineType = this.get('type');
  7642. var dotSize = Math.max(lineWidth, 2);
  7643. var dashSize = lineWidth * 4;
  7644. return lineType === 'solid' || lineType == null ? null : lineType === 'dashed' ? [dashSize, dashSize] : [dotSize, dotSize];
  7645. }
  7646. };
  7647. module.exports = _default;
  7648. /***/ }),
  7649. /* 36 */
  7650. /***/ (function(module, exports, __webpack_require__) {
  7651. var makeStyleMapper = __webpack_require__(11);
  7652. var getAreaStyle = makeStyleMapper([['fill', 'color'], ['shadowBlur'], ['shadowOffsetX'], ['shadowOffsetY'], ['opacity'], ['shadowColor']]);
  7653. var _default = {
  7654. getAreaStyle: function (excludes, includes) {
  7655. return getAreaStyle(this, excludes, includes);
  7656. }
  7657. };
  7658. module.exports = _default;
  7659. /***/ }),
  7660. /* 37 */
  7661. /***/ (function(module, exports, __webpack_require__) {
  7662. var textContain = __webpack_require__(5);
  7663. var graphicUtil = __webpack_require__(38);
  7664. var PATH_COLOR = ['textStyle', 'color'];
  7665. var _default = {
  7666. /**
  7667. * Get color property or get color from option.textStyle.color
  7668. * @param {boolean} [isEmphasis]
  7669. * @return {string}
  7670. */
  7671. getTextColor: function (isEmphasis) {
  7672. var ecModel = this.ecModel;
  7673. return this.getShallow('color') || (!isEmphasis && ecModel ? ecModel.get(PATH_COLOR) : null);
  7674. },
  7675. /**
  7676. * Create font string from fontStyle, fontWeight, fontSize, fontFamily
  7677. * @return {string}
  7678. */
  7679. getFont: function () {
  7680. return graphicUtil.getFont({
  7681. fontStyle: this.getShallow('fontStyle'),
  7682. fontWeight: this.getShallow('fontWeight'),
  7683. fontSize: this.getShallow('fontSize'),
  7684. fontFamily: this.getShallow('fontFamily')
  7685. }, this.ecModel);
  7686. },
  7687. getTextRect: function (text) {
  7688. return textContain.getBoundingRect(text, this.getFont(), this.getShallow('align'), this.getShallow('verticalAlign') || this.getShallow('baseline'), this.getShallow('padding'), this.getShallow('rich'), this.getShallow('truncateText'));
  7689. }
  7690. };
  7691. module.exports = _default;
  7692. /***/ }),
  7693. /* 38 */
  7694. /***/ (function(module, exports, __webpack_require__) {
  7695. var zrUtil = __webpack_require__(0);
  7696. var pathTool = __webpack_require__(39);
  7697. var colorTool = __webpack_require__(18);
  7698. var matrix = __webpack_require__(8);
  7699. var vector = __webpack_require__(2);
  7700. var Path = __webpack_require__(1);
  7701. var Transformable = __webpack_require__(17);
  7702. var Image = __webpack_require__(58);
  7703. exports.Image = Image;
  7704. var Group = __webpack_require__(59);
  7705. exports.Group = Group;
  7706. var Text = __webpack_require__(60);
  7707. exports.Text = Text;
  7708. var Circle = __webpack_require__(61);
  7709. exports.Circle = Circle;
  7710. var Sector = __webpack_require__(62);
  7711. exports.Sector = Sector;
  7712. var Ring = __webpack_require__(64);
  7713. exports.Ring = Ring;
  7714. var Polygon = __webpack_require__(65);
  7715. exports.Polygon = Polygon;
  7716. var Polyline = __webpack_require__(68);
  7717. exports.Polyline = Polyline;
  7718. var Rect = __webpack_require__(69);
  7719. exports.Rect = Rect;
  7720. var Line = __webpack_require__(70);
  7721. exports.Line = Line;
  7722. var BezierCurve = __webpack_require__(71);
  7723. exports.BezierCurve = BezierCurve;
  7724. var Arc = __webpack_require__(72);
  7725. exports.Arc = Arc;
  7726. var CompoundPath = __webpack_require__(73);
  7727. exports.CompoundPath = CompoundPath;
  7728. var LinearGradient = __webpack_require__(74);
  7729. exports.LinearGradient = LinearGradient;
  7730. var RadialGradient = __webpack_require__(75);
  7731. exports.RadialGradient = RadialGradient;
  7732. var BoundingRect = __webpack_require__(3);
  7733. exports.BoundingRect = BoundingRect;
  7734. var round = Math.round;
  7735. var mathMax = Math.max;
  7736. var mathMin = Math.min;
  7737. var EMPTY_OBJ = {};
  7738. /**
  7739. * Extend shape with parameters
  7740. */
  7741. function extendShape(opts) {
  7742. return Path.extend(opts);
  7743. }
  7744. /**
  7745. * Extend path
  7746. */
  7747. function extendPath(pathData, opts) {
  7748. return pathTool.extendFromString(pathData, opts);
  7749. }
  7750. /**
  7751. * Create a path element from path data string
  7752. * @param {string} pathData
  7753. * @param {Object} opts
  7754. * @param {module:zrender/core/BoundingRect} rect
  7755. * @param {string} [layout=cover] 'center' or 'cover'
  7756. */
  7757. function makePath(pathData, opts, rect, layout) {
  7758. var path = pathTool.createFromString(pathData, opts);
  7759. var boundingRect = path.getBoundingRect();
  7760. if (rect) {
  7761. if (layout === 'center') {
  7762. rect = centerGraphic(rect, boundingRect);
  7763. }
  7764. resizePath(path, rect);
  7765. }
  7766. return path;
  7767. }
  7768. /**
  7769. * Create a image element from image url
  7770. * @param {string} imageUrl image url
  7771. * @param {Object} opts options
  7772. * @param {module:zrender/core/BoundingRect} rect constrain rect
  7773. * @param {string} [layout=cover] 'center' or 'cover'
  7774. */
  7775. function makeImage(imageUrl, rect, layout) {
  7776. var path = new Image({
  7777. style: {
  7778. image: imageUrl,
  7779. x: rect.x,
  7780. y: rect.y,
  7781. width: rect.width,
  7782. height: rect.height
  7783. },
  7784. onload: function (img) {
  7785. if (layout === 'center') {
  7786. var boundingRect = {
  7787. width: img.width,
  7788. height: img.height
  7789. };
  7790. path.setStyle(centerGraphic(rect, boundingRect));
  7791. }
  7792. }
  7793. });
  7794. return path;
  7795. }
  7796. /**
  7797. * Get position of centered element in bounding box.
  7798. *
  7799. * @param {Object} rect element local bounding box
  7800. * @param {Object} boundingRect constraint bounding box
  7801. * @return {Object} element position containing x, y, width, and height
  7802. */
  7803. function centerGraphic(rect, boundingRect) {
  7804. // Set rect to center, keep width / height ratio.
  7805. var aspect = boundingRect.width / boundingRect.height;
  7806. var width = rect.height * aspect;
  7807. var height;
  7808. if (width <= rect.width) {
  7809. height = rect.height;
  7810. } else {
  7811. width = rect.width;
  7812. height = width / aspect;
  7813. }
  7814. var cx = rect.x + rect.width / 2;
  7815. var cy = rect.y + rect.height / 2;
  7816. return {
  7817. x: cx - width / 2,
  7818. y: cy - height / 2,
  7819. width: width,
  7820. height: height
  7821. };
  7822. }
  7823. var mergePath = pathTool.mergePath;
  7824. /**
  7825. * Resize a path to fit the rect
  7826. * @param {module:zrender/graphic/Path} path
  7827. * @param {Object} rect
  7828. */
  7829. function resizePath(path, rect) {
  7830. if (!path.applyTransform) {
  7831. return;
  7832. }
  7833. var pathRect = path.getBoundingRect();
  7834. var m = pathRect.calculateTransform(rect);
  7835. path.applyTransform(m);
  7836. }
  7837. /**
  7838. * Sub pixel optimize line for canvas
  7839. *
  7840. * @param {Object} param
  7841. * @param {Object} [param.shape]
  7842. * @param {number} [param.shape.x1]
  7843. * @param {number} [param.shape.y1]
  7844. * @param {number} [param.shape.x2]
  7845. * @param {number} [param.shape.y2]
  7846. * @param {Object} [param.style]
  7847. * @param {number} [param.style.lineWidth]
  7848. * @return {Object} Modified param
  7849. */
  7850. function subPixelOptimizeLine(param) {
  7851. var shape = param.shape;
  7852. var lineWidth = param.style.lineWidth;
  7853. if (round(shape.x1 * 2) === round(shape.x2 * 2)) {
  7854. shape.x1 = shape.x2 = subPixelOptimize(shape.x1, lineWidth, true);
  7855. }
  7856. if (round(shape.y1 * 2) === round(shape.y2 * 2)) {
  7857. shape.y1 = shape.y2 = subPixelOptimize(shape.y1, lineWidth, true);
  7858. }
  7859. return param;
  7860. }
  7861. /**
  7862. * Sub pixel optimize rect for canvas
  7863. *
  7864. * @param {Object} param
  7865. * @param {Object} [param.shape]
  7866. * @param {number} [param.shape.x]
  7867. * @param {number} [param.shape.y]
  7868. * @param {number} [param.shape.width]
  7869. * @param {number} [param.shape.height]
  7870. * @param {Object} [param.style]
  7871. * @param {number} [param.style.lineWidth]
  7872. * @return {Object} Modified param
  7873. */
  7874. function subPixelOptimizeRect(param) {
  7875. var shape = param.shape;
  7876. var lineWidth = param.style.lineWidth;
  7877. var originX = shape.x;
  7878. var originY = shape.y;
  7879. var originWidth = shape.width;
  7880. var originHeight = shape.height;
  7881. shape.x = subPixelOptimize(shape.x, lineWidth, true);
  7882. shape.y = subPixelOptimize(shape.y, lineWidth, true);
  7883. shape.width = Math.max(subPixelOptimize(originX + originWidth, lineWidth, false) - shape.x, originWidth === 0 ? 0 : 1);
  7884. shape.height = Math.max(subPixelOptimize(originY + originHeight, lineWidth, false) - shape.y, originHeight === 0 ? 0 : 1);
  7885. return param;
  7886. }
  7887. /**
  7888. * Sub pixel optimize for canvas
  7889. *
  7890. * @param {number} position Coordinate, such as x, y
  7891. * @param {number} lineWidth Should be nonnegative integer.
  7892. * @param {boolean=} positiveOrNegative Default false (negative).
  7893. * @return {number} Optimized position.
  7894. */
  7895. function subPixelOptimize(position, lineWidth, positiveOrNegative) {
  7896. // Assure that (position + lineWidth / 2) is near integer edge,
  7897. // otherwise line will be fuzzy in canvas.
  7898. var doubledPosition = round(position * 2);
  7899. return (doubledPosition + round(lineWidth)) % 2 === 0 ? doubledPosition / 2 : (doubledPosition + (positiveOrNegative ? 1 : -1)) / 2;
  7900. }
  7901. function hasFillOrStroke(fillOrStroke) {
  7902. return fillOrStroke != null && fillOrStroke != 'none';
  7903. }
  7904. function liftColor(color) {
  7905. return typeof color === 'string' ? colorTool.lift(color, -0.1) : color;
  7906. }
  7907. /**
  7908. * @private
  7909. */
  7910. function cacheElementStl(el) {
  7911. if (el.__hoverStlDirty) {
  7912. var stroke = el.style.stroke;
  7913. var fill = el.style.fill; // Create hoverStyle on mouseover
  7914. var hoverStyle = el.__hoverStl;
  7915. hoverStyle.fill = hoverStyle.fill || (hasFillOrStroke(fill) ? liftColor(fill) : null);
  7916. hoverStyle.stroke = hoverStyle.stroke || (hasFillOrStroke(stroke) ? liftColor(stroke) : null);
  7917. var normalStyle = {};
  7918. for (var name in hoverStyle) {
  7919. // See comment in `doSingleEnterHover`.
  7920. if (hoverStyle[name] != null) {
  7921. normalStyle[name] = el.style[name];
  7922. }
  7923. }
  7924. el.__normalStl = normalStyle;
  7925. el.__hoverStlDirty = false;
  7926. }
  7927. }
  7928. /**
  7929. * @private
  7930. */
  7931. function doSingleEnterHover(el) {
  7932. if (el.__isHover) {
  7933. return;
  7934. }
  7935. cacheElementStl(el);
  7936. if (el.useHoverLayer) {
  7937. el.__zr && el.__zr.addHover(el, el.__hoverStl);
  7938. } else {
  7939. var style = el.style;
  7940. var insideRollbackOpt = style.insideRollbackOpt; // Consider case: only `position: 'top'` is set on emphasis, then text
  7941. // color should be returned to `autoColor`, rather than remain '#fff'.
  7942. // So we should rollback then apply again after style merging.
  7943. insideRollbackOpt && rollbackInsideStyle(style); // styles can be:
  7944. // {
  7945. // label: {
  7946. // normal: {
  7947. // show: false,
  7948. // position: 'outside',
  7949. // fontSize: 18
  7950. // },
  7951. // emphasis: {
  7952. // show: true
  7953. // }
  7954. // }
  7955. // },
  7956. // where properties of `emphasis` may not appear in `normal`. We previously use
  7957. // module:echarts/util/model#defaultEmphasis to merge `normal` to `emphasis`.
  7958. // But consider rich text and setOption in merge mode, it is impossible to cover
  7959. // all properties in merge. So we use merge mode when setting style here, where
  7960. // only properties that is not `null/undefined` can be set. The disadventage:
  7961. // null/undefined can not be used to remove style any more in `emphasis`.
  7962. style.extendFrom(el.__hoverStl); // Do not save `insideRollback`.
  7963. if (insideRollbackOpt) {
  7964. applyInsideStyle(style, style.insideOriginalTextPosition, insideRollbackOpt); // textFill may be rollbacked to null.
  7965. if (style.textFill == null) {
  7966. style.textFill = insideRollbackOpt.autoColor;
  7967. }
  7968. }
  7969. el.dirty(false);
  7970. el.z2 += 1;
  7971. }
  7972. el.__isHover = true;
  7973. }
  7974. /**
  7975. * @inner
  7976. */
  7977. function doSingleLeaveHover(el) {
  7978. if (!el.__isHover) {
  7979. return;
  7980. }
  7981. var normalStl = el.__normalStl;
  7982. if (el.useHoverLayer) {
  7983. el.__zr && el.__zr.removeHover(el);
  7984. } else {
  7985. // Consider null/undefined value, should use
  7986. // `setStyle` but not `extendFrom(stl, true)`.
  7987. normalStl && el.setStyle(normalStl);
  7988. el.z2 -= 1;
  7989. }
  7990. el.__isHover = false;
  7991. }
  7992. /**
  7993. * @inner
  7994. */
  7995. function doEnterHover(el) {
  7996. el.type === 'group' ? el.traverse(function (child) {
  7997. if (child.type !== 'group') {
  7998. doSingleEnterHover(child);
  7999. }
  8000. }) : doSingleEnterHover(el);
  8001. }
  8002. function doLeaveHover(el) {
  8003. el.type === 'group' ? el.traverse(function (child) {
  8004. if (child.type !== 'group') {
  8005. doSingleLeaveHover(child);
  8006. }
  8007. }) : doSingleLeaveHover(el);
  8008. }
  8009. /**
  8010. * @inner
  8011. */
  8012. function setElementHoverStl(el, hoverStl) {
  8013. // If element has sepcified hoverStyle, then use it instead of given hoverStyle
  8014. // Often used when item group has a label element and it's hoverStyle is different
  8015. el.__hoverStl = el.hoverStyle || hoverStl || {};
  8016. el.__hoverStlDirty = true;
  8017. if (el.__isHover) {
  8018. cacheElementStl(el);
  8019. }
  8020. }
  8021. /**
  8022. * @inner
  8023. */
  8024. function onElementMouseOver(e) {
  8025. if (this.__hoverSilentOnTouch && e.zrByTouch) {
  8026. return;
  8027. } // Only if element is not in emphasis status
  8028. !this.__isEmphasis && doEnterHover(this);
  8029. }
  8030. /**
  8031. * @inner
  8032. */
  8033. function onElementMouseOut(e) {
  8034. if (this.__hoverSilentOnTouch && e.zrByTouch) {
  8035. return;
  8036. } // Only if element is not in emphasis status
  8037. !this.__isEmphasis && doLeaveHover(this);
  8038. }
  8039. /**
  8040. * @inner
  8041. */
  8042. function enterEmphasis() {
  8043. this.__isEmphasis = true;
  8044. doEnterHover(this);
  8045. }
  8046. /**
  8047. * @inner
  8048. */
  8049. function leaveEmphasis() {
  8050. this.__isEmphasis = false;
  8051. doLeaveHover(this);
  8052. }
  8053. /**
  8054. * Set hover style of element.
  8055. * This method can be called repeatly without side-effects.
  8056. * @param {module:zrender/Element} el
  8057. * @param {Object} [hoverStyle]
  8058. * @param {Object} [opt]
  8059. * @param {boolean} [opt.hoverSilentOnTouch=false]
  8060. * In touch device, mouseover event will be trigger on touchstart event
  8061. * (see module:zrender/dom/HandlerProxy). By this mechanism, we can
  8062. * conviniently use hoverStyle when tap on touch screen without additional
  8063. * code for compatibility.
  8064. * But if the chart/component has select feature, which usually also use
  8065. * hoverStyle, there might be conflict between 'select-highlight' and
  8066. * 'hover-highlight' especially when roam is enabled (see geo for example).
  8067. * In this case, hoverSilentOnTouch should be used to disable hover-highlight
  8068. * on touch device.
  8069. */
  8070. function setHoverStyle(el, hoverStyle, opt) {
  8071. el.__hoverSilentOnTouch = opt && opt.hoverSilentOnTouch;
  8072. el.type === 'group' ? el.traverse(function (child) {
  8073. if (child.type !== 'group') {
  8074. setElementHoverStl(child, hoverStyle);
  8075. }
  8076. }) : setElementHoverStl(el, hoverStyle); // Duplicated function will be auto-ignored, see Eventful.js.
  8077. el.on('mouseover', onElementMouseOver).on('mouseout', onElementMouseOut); // Emphasis, normal can be triggered manually
  8078. el.on('emphasis', enterEmphasis).on('normal', leaveEmphasis);
  8079. }
  8080. /**
  8081. * @param {Object|module:zrender/graphic/Style} normalStyle
  8082. * @param {Object} emphasisStyle
  8083. * @param {module:echarts/model/Model} normalModel
  8084. * @param {module:echarts/model/Model} emphasisModel
  8085. * @param {Object} opt Check `opt` of `setTextStyleCommon` to find other props.
  8086. * @param {Object} [opt.defaultText]
  8087. * @param {module:echarts/model/Model} [opt.labelFetcher] Fetch text by
  8088. * `opt.labelFetcher.getFormattedLabel(opt.labelDataIndex, 'normal'/'emphasis', null, opt.labelDimIndex)`
  8089. * @param {module:echarts/model/Model} [opt.labelDataIndex] Fetch text by
  8090. * `opt.textFetcher.getFormattedLabel(opt.labelDataIndex, 'normal'/'emphasis', null, opt.labelDimIndex)`
  8091. * @param {module:echarts/model/Model} [opt.labelDimIndex] Fetch text by
  8092. * `opt.textFetcher.getFormattedLabel(opt.labelDataIndex, 'normal'/'emphasis', null, opt.labelDimIndex)`
  8093. * @param {Object} [normalSpecified]
  8094. * @param {Object} [emphasisSpecified]
  8095. */
  8096. function setLabelStyle(normalStyle, emphasisStyle, normalModel, emphasisModel, opt, normalSpecified, emphasisSpecified) {
  8097. opt = opt || EMPTY_OBJ;
  8098. var labelFetcher = opt.labelFetcher;
  8099. var labelDataIndex = opt.labelDataIndex;
  8100. var labelDimIndex = opt.labelDimIndex; // This scenario, `label.normal.show = true; label.emphasis.show = false`,
  8101. // is not supported util someone requests.
  8102. var showNormal = normalModel.getShallow('show');
  8103. var showEmphasis = emphasisModel.getShallow('show'); // Consider performance, only fetch label when necessary.
  8104. // If `normal.show` is `false` and `emphasis.show` is `true` and `emphasis.formatter` is not set,
  8105. // label should be displayed, where text is fetched by `normal.formatter` or `opt.defaultText`.
  8106. var baseText = showNormal || showEmphasis ? zrUtil.retrieve2(labelFetcher ? labelFetcher.getFormattedLabel(labelDataIndex, 'normal', null, labelDimIndex) : null, opt.defaultText) : null;
  8107. var normalStyleText = showNormal ? baseText : null;
  8108. var emphasisStyleText = showEmphasis ? zrUtil.retrieve2(labelFetcher ? labelFetcher.getFormattedLabel(labelDataIndex, 'emphasis', null, labelDimIndex) : null, baseText) : null; // Optimize: If style.text is null, text will not be drawn.
  8109. if (normalStyleText != null || emphasisStyleText != null) {
  8110. // Always set `textStyle` even if `normalStyle.text` is null, because default
  8111. // values have to be set on `normalStyle`.
  8112. // If we set default values on `emphasisStyle`, consider case:
  8113. // Firstly, `setOption(... label: {normal: {text: null}, emphasis: {show: true}} ...);`
  8114. // Secondly, `setOption(... label: {noraml: {show: true, text: 'abc', color: 'red'} ...);`
  8115. // Then the 'red' will not work on emphasis.
  8116. setTextStyle(normalStyle, normalModel, normalSpecified, opt);
  8117. setTextStyle(emphasisStyle, emphasisModel, emphasisSpecified, opt, true);
  8118. }
  8119. normalStyle.text = normalStyleText;
  8120. emphasisStyle.text = emphasisStyleText;
  8121. }
  8122. /**
  8123. * Set basic textStyle properties.
  8124. * @param {Object|module:zrender/graphic/Style} textStyle
  8125. * @param {module:echarts/model/Model} model
  8126. * @param {Object} [specifiedTextStyle] Can be overrided by settings in model.
  8127. * @param {Object} [opt] See `opt` of `setTextStyleCommon`.
  8128. * @param {boolean} [isEmphasis]
  8129. */
  8130. function setTextStyle(textStyle, textStyleModel, specifiedTextStyle, opt, isEmphasis) {
  8131. setTextStyleCommon(textStyle, textStyleModel, opt, isEmphasis);
  8132. specifiedTextStyle && zrUtil.extend(textStyle, specifiedTextStyle);
  8133. textStyle.host && textStyle.host.dirty && textStyle.host.dirty(false);
  8134. return textStyle;
  8135. }
  8136. /**
  8137. * Set text option in the style.
  8138. * @deprecated
  8139. * @param {Object} textStyle
  8140. * @param {module:echarts/model/Model} labelModel
  8141. * @param {string|boolean} defaultColor Default text color.
  8142. * If set as false, it will be processed as a emphasis style.
  8143. */
  8144. function setText(textStyle, labelModel, defaultColor) {
  8145. var opt = {
  8146. isRectText: true
  8147. };
  8148. var isEmphasis;
  8149. if (defaultColor === false) {
  8150. isEmphasis = true;
  8151. } else {
  8152. // Support setting color as 'auto' to get visual color.
  8153. opt.autoColor = defaultColor;
  8154. }
  8155. setTextStyleCommon(textStyle, labelModel, opt, isEmphasis);
  8156. textStyle.host && textStyle.host.dirty && textStyle.host.dirty(false);
  8157. }
  8158. /**
  8159. * {
  8160. * disableBox: boolean, Whether diable drawing box of block (outer most).
  8161. * isRectText: boolean,
  8162. * autoColor: string, specify a color when color is 'auto',
  8163. * for textFill, textStroke, textBackgroundColor, and textBorderColor.
  8164. * If autoColor specified, it is used as default textFill.
  8165. * useInsideStyle:
  8166. * `true`: Use inside style (textFill, textStroke, textStrokeWidth)
  8167. * if `textFill` is not specified.
  8168. * `false`: Do not use inside style.
  8169. * `null/undefined`: use inside style if `isRectText` is true and
  8170. * `textFill` is not specified and textPosition contains `'inside'`.
  8171. * forceRich: boolean
  8172. * }
  8173. */
  8174. function setTextStyleCommon(textStyle, textStyleModel, opt, isEmphasis) {
  8175. // Consider there will be abnormal when merge hover style to normal style if given default value.
  8176. opt = opt || EMPTY_OBJ;
  8177. if (opt.isRectText) {
  8178. var textPosition = textStyleModel.getShallow('position') || (isEmphasis ? null : 'inside'); // 'outside' is not a valid zr textPostion value, but used
  8179. // in bar series, and magric type should be considered.
  8180. textPosition === 'outside' && (textPosition = 'top');
  8181. textStyle.textPosition = textPosition;
  8182. textStyle.textOffset = textStyleModel.getShallow('offset');
  8183. var labelRotate = textStyleModel.getShallow('rotate');
  8184. labelRotate != null && (labelRotate *= Math.PI / 180);
  8185. textStyle.textRotation = labelRotate;
  8186. textStyle.textDistance = zrUtil.retrieve2(textStyleModel.getShallow('distance'), isEmphasis ? null : 5);
  8187. }
  8188. var ecModel = textStyleModel.ecModel;
  8189. var globalTextStyle = ecModel && ecModel.option.textStyle; // Consider case:
  8190. // {
  8191. // data: [{
  8192. // value: 12,
  8193. // label: {
  8194. // normal: {
  8195. // rich: {
  8196. // // no 'a' here but using parent 'a'.
  8197. // }
  8198. // }
  8199. // }
  8200. // }],
  8201. // rich: {
  8202. // a: { ... }
  8203. // }
  8204. // }
  8205. var richItemNames = getRichItemNames(textStyleModel);
  8206. var richResult;
  8207. if (richItemNames) {
  8208. richResult = {};
  8209. for (var name in richItemNames) {
  8210. if (richItemNames.hasOwnProperty(name)) {
  8211. // Cascade is supported in rich.
  8212. var richTextStyle = textStyleModel.getModel(['rich', name]); // In rich, never `disableBox`.
  8213. setTokenTextStyle(richResult[name] = {}, richTextStyle, globalTextStyle, opt, isEmphasis);
  8214. }
  8215. }
  8216. }
  8217. textStyle.rich = richResult;
  8218. setTokenTextStyle(textStyle, textStyleModel, globalTextStyle, opt, isEmphasis, true);
  8219. if (opt.forceRich && !opt.textStyle) {
  8220. opt.textStyle = {};
  8221. }
  8222. return textStyle;
  8223. } // Consider case:
  8224. // {
  8225. // data: [{
  8226. // value: 12,
  8227. // label: {
  8228. // normal: {
  8229. // rich: {
  8230. // // no 'a' here but using parent 'a'.
  8231. // }
  8232. // }
  8233. // }
  8234. // }],
  8235. // rich: {
  8236. // a: { ... }
  8237. // }
  8238. // }
  8239. function getRichItemNames(textStyleModel) {
  8240. // Use object to remove duplicated names.
  8241. var richItemNameMap;
  8242. while (textStyleModel && textStyleModel !== textStyleModel.ecModel) {
  8243. var rich = (textStyleModel.option || EMPTY_OBJ).rich;
  8244. if (rich) {
  8245. richItemNameMap = richItemNameMap || {};
  8246. for (var name in rich) {
  8247. if (rich.hasOwnProperty(name)) {
  8248. richItemNameMap[name] = 1;
  8249. }
  8250. }
  8251. }
  8252. textStyleModel = textStyleModel.parentModel;
  8253. }
  8254. return richItemNameMap;
  8255. }
  8256. function setTokenTextStyle(textStyle, textStyleModel, globalTextStyle, opt, isEmphasis, isBlock) {
  8257. // In merge mode, default value should not be given.
  8258. globalTextStyle = !isEmphasis && globalTextStyle || EMPTY_OBJ;
  8259. textStyle.textFill = getAutoColor(textStyleModel.getShallow('color'), opt) || globalTextStyle.color;
  8260. textStyle.textStroke = getAutoColor(textStyleModel.getShallow('textBorderColor'), opt) || globalTextStyle.textBorderColor;
  8261. textStyle.textStrokeWidth = zrUtil.retrieve2(textStyleModel.getShallow('textBorderWidth'), globalTextStyle.textBorderWidth);
  8262. if (!isEmphasis) {
  8263. if (isBlock) {
  8264. // Always set `insideRollback`, for clearing previous.
  8265. var originalTextPosition = textStyle.textPosition;
  8266. textStyle.insideRollback = applyInsideStyle(textStyle, originalTextPosition, opt); // Save original textPosition, because style.textPosition will be repalced by
  8267. // real location (like [10, 30]) in zrender.
  8268. textStyle.insideOriginalTextPosition = originalTextPosition;
  8269. textStyle.insideRollbackOpt = opt;
  8270. } // Set default finally.
  8271. if (textStyle.textFill == null) {
  8272. textStyle.textFill = opt.autoColor;
  8273. }
  8274. } // Do not use `getFont` here, because merge should be supported, where
  8275. // part of these properties may be changed in emphasis style, and the
  8276. // others should remain their original value got from normal style.
  8277. textStyle.fontStyle = textStyleModel.getShallow('fontStyle') || globalTextStyle.fontStyle;
  8278. textStyle.fontWeight = textStyleModel.getShallow('fontWeight') || globalTextStyle.fontWeight;
  8279. textStyle.fontSize = textStyleModel.getShallow('fontSize') || globalTextStyle.fontSize;
  8280. textStyle.fontFamily = textStyleModel.getShallow('fontFamily') || globalTextStyle.fontFamily;
  8281. textStyle.textAlign = textStyleModel.getShallow('align');
  8282. textStyle.textVerticalAlign = textStyleModel.getShallow('verticalAlign') || textStyleModel.getShallow('baseline');
  8283. textStyle.textLineHeight = textStyleModel.getShallow('lineHeight');
  8284. textStyle.textWidth = textStyleModel.getShallow('width');
  8285. textStyle.textHeight = textStyleModel.getShallow('height');
  8286. textStyle.textTag = textStyleModel.getShallow('tag');
  8287. if (!isBlock || !opt.disableBox) {
  8288. textStyle.textBackgroundColor = getAutoColor(textStyleModel.getShallow('backgroundColor'), opt);
  8289. textStyle.textPadding = textStyleModel.getShallow('padding');
  8290. textStyle.textBorderColor = getAutoColor(textStyleModel.getShallow('borderColor'), opt);
  8291. textStyle.textBorderWidth = textStyleModel.getShallow('borderWidth');
  8292. textStyle.textBorderRadius = textStyleModel.getShallow('borderRadius');
  8293. textStyle.textBoxShadowColor = textStyleModel.getShallow('shadowColor');
  8294. textStyle.textBoxShadowBlur = textStyleModel.getShallow('shadowBlur');
  8295. textStyle.textBoxShadowOffsetX = textStyleModel.getShallow('shadowOffsetX');
  8296. textStyle.textBoxShadowOffsetY = textStyleModel.getShallow('shadowOffsetY');
  8297. }
  8298. textStyle.textShadowColor = textStyleModel.getShallow('textShadowColor') || globalTextStyle.textShadowColor;
  8299. textStyle.textShadowBlur = textStyleModel.getShallow('textShadowBlur') || globalTextStyle.textShadowBlur;
  8300. textStyle.textShadowOffsetX = textStyleModel.getShallow('textShadowOffsetX') || globalTextStyle.textShadowOffsetX;
  8301. textStyle.textShadowOffsetY = textStyleModel.getShallow('textShadowOffsetY') || globalTextStyle.textShadowOffsetY;
  8302. }
  8303. function getAutoColor(color, opt) {
  8304. return color !== 'auto' ? color : opt && opt.autoColor ? opt.autoColor : null;
  8305. }
  8306. function applyInsideStyle(textStyle, textPosition, opt) {
  8307. var useInsideStyle = opt.useInsideStyle;
  8308. var insideRollback;
  8309. if (textStyle.textFill == null && useInsideStyle !== false && (useInsideStyle === true || opt.isRectText && textPosition // textPosition can be [10, 30]
  8310. && typeof textPosition === 'string' && textPosition.indexOf('inside') >= 0)) {
  8311. insideRollback = {
  8312. textFill: null,
  8313. textStroke: textStyle.textStroke,
  8314. textStrokeWidth: textStyle.textStrokeWidth
  8315. };
  8316. textStyle.textFill = '#fff'; // Consider text with #fff overflow its container.
  8317. if (textStyle.textStroke == null) {
  8318. textStyle.textStroke = opt.autoColor;
  8319. textStyle.textStrokeWidth == null && (textStyle.textStrokeWidth = 2);
  8320. }
  8321. }
  8322. return insideRollback;
  8323. }
  8324. function rollbackInsideStyle(style) {
  8325. var insideRollback = style.insideRollback;
  8326. if (insideRollback) {
  8327. style.textFill = insideRollback.textFill;
  8328. style.textStroke = insideRollback.textStroke;
  8329. style.textStrokeWidth = insideRollback.textStrokeWidth;
  8330. }
  8331. }
  8332. function getFont(opt, ecModel) {
  8333. // ecModel or default text style model.
  8334. var gTextStyleModel = ecModel || ecModel.getModel('textStyle');
  8335. return [// FIXME in node-canvas fontWeight is before fontStyle
  8336. opt.fontStyle || gTextStyleModel && gTextStyleModel.getShallow('fontStyle') || '', opt.fontWeight || gTextStyleModel && gTextStyleModel.getShallow('fontWeight') || '', (opt.fontSize || gTextStyleModel && gTextStyleModel.getShallow('fontSize') || 12) + 'px', opt.fontFamily || gTextStyleModel && gTextStyleModel.getShallow('fontFamily') || 'sans-serif'].join(' ');
  8337. }
  8338. function animateOrSetProps(isUpdate, el, props, animatableModel, dataIndex, cb) {
  8339. if (typeof dataIndex === 'function') {
  8340. cb = dataIndex;
  8341. dataIndex = null;
  8342. } // Do not check 'animation' property directly here. Consider this case:
  8343. // animation model is an `itemModel`, whose does not have `isAnimationEnabled`
  8344. // but its parent model (`seriesModel`) does.
  8345. var animationEnabled = animatableModel && animatableModel.isAnimationEnabled();
  8346. if (animationEnabled) {
  8347. var postfix = isUpdate ? 'Update' : '';
  8348. var duration = animatableModel.getShallow('animationDuration' + postfix);
  8349. var animationEasing = animatableModel.getShallow('animationEasing' + postfix);
  8350. var animationDelay = animatableModel.getShallow('animationDelay' + postfix);
  8351. if (typeof animationDelay === 'function') {
  8352. animationDelay = animationDelay(dataIndex, animatableModel.getAnimationDelayParams ? animatableModel.getAnimationDelayParams(el, dataIndex) : null);
  8353. }
  8354. if (typeof duration === 'function') {
  8355. duration = duration(dataIndex);
  8356. }
  8357. duration > 0 ? el.animateTo(props, duration, animationDelay || 0, animationEasing, cb, !!cb) : (el.stopAnimation(), el.attr(props), cb && cb());
  8358. } else {
  8359. el.stopAnimation();
  8360. el.attr(props);
  8361. cb && cb();
  8362. }
  8363. }
  8364. /**
  8365. * Update graphic element properties with or without animation according to the
  8366. * configuration in series.
  8367. *
  8368. * Caution: this method will stop previous animation.
  8369. * So if do not use this method to one element twice before
  8370. * animation starts, unless you know what you are doing.
  8371. *
  8372. * @param {module:zrender/Element} el
  8373. * @param {Object} props
  8374. * @param {module:echarts/model/Model} [animatableModel]
  8375. * @param {number} [dataIndex]
  8376. * @param {Function} [cb]
  8377. * @example
  8378. * graphic.updateProps(el, {
  8379. * position: [100, 100]
  8380. * }, seriesModel, dataIndex, function () { console.log('Animation done!'); });
  8381. * // Or
  8382. * graphic.updateProps(el, {
  8383. * position: [100, 100]
  8384. * }, seriesModel, function () { console.log('Animation done!'); });
  8385. */
  8386. function updateProps(el, props, animatableModel, dataIndex, cb) {
  8387. animateOrSetProps(true, el, props, animatableModel, dataIndex, cb);
  8388. }
  8389. /**
  8390. * Init graphic element properties with or without animation according to the
  8391. * configuration in series.
  8392. *
  8393. * Caution: this method will stop previous animation.
  8394. * So if do not use this method to one element twice before
  8395. * animation starts, unless you know what you are doing.
  8396. *
  8397. * @param {module:zrender/Element} el
  8398. * @param {Object} props
  8399. * @param {module:echarts/model/Model} [animatableModel]
  8400. * @param {number} [dataIndex]
  8401. * @param {Function} cb
  8402. */
  8403. function initProps(el, props, animatableModel, dataIndex, cb) {
  8404. animateOrSetProps(false, el, props, animatableModel, dataIndex, cb);
  8405. }
  8406. /**
  8407. * Get transform matrix of target (param target),
  8408. * in coordinate of its ancestor (param ancestor)
  8409. *
  8410. * @param {module:zrender/mixin/Transformable} target
  8411. * @param {module:zrender/mixin/Transformable} [ancestor]
  8412. */
  8413. function getTransform(target, ancestor) {
  8414. var mat = matrix.identity([]);
  8415. while (target && target !== ancestor) {
  8416. matrix.mul(mat, target.getLocalTransform(), mat);
  8417. target = target.parent;
  8418. }
  8419. return mat;
  8420. }
  8421. /**
  8422. * Apply transform to an vertex.
  8423. * @param {Array.<number>} target [x, y]
  8424. * @param {Array.<number>|TypedArray.<number>|Object} transform Can be:
  8425. * + Transform matrix: like [1, 0, 0, 1, 0, 0]
  8426. * + {position, rotation, scale}, the same as `zrender/Transformable`.
  8427. * @param {boolean=} invert Whether use invert matrix.
  8428. * @return {Array.<number>} [x, y]
  8429. */
  8430. function applyTransform(target, transform, invert) {
  8431. if (transform && !zrUtil.isArrayLike(transform)) {
  8432. transform = Transformable.getLocalTransform(transform);
  8433. }
  8434. if (invert) {
  8435. transform = matrix.invert([], transform);
  8436. }
  8437. return vector.applyTransform([], target, transform);
  8438. }
  8439. /**
  8440. * @param {string} direction 'left' 'right' 'top' 'bottom'
  8441. * @param {Array.<number>} transform Transform matrix: like [1, 0, 0, 1, 0, 0]
  8442. * @param {boolean=} invert Whether use invert matrix.
  8443. * @return {string} Transformed direction. 'left' 'right' 'top' 'bottom'
  8444. */
  8445. function transformDirection(direction, transform, invert) {
  8446. // Pick a base, ensure that transform result will not be (0, 0).
  8447. var hBase = transform[4] === 0 || transform[5] === 0 || transform[0] === 0 ? 1 : Math.abs(2 * transform[4] / transform[0]);
  8448. var vBase = transform[4] === 0 || transform[5] === 0 || transform[2] === 0 ? 1 : Math.abs(2 * transform[4] / transform[2]);
  8449. var vertex = [direction === 'left' ? -hBase : direction === 'right' ? hBase : 0, direction === 'top' ? -vBase : direction === 'bottom' ? vBase : 0];
  8450. vertex = applyTransform(vertex, transform, invert);
  8451. return Math.abs(vertex[0]) > Math.abs(vertex[1]) ? vertex[0] > 0 ? 'right' : 'left' : vertex[1] > 0 ? 'bottom' : 'top';
  8452. }
  8453. /**
  8454. * Apply group transition animation from g1 to g2.
  8455. * If no animatableModel, no animation.
  8456. */
  8457. function groupTransition(g1, g2, animatableModel, cb) {
  8458. if (!g1 || !g2) {
  8459. return;
  8460. }
  8461. function getElMap(g) {
  8462. var elMap = {};
  8463. g.traverse(function (el) {
  8464. if (!el.isGroup && el.anid) {
  8465. elMap[el.anid] = el;
  8466. }
  8467. });
  8468. return elMap;
  8469. }
  8470. function getAnimatableProps(el) {
  8471. var obj = {
  8472. position: vector.clone(el.position),
  8473. rotation: el.rotation
  8474. };
  8475. if (el.shape) {
  8476. obj.shape = zrUtil.extend({}, el.shape);
  8477. }
  8478. return obj;
  8479. }
  8480. var elMap1 = getElMap(g1);
  8481. g2.traverse(function (el) {
  8482. if (!el.isGroup && el.anid) {
  8483. var oldEl = elMap1[el.anid];
  8484. if (oldEl) {
  8485. var newProp = getAnimatableProps(el);
  8486. el.attr(getAnimatableProps(oldEl));
  8487. updateProps(el, newProp, animatableModel, el.dataIndex);
  8488. } // else {
  8489. // if (el.previousProps) {
  8490. // graphic.updateProps
  8491. // }
  8492. // }
  8493. }
  8494. });
  8495. }
  8496. /**
  8497. * @param {Array.<Array.<number>>} points Like: [[23, 44], [53, 66], ...]
  8498. * @param {Object} rect {x, y, width, height}
  8499. * @return {Array.<Array.<number>>} A new clipped points.
  8500. */
  8501. function clipPointsByRect(points, rect) {
  8502. return zrUtil.map(points, function (point) {
  8503. var x = point[0];
  8504. x = mathMax(x, rect.x);
  8505. x = mathMin(x, rect.x + rect.width);
  8506. var y = point[1];
  8507. y = mathMax(y, rect.y);
  8508. y = mathMin(y, rect.y + rect.height);
  8509. return [x, y];
  8510. });
  8511. }
  8512. /**
  8513. * @param {Object} targetRect {x, y, width, height}
  8514. * @param {Object} rect {x, y, width, height}
  8515. * @return {Object} A new clipped rect. If rect size are negative, return undefined.
  8516. */
  8517. function clipRectByRect(targetRect, rect) {
  8518. var x = mathMax(targetRect.x, rect.x);
  8519. var x2 = mathMin(targetRect.x + targetRect.width, rect.x + rect.width);
  8520. var y = mathMax(targetRect.y, rect.y);
  8521. var y2 = mathMin(targetRect.y + targetRect.height, rect.y + rect.height);
  8522. if (x2 >= x && y2 >= y) {
  8523. return {
  8524. x: x,
  8525. y: y,
  8526. width: x2 - x,
  8527. height: y2 - y
  8528. };
  8529. }
  8530. }
  8531. /**
  8532. * @param {string} iconStr Support 'image://' or 'path://' or direct svg path.
  8533. * @param {Object} [opt] Properties of `module:zrender/Element`, except `style`.
  8534. * @param {Object} [rect] {x, y, width, height}
  8535. * @return {module:zrender/Element} Icon path or image element.
  8536. */
  8537. function createIcon(iconStr, opt, rect) {
  8538. opt = zrUtil.extend({
  8539. rectHover: true
  8540. }, opt);
  8541. var style = opt.style = {
  8542. strokeNoScale: true
  8543. };
  8544. rect = rect || {
  8545. x: -1,
  8546. y: -1,
  8547. width: 2,
  8548. height: 2
  8549. };
  8550. if (iconStr) {
  8551. return iconStr.indexOf('image://') === 0 ? (style.image = iconStr.slice(8), zrUtil.defaults(style, rect), new Image(opt)) : makePath(iconStr.replace('path://', ''), opt, rect, 'center');
  8552. }
  8553. }
  8554. exports.extendShape = extendShape;
  8555. exports.extendPath = extendPath;
  8556. exports.makePath = makePath;
  8557. exports.makeImage = makeImage;
  8558. exports.mergePath = mergePath;
  8559. exports.resizePath = resizePath;
  8560. exports.subPixelOptimizeLine = subPixelOptimizeLine;
  8561. exports.subPixelOptimizeRect = subPixelOptimizeRect;
  8562. exports.subPixelOptimize = subPixelOptimize;
  8563. exports.setHoverStyle = setHoverStyle;
  8564. exports.setLabelStyle = setLabelStyle;
  8565. exports.setTextStyle = setTextStyle;
  8566. exports.setText = setText;
  8567. exports.getFont = getFont;
  8568. exports.updateProps = updateProps;
  8569. exports.initProps = initProps;
  8570. exports.getTransform = getTransform;
  8571. exports.applyTransform = applyTransform;
  8572. exports.transformDirection = transformDirection;
  8573. exports.groupTransition = groupTransition;
  8574. exports.clipPointsByRect = clipPointsByRect;
  8575. exports.clipRectByRect = clipRectByRect;
  8576. exports.createIcon = createIcon;
  8577. /***/ }),
  8578. /* 39 */
  8579. /***/ (function(module, exports, __webpack_require__) {
  8580. var Path = __webpack_require__(1);
  8581. var PathProxy = __webpack_require__(6);
  8582. var transformPath = __webpack_require__(57);
  8583. // command chars
  8584. var cc = ['m', 'M', 'l', 'L', 'v', 'V', 'h', 'H', 'z', 'Z', 'c', 'C', 'q', 'Q', 't', 'T', 's', 'S', 'a', 'A'];
  8585. var mathSqrt = Math.sqrt;
  8586. var mathSin = Math.sin;
  8587. var mathCos = Math.cos;
  8588. var PI = Math.PI;
  8589. var vMag = function (v) {
  8590. return Math.sqrt(v[0] * v[0] + v[1] * v[1]);
  8591. };
  8592. var vRatio = function (u, v) {
  8593. return (u[0] * v[0] + u[1] * v[1]) / (vMag(u) * vMag(v));
  8594. };
  8595. var vAngle = function (u, v) {
  8596. return (u[0] * v[1] < u[1] * v[0] ? -1 : 1) * Math.acos(vRatio(u, v));
  8597. };
  8598. function processArc(x1, y1, x2, y2, fa, fs, rx, ry, psiDeg, cmd, path) {
  8599. var psi = psiDeg * (PI / 180.0);
  8600. var xp = mathCos(psi) * (x1 - x2) / 2.0 + mathSin(psi) * (y1 - y2) / 2.0;
  8601. var yp = -1 * mathSin(psi) * (x1 - x2) / 2.0 + mathCos(psi) * (y1 - y2) / 2.0;
  8602. var lambda = xp * xp / (rx * rx) + yp * yp / (ry * ry);
  8603. if (lambda > 1) {
  8604. rx *= mathSqrt(lambda);
  8605. ry *= mathSqrt(lambda);
  8606. }
  8607. var f = (fa === fs ? -1 : 1) * mathSqrt((rx * rx * (ry * ry) - rx * rx * (yp * yp) - ry * ry * (xp * xp)) / (rx * rx * (yp * yp) + ry * ry * (xp * xp))) || 0;
  8608. var cxp = f * rx * yp / ry;
  8609. var cyp = f * -ry * xp / rx;
  8610. var cx = (x1 + x2) / 2.0 + mathCos(psi) * cxp - mathSin(psi) * cyp;
  8611. var cy = (y1 + y2) / 2.0 + mathSin(psi) * cxp + mathCos(psi) * cyp;
  8612. var theta = vAngle([1, 0], [(xp - cxp) / rx, (yp - cyp) / ry]);
  8613. var u = [(xp - cxp) / rx, (yp - cyp) / ry];
  8614. var v = [(-1 * xp - cxp) / rx, (-1 * yp - cyp) / ry];
  8615. var dTheta = vAngle(u, v);
  8616. if (vRatio(u, v) <= -1) {
  8617. dTheta = PI;
  8618. }
  8619. if (vRatio(u, v) >= 1) {
  8620. dTheta = 0;
  8621. }
  8622. if (fs === 0 && dTheta > 0) {
  8623. dTheta = dTheta - 2 * PI;
  8624. }
  8625. if (fs === 1 && dTheta < 0) {
  8626. dTheta = dTheta + 2 * PI;
  8627. }
  8628. path.addData(cmd, cx, cy, rx, ry, theta, dTheta, psi, fs);
  8629. }
  8630. function createPathProxyFromString(data) {
  8631. if (!data) {
  8632. return [];
  8633. } // command string
  8634. var cs = data.replace(/-/g, ' -').replace(/ /g, ' ').replace(/ /g, ',').replace(/,,/g, ',');
  8635. var n; // create pipes so that we can split the data
  8636. for (n = 0; n < cc.length; n++) {
  8637. cs = cs.replace(new RegExp(cc[n], 'g'), '|' + cc[n]);
  8638. } // create array
  8639. var arr = cs.split('|'); // init context point
  8640. var cpx = 0;
  8641. var cpy = 0;
  8642. var path = new PathProxy();
  8643. var CMD = PathProxy.CMD;
  8644. var prevCmd;
  8645. for (n = 1; n < arr.length; n++) {
  8646. var str = arr[n];
  8647. var c = str.charAt(0);
  8648. var off = 0;
  8649. var p = str.slice(1).replace(/e,-/g, 'e-').split(',');
  8650. var cmd;
  8651. if (p.length > 0 && p[0] === '') {
  8652. p.shift();
  8653. }
  8654. for (var i = 0; i < p.length; i++) {
  8655. p[i] = parseFloat(p[i]);
  8656. }
  8657. while (off < p.length && !isNaN(p[off])) {
  8658. if (isNaN(p[0])) {
  8659. break;
  8660. }
  8661. var ctlPtx;
  8662. var ctlPty;
  8663. var rx;
  8664. var ry;
  8665. var psi;
  8666. var fa;
  8667. var fs;
  8668. var x1 = cpx;
  8669. var y1 = cpy; // convert l, H, h, V, and v to L
  8670. switch (c) {
  8671. case 'l':
  8672. cpx += p[off++];
  8673. cpy += p[off++];
  8674. cmd = CMD.L;
  8675. path.addData(cmd, cpx, cpy);
  8676. break;
  8677. case 'L':
  8678. cpx = p[off++];
  8679. cpy = p[off++];
  8680. cmd = CMD.L;
  8681. path.addData(cmd, cpx, cpy);
  8682. break;
  8683. case 'm':
  8684. cpx += p[off++];
  8685. cpy += p[off++];
  8686. cmd = CMD.M;
  8687. path.addData(cmd, cpx, cpy);
  8688. c = 'l';
  8689. break;
  8690. case 'M':
  8691. cpx = p[off++];
  8692. cpy = p[off++];
  8693. cmd = CMD.M;
  8694. path.addData(cmd, cpx, cpy);
  8695. c = 'L';
  8696. break;
  8697. case 'h':
  8698. cpx += p[off++];
  8699. cmd = CMD.L;
  8700. path.addData(cmd, cpx, cpy);
  8701. break;
  8702. case 'H':
  8703. cpx = p[off++];
  8704. cmd = CMD.L;
  8705. path.addData(cmd, cpx, cpy);
  8706. break;
  8707. case 'v':
  8708. cpy += p[off++];
  8709. cmd = CMD.L;
  8710. path.addData(cmd, cpx, cpy);
  8711. break;
  8712. case 'V':
  8713. cpy = p[off++];
  8714. cmd = CMD.L;
  8715. path.addData(cmd, cpx, cpy);
  8716. break;
  8717. case 'C':
  8718. cmd = CMD.C;
  8719. path.addData(cmd, p[off++], p[off++], p[off++], p[off++], p[off++], p[off++]);
  8720. cpx = p[off - 2];
  8721. cpy = p[off - 1];
  8722. break;
  8723. case 'c':
  8724. cmd = CMD.C;
  8725. path.addData(cmd, p[off++] + cpx, p[off++] + cpy, p[off++] + cpx, p[off++] + cpy, p[off++] + cpx, p[off++] + cpy);
  8726. cpx += p[off - 2];
  8727. cpy += p[off - 1];
  8728. break;
  8729. case 'S':
  8730. ctlPtx = cpx;
  8731. ctlPty = cpy;
  8732. var len = path.len();
  8733. var pathData = path.data;
  8734. if (prevCmd === CMD.C) {
  8735. ctlPtx += cpx - pathData[len - 4];
  8736. ctlPty += cpy - pathData[len - 3];
  8737. }
  8738. cmd = CMD.C;
  8739. x1 = p[off++];
  8740. y1 = p[off++];
  8741. cpx = p[off++];
  8742. cpy = p[off++];
  8743. path.addData(cmd, ctlPtx, ctlPty, x1, y1, cpx, cpy);
  8744. break;
  8745. case 's':
  8746. ctlPtx = cpx;
  8747. ctlPty = cpy;
  8748. var len = path.len();
  8749. var pathData = path.data;
  8750. if (prevCmd === CMD.C) {
  8751. ctlPtx += cpx - pathData[len - 4];
  8752. ctlPty += cpy - pathData[len - 3];
  8753. }
  8754. cmd = CMD.C;
  8755. x1 = cpx + p[off++];
  8756. y1 = cpy + p[off++];
  8757. cpx += p[off++];
  8758. cpy += p[off++];
  8759. path.addData(cmd, ctlPtx, ctlPty, x1, y1, cpx, cpy);
  8760. break;
  8761. case 'Q':
  8762. x1 = p[off++];
  8763. y1 = p[off++];
  8764. cpx = p[off++];
  8765. cpy = p[off++];
  8766. cmd = CMD.Q;
  8767. path.addData(cmd, x1, y1, cpx, cpy);
  8768. break;
  8769. case 'q':
  8770. x1 = p[off++] + cpx;
  8771. y1 = p[off++] + cpy;
  8772. cpx += p[off++];
  8773. cpy += p[off++];
  8774. cmd = CMD.Q;
  8775. path.addData(cmd, x1, y1, cpx, cpy);
  8776. break;
  8777. case 'T':
  8778. ctlPtx = cpx;
  8779. ctlPty = cpy;
  8780. var len = path.len();
  8781. var pathData = path.data;
  8782. if (prevCmd === CMD.Q) {
  8783. ctlPtx += cpx - pathData[len - 4];
  8784. ctlPty += cpy - pathData[len - 3];
  8785. }
  8786. cpx = p[off++];
  8787. cpy = p[off++];
  8788. cmd = CMD.Q;
  8789. path.addData(cmd, ctlPtx, ctlPty, cpx, cpy);
  8790. break;
  8791. case 't':
  8792. ctlPtx = cpx;
  8793. ctlPty = cpy;
  8794. var len = path.len();
  8795. var pathData = path.data;
  8796. if (prevCmd === CMD.Q) {
  8797. ctlPtx += cpx - pathData[len - 4];
  8798. ctlPty += cpy - pathData[len - 3];
  8799. }
  8800. cpx += p[off++];
  8801. cpy += p[off++];
  8802. cmd = CMD.Q;
  8803. path.addData(cmd, ctlPtx, ctlPty, cpx, cpy);
  8804. break;
  8805. case 'A':
  8806. rx = p[off++];
  8807. ry = p[off++];
  8808. psi = p[off++];
  8809. fa = p[off++];
  8810. fs = p[off++];
  8811. x1 = cpx, y1 = cpy;
  8812. cpx = p[off++];
  8813. cpy = p[off++];
  8814. cmd = CMD.A;
  8815. processArc(x1, y1, cpx, cpy, fa, fs, rx, ry, psi, cmd, path);
  8816. break;
  8817. case 'a':
  8818. rx = p[off++];
  8819. ry = p[off++];
  8820. psi = p[off++];
  8821. fa = p[off++];
  8822. fs = p[off++];
  8823. x1 = cpx, y1 = cpy;
  8824. cpx += p[off++];
  8825. cpy += p[off++];
  8826. cmd = CMD.A;
  8827. processArc(x1, y1, cpx, cpy, fa, fs, rx, ry, psi, cmd, path);
  8828. break;
  8829. }
  8830. }
  8831. if (c === 'z' || c === 'Z') {
  8832. cmd = CMD.Z;
  8833. path.addData(cmd);
  8834. }
  8835. prevCmd = cmd;
  8836. }
  8837. path.toStatic();
  8838. return path;
  8839. } // TODO Optimize double memory cost problem
  8840. function createPathOptions(str, opts) {
  8841. var pathProxy = createPathProxyFromString(str);
  8842. opts = opts || {};
  8843. opts.buildPath = function (path) {
  8844. if (path.setData) {
  8845. path.setData(pathProxy.data); // Svg and vml renderer don't have context
  8846. var ctx = path.getContext();
  8847. if (ctx) {
  8848. path.rebuildPath(ctx);
  8849. }
  8850. } else {
  8851. var ctx = path;
  8852. pathProxy.rebuildPath(ctx);
  8853. }
  8854. };
  8855. opts.applyTransform = function (m) {
  8856. transformPath(pathProxy, m);
  8857. this.dirty(true);
  8858. };
  8859. return opts;
  8860. }
  8861. /**
  8862. * Create a Path object from path string data
  8863. * http://www.w3.org/TR/SVG/paths.html#PathData
  8864. * @param {Object} opts Other options
  8865. */
  8866. function createFromString(str, opts) {
  8867. return new Path(createPathOptions(str, opts));
  8868. }
  8869. /**
  8870. * Create a Path class from path string data
  8871. * @param {string} str
  8872. * @param {Object} opts Other options
  8873. */
  8874. function extendFromString(str, opts) {
  8875. return Path.extend(createPathOptions(str, opts));
  8876. }
  8877. /**
  8878. * Merge multiple paths
  8879. */
  8880. // TODO Apply transform
  8881. // TODO stroke dash
  8882. // TODO Optimize double memory cost problem
  8883. function mergePath(pathEls, opts) {
  8884. var pathList = [];
  8885. var len = pathEls.length;
  8886. for (var i = 0; i < len; i++) {
  8887. var pathEl = pathEls[i];
  8888. if (!pathEl.path) {
  8889. pathEl.createPathProxy();
  8890. }
  8891. if (pathEl.__dirtyPath) {
  8892. pathEl.buildPath(pathEl.path, pathEl.shape, true);
  8893. }
  8894. pathList.push(pathEl.path);
  8895. }
  8896. var pathBundle = new Path(opts); // Need path proxy.
  8897. pathBundle.createPathProxy();
  8898. pathBundle.buildPath = function (path) {
  8899. path.appendPath(pathList); // Svg and vml renderer don't have context
  8900. var ctx = path.getContext();
  8901. if (ctx) {
  8902. path.rebuildPath(ctx);
  8903. }
  8904. };
  8905. return pathBundle;
  8906. }
  8907. exports.createFromString = createFromString;
  8908. exports.extendFromString = extendFromString;
  8909. exports.mergePath = mergePath;
  8910. /***/ }),
  8911. /* 40 */
  8912. /***/ (function(module, exports) {
  8913. var STYLE_COMMON_PROPS = [['shadowBlur', 0], ['shadowOffsetX', 0], ['shadowOffsetY', 0], ['shadowColor', '#000'], ['lineCap', 'butt'], ['lineJoin', 'miter'], ['miterLimit', 10]]; // var SHADOW_PROPS = STYLE_COMMON_PROPS.slice(0, 4);
  8914. // var LINE_PROPS = STYLE_COMMON_PROPS.slice(4);
  8915. var Style = function (opts, host) {
  8916. this.extendFrom(opts, false);
  8917. this.host = host;
  8918. };
  8919. function createLinearGradient(ctx, obj, rect) {
  8920. var x = obj.x == null ? 0 : obj.x;
  8921. var x2 = obj.x2 == null ? 1 : obj.x2;
  8922. var y = obj.y == null ? 0 : obj.y;
  8923. var y2 = obj.y2 == null ? 0 : obj.y2;
  8924. if (!obj.global) {
  8925. x = x * rect.width + rect.x;
  8926. x2 = x2 * rect.width + rect.x;
  8927. y = y * rect.height + rect.y;
  8928. y2 = y2 * rect.height + rect.y;
  8929. }
  8930. var canvasGradient = ctx.createLinearGradient(x, y, x2, y2);
  8931. return canvasGradient;
  8932. }
  8933. function createRadialGradient(ctx, obj, rect) {
  8934. var width = rect.width;
  8935. var height = rect.height;
  8936. var min = Math.min(width, height);
  8937. var x = obj.x == null ? 0.5 : obj.x;
  8938. var y = obj.y == null ? 0.5 : obj.y;
  8939. var r = obj.r == null ? 0.5 : obj.r;
  8940. if (!obj.global) {
  8941. x = x * width + rect.x;
  8942. y = y * height + rect.y;
  8943. r = r * min;
  8944. }
  8945. var canvasGradient = ctx.createRadialGradient(x, y, 0, x, y, r);
  8946. return canvasGradient;
  8947. }
  8948. Style.prototype = {
  8949. constructor: Style,
  8950. /**
  8951. * @type {module:zrender/graphic/Displayable}
  8952. */
  8953. host: null,
  8954. /**
  8955. * @type {string}
  8956. */
  8957. fill: '#000',
  8958. /**
  8959. * @type {string}
  8960. */
  8961. stroke: null,
  8962. /**
  8963. * @type {number}
  8964. */
  8965. opacity: 1,
  8966. /**
  8967. * @type {Array.<number>}
  8968. */
  8969. lineDash: null,
  8970. /**
  8971. * @type {number}
  8972. */
  8973. lineDashOffset: 0,
  8974. /**
  8975. * @type {number}
  8976. */
  8977. shadowBlur: 0,
  8978. /**
  8979. * @type {number}
  8980. */
  8981. shadowOffsetX: 0,
  8982. /**
  8983. * @type {number}
  8984. */
  8985. shadowOffsetY: 0,
  8986. /**
  8987. * @type {number}
  8988. */
  8989. lineWidth: 1,
  8990. /**
  8991. * If stroke ignore scale
  8992. * @type {Boolean}
  8993. */
  8994. strokeNoScale: false,
  8995. // Bounding rect text configuration
  8996. // Not affected by element transform
  8997. /**
  8998. * @type {string}
  8999. */
  9000. text: null,
  9001. /**
  9002. * If `fontSize` or `fontFamily` exists, `font` will be reset by
  9003. * `fontSize`, `fontStyle`, `fontWeight`, `fontFamily`.
  9004. * So do not visit it directly in upper application (like echarts),
  9005. * but use `contain/text#makeFont` instead.
  9006. * @type {string}
  9007. */
  9008. font: null,
  9009. /**
  9010. * The same as font. Use font please.
  9011. * @deprecated
  9012. * @type {string}
  9013. */
  9014. textFont: null,
  9015. /**
  9016. * It helps merging respectively, rather than parsing an entire font string.
  9017. * @type {string}
  9018. */
  9019. fontStyle: null,
  9020. /**
  9021. * It helps merging respectively, rather than parsing an entire font string.
  9022. * @type {string}
  9023. */
  9024. fontWeight: null,
  9025. /**
  9026. * It helps merging respectively, rather than parsing an entire font string.
  9027. * Should be 12 but not '12px'.
  9028. * @type {number}
  9029. */
  9030. fontSize: null,
  9031. /**
  9032. * It helps merging respectively, rather than parsing an entire font string.
  9033. * @type {string}
  9034. */
  9035. fontFamily: null,
  9036. /**
  9037. * Reserved for special functinality, like 'hr'.
  9038. * @type {string}
  9039. */
  9040. textTag: null,
  9041. /**
  9042. * @type {string}
  9043. */
  9044. textFill: '#000',
  9045. /**
  9046. * @type {string}
  9047. */
  9048. textStroke: null,
  9049. /**
  9050. * @type {number}
  9051. */
  9052. textWidth: null,
  9053. /**
  9054. * Only for textBackground.
  9055. * @type {number}
  9056. */
  9057. textHeight: null,
  9058. /**
  9059. * textStroke may be set as some color as a default
  9060. * value in upper applicaion, where the default value
  9061. * of textStrokeWidth should be 0 to make sure that
  9062. * user can choose to do not use text stroke.
  9063. * @type {number}
  9064. */
  9065. textStrokeWidth: 0,
  9066. /**
  9067. * @type {number}
  9068. */
  9069. textLineHeight: null,
  9070. /**
  9071. * 'inside', 'left', 'right', 'top', 'bottom'
  9072. * [x, y]
  9073. * Based on x, y of rect.
  9074. * @type {string|Array.<number>}
  9075. * @default 'inside'
  9076. */
  9077. textPosition: 'inside',
  9078. /**
  9079. * If not specified, use the boundingRect of a `displayable`.
  9080. * @type {Object}
  9081. */
  9082. textRect: null,
  9083. /**
  9084. * [x, y]
  9085. * @type {Array.<number>}
  9086. */
  9087. textOffset: null,
  9088. /**
  9089. * @type {string}
  9090. */
  9091. textAlign: null,
  9092. /**
  9093. * @type {string}
  9094. */
  9095. textVerticalAlign: null,
  9096. /**
  9097. * @type {number}
  9098. */
  9099. textDistance: 5,
  9100. /**
  9101. * @type {string}
  9102. */
  9103. textShadowColor: 'transparent',
  9104. /**
  9105. * @type {number}
  9106. */
  9107. textShadowBlur: 0,
  9108. /**
  9109. * @type {number}
  9110. */
  9111. textShadowOffsetX: 0,
  9112. /**
  9113. * @type {number}
  9114. */
  9115. textShadowOffsetY: 0,
  9116. /**
  9117. * @type {string}
  9118. */
  9119. textBoxShadowColor: 'transparent',
  9120. /**
  9121. * @type {number}
  9122. */
  9123. textBoxShadowBlur: 0,
  9124. /**
  9125. * @type {number}
  9126. */
  9127. textBoxShadowOffsetX: 0,
  9128. /**
  9129. * @type {number}
  9130. */
  9131. textBoxShadowOffsetY: 0,
  9132. /**
  9133. * Whether transform text.
  9134. * Only useful in Path and Image element
  9135. * @type {boolean}
  9136. */
  9137. transformText: false,
  9138. /**
  9139. * Text rotate around position of Path or Image
  9140. * Only useful in Path and Image element and transformText is false.
  9141. */
  9142. textRotation: 0,
  9143. /**
  9144. * Text origin of text rotation, like [10, 40].
  9145. * Based on x, y of rect.
  9146. * Useful in label rotation of circular symbol.
  9147. * By default, this origin is textPosition.
  9148. * Can be 'center'.
  9149. * @type {string|Array.<number>}
  9150. */
  9151. textOrigin: null,
  9152. /**
  9153. * @type {string}
  9154. */
  9155. textBackgroundColor: null,
  9156. /**
  9157. * @type {string}
  9158. */
  9159. textBorderColor: null,
  9160. /**
  9161. * @type {number}
  9162. */
  9163. textBorderWidth: 0,
  9164. /**
  9165. * @type {number}
  9166. */
  9167. textBorderRadius: 0,
  9168. /**
  9169. * Can be `2` or `[2, 4]` or `[2, 3, 4, 5]`
  9170. * @type {number|Array.<number>}
  9171. */
  9172. textPadding: null,
  9173. /**
  9174. * Text styles for rich text.
  9175. * @type {Object}
  9176. */
  9177. rich: null,
  9178. /**
  9179. * {outerWidth, outerHeight, ellipsis, placeholder}
  9180. * @type {Object}
  9181. */
  9182. truncate: null,
  9183. /**
  9184. * https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/globalCompositeOperation
  9185. * @type {string}
  9186. */
  9187. blend: null,
  9188. /**
  9189. * @param {CanvasRenderingContext2D} ctx
  9190. */
  9191. bind: function (ctx, el, prevEl) {
  9192. var style = this;
  9193. var prevStyle = prevEl && prevEl.style;
  9194. var firstDraw = !prevStyle;
  9195. for (var i = 0; i < STYLE_COMMON_PROPS.length; i++) {
  9196. var prop = STYLE_COMMON_PROPS[i];
  9197. var styleName = prop[0];
  9198. if (firstDraw || style[styleName] !== prevStyle[styleName]) {
  9199. // FIXME Invalid property value will cause style leak from previous element.
  9200. ctx[styleName] = style[styleName] || prop[1];
  9201. }
  9202. }
  9203. if (firstDraw || style.fill !== prevStyle.fill) {
  9204. ctx.fillStyle = style.fill;
  9205. }
  9206. if (firstDraw || style.stroke !== prevStyle.stroke) {
  9207. ctx.strokeStyle = style.stroke;
  9208. }
  9209. if (firstDraw || style.opacity !== prevStyle.opacity) {
  9210. ctx.globalAlpha = style.opacity == null ? 1 : style.opacity;
  9211. }
  9212. if (firstDraw || style.blend !== prevStyle.blend) {
  9213. ctx.globalCompositeOperation = style.blend || 'source-over';
  9214. }
  9215. if (this.hasStroke()) {
  9216. var lineWidth = style.lineWidth;
  9217. ctx.lineWidth = lineWidth / (this.strokeNoScale && el && el.getLineScale ? el.getLineScale() : 1);
  9218. }
  9219. },
  9220. hasFill: function () {
  9221. var fill = this.fill;
  9222. return fill != null && fill !== 'none';
  9223. },
  9224. hasStroke: function () {
  9225. var stroke = this.stroke;
  9226. return stroke != null && stroke !== 'none' && this.lineWidth > 0;
  9227. },
  9228. /**
  9229. * Extend from other style
  9230. * @param {zrender/graphic/Style} otherStyle
  9231. * @param {boolean} overwrite true: overwrirte any way.
  9232. * false: overwrite only when !target.hasOwnProperty
  9233. * others: overwrite when property is not null/undefined.
  9234. */
  9235. extendFrom: function (otherStyle, overwrite) {
  9236. if (otherStyle) {
  9237. for (var name in otherStyle) {
  9238. if (otherStyle.hasOwnProperty(name) && (overwrite === true || (overwrite === false ? !this.hasOwnProperty(name) : otherStyle[name] != null))) {
  9239. this[name] = otherStyle[name];
  9240. }
  9241. }
  9242. }
  9243. },
  9244. /**
  9245. * Batch setting style with a given object
  9246. * @param {Object|string} obj
  9247. * @param {*} [obj]
  9248. */
  9249. set: function (obj, value) {
  9250. if (typeof obj === 'string') {
  9251. this[obj] = value;
  9252. } else {
  9253. this.extendFrom(obj, true);
  9254. }
  9255. },
  9256. /**
  9257. * Clone
  9258. * @return {zrender/graphic/Style} [description]
  9259. */
  9260. clone: function () {
  9261. var newStyle = new this.constructor();
  9262. newStyle.extendFrom(this, true);
  9263. return newStyle;
  9264. },
  9265. getGradient: function (ctx, obj, rect) {
  9266. var method = obj.type === 'radial' ? createRadialGradient : createLinearGradient;
  9267. var canvasGradient = method(ctx, obj, rect);
  9268. var colorStops = obj.colorStops;
  9269. for (var i = 0; i < colorStops.length; i++) {
  9270. canvasGradient.addColorStop(colorStops[i].offset, colorStops[i].color);
  9271. }
  9272. return canvasGradient;
  9273. }
  9274. };
  9275. var styleProto = Style.prototype;
  9276. for (var i = 0; i < STYLE_COMMON_PROPS.length; i++) {
  9277. var prop = STYLE_COMMON_PROPS[i];
  9278. if (!(prop[0] in styleProto)) {
  9279. styleProto[prop[0]] = prop[1];
  9280. }
  9281. } // Provide for others
  9282. Style.getGradient = styleProto.getGradient;
  9283. var _default = Style;
  9284. module.exports = _default;
  9285. /***/ }),
  9286. /* 41 */
  9287. /***/ (function(module, exports) {
  9288. /**
  9289. * zrender: 生成唯一id
  9290. *
  9291. * @author errorrik (errorrik@gmail.com)
  9292. */
  9293. var idStart = 0x0907;
  9294. function _default() {
  9295. return idStart++;
  9296. }
  9297. module.exports = _default;
  9298. /***/ }),
  9299. /* 42 */
  9300. /***/ (function(module, exports) {
  9301. /**
  9302. * 事件扩展
  9303. * @module zrender/mixin/Eventful
  9304. * @author Kener (@Kener-林峰, kener.linfeng@gmail.com)
  9305. * pissang (https://www.github.com/pissang)
  9306. */
  9307. var arrySlice = Array.prototype.slice;
  9308. /**
  9309. * 事件分发器
  9310. * @alias module:zrender/mixin/Eventful
  9311. * @constructor
  9312. */
  9313. var Eventful = function () {
  9314. this._$handlers = {};
  9315. };
  9316. Eventful.prototype = {
  9317. constructor: Eventful,
  9318. /**
  9319. * 单次触发绑定,trigger后销毁
  9320. *
  9321. * @param {string} event 事件名
  9322. * @param {Function} handler 响应函数
  9323. * @param {Object} context
  9324. */
  9325. one: function (event, handler, context) {
  9326. var _h = this._$handlers;
  9327. if (!handler || !event) {
  9328. return this;
  9329. }
  9330. if (!_h[event]) {
  9331. _h[event] = [];
  9332. }
  9333. for (var i = 0; i < _h[event].length; i++) {
  9334. if (_h[event][i].h === handler) {
  9335. return this;
  9336. }
  9337. }
  9338. _h[event].push({
  9339. h: handler,
  9340. one: true,
  9341. ctx: context || this
  9342. });
  9343. return this;
  9344. },
  9345. /**
  9346. * 绑定事件
  9347. * @param {string} event 事件名
  9348. * @param {Function} handler 事件处理函数
  9349. * @param {Object} [context]
  9350. */
  9351. on: function (event, handler, context) {
  9352. var _h = this._$handlers;
  9353. if (!handler || !event) {
  9354. return this;
  9355. }
  9356. if (!_h[event]) {
  9357. _h[event] = [];
  9358. }
  9359. for (var i = 0; i < _h[event].length; i++) {
  9360. if (_h[event][i].h === handler) {
  9361. return this;
  9362. }
  9363. }
  9364. _h[event].push({
  9365. h: handler,
  9366. one: false,
  9367. ctx: context || this
  9368. });
  9369. return this;
  9370. },
  9371. /**
  9372. * 是否绑定了事件
  9373. * @param {string} event
  9374. * @return {boolean}
  9375. */
  9376. isSilent: function (event) {
  9377. var _h = this._$handlers;
  9378. return _h[event] && _h[event].length;
  9379. },
  9380. /**
  9381. * 解绑事件
  9382. * @param {string} event 事件名
  9383. * @param {Function} [handler] 事件处理函数
  9384. */
  9385. off: function (event, handler) {
  9386. var _h = this._$handlers;
  9387. if (!event) {
  9388. this._$handlers = {};
  9389. return this;
  9390. }
  9391. if (handler) {
  9392. if (_h[event]) {
  9393. var newList = [];
  9394. for (var i = 0, l = _h[event].length; i < l; i++) {
  9395. if (_h[event][i]['h'] != handler) {
  9396. newList.push(_h[event][i]);
  9397. }
  9398. }
  9399. _h[event] = newList;
  9400. }
  9401. if (_h[event] && _h[event].length === 0) {
  9402. delete _h[event];
  9403. }
  9404. } else {
  9405. delete _h[event];
  9406. }
  9407. return this;
  9408. },
  9409. /**
  9410. * 事件分发
  9411. *
  9412. * @param {string} type 事件类型
  9413. */
  9414. trigger: function (type) {
  9415. if (this._$handlers[type]) {
  9416. var args = arguments;
  9417. var argLen = args.length;
  9418. if (argLen > 3) {
  9419. args = arrySlice.call(args, 1);
  9420. }
  9421. var _h = this._$handlers[type];
  9422. var len = _h.length;
  9423. for (var i = 0; i < len;) {
  9424. // Optimize advise from backbone
  9425. switch (argLen) {
  9426. case 1:
  9427. _h[i]['h'].call(_h[i]['ctx']);
  9428. break;
  9429. case 2:
  9430. _h[i]['h'].call(_h[i]['ctx'], args[1]);
  9431. break;
  9432. case 3:
  9433. _h[i]['h'].call(_h[i]['ctx'], args[1], args[2]);
  9434. break;
  9435. default:
  9436. // have more than 2 given arguments
  9437. _h[i]['h'].apply(_h[i]['ctx'], args);
  9438. break;
  9439. }
  9440. if (_h[i]['one']) {
  9441. _h.splice(i, 1);
  9442. len--;
  9443. } else {
  9444. i++;
  9445. }
  9446. }
  9447. }
  9448. return this;
  9449. },
  9450. /**
  9451. * 带有context的事件分发, 最后一个参数是事件回调的context
  9452. * @param {string} type 事件类型
  9453. */
  9454. triggerWithContext: function (type) {
  9455. if (this._$handlers[type]) {
  9456. var args = arguments;
  9457. var argLen = args.length;
  9458. if (argLen > 4) {
  9459. args = arrySlice.call(args, 1, args.length - 1);
  9460. }
  9461. var ctx = args[args.length - 1];
  9462. var _h = this._$handlers[type];
  9463. var len = _h.length;
  9464. for (var i = 0; i < len;) {
  9465. // Optimize advise from backbone
  9466. switch (argLen) {
  9467. case 1:
  9468. _h[i]['h'].call(ctx);
  9469. break;
  9470. case 2:
  9471. _h[i]['h'].call(ctx, args[1]);
  9472. break;
  9473. case 3:
  9474. _h[i]['h'].call(ctx, args[1], args[2]);
  9475. break;
  9476. default:
  9477. // have more than 2 given arguments
  9478. _h[i]['h'].apply(ctx, args);
  9479. break;
  9480. }
  9481. if (_h[i]['one']) {
  9482. _h.splice(i, 1);
  9483. len--;
  9484. } else {
  9485. i++;
  9486. }
  9487. }
  9488. }
  9489. return this;
  9490. }
  9491. }; // 对象可以通过 onxxxx 绑定事件
  9492. /**
  9493. * @event module:zrender/mixin/Eventful#onclick
  9494. * @type {Function}
  9495. * @default null
  9496. */
  9497. /**
  9498. * @event module:zrender/mixin/Eventful#onmouseover
  9499. * @type {Function}
  9500. * @default null
  9501. */
  9502. /**
  9503. * @event module:zrender/mixin/Eventful#onmouseout
  9504. * @type {Function}
  9505. * @default null
  9506. */
  9507. /**
  9508. * @event module:zrender/mixin/Eventful#onmousemove
  9509. * @type {Function}
  9510. * @default null
  9511. */
  9512. /**
  9513. * @event module:zrender/mixin/Eventful#onmousewheel
  9514. * @type {Function}
  9515. * @default null
  9516. */
  9517. /**
  9518. * @event module:zrender/mixin/Eventful#onmousedown
  9519. * @type {Function}
  9520. * @default null
  9521. */
  9522. /**
  9523. * @event module:zrender/mixin/Eventful#onmouseup
  9524. * @type {Function}
  9525. * @default null
  9526. */
  9527. /**
  9528. * @event module:zrender/mixin/Eventful#ondrag
  9529. * @type {Function}
  9530. * @default null
  9531. */
  9532. /**
  9533. * @event module:zrender/mixin/Eventful#ondragstart
  9534. * @type {Function}
  9535. * @default null
  9536. */
  9537. /**
  9538. * @event module:zrender/mixin/Eventful#ondragend
  9539. * @type {Function}
  9540. * @default null
  9541. */
  9542. /**
  9543. * @event module:zrender/mixin/Eventful#ondragenter
  9544. * @type {Function}
  9545. * @default null
  9546. */
  9547. /**
  9548. * @event module:zrender/mixin/Eventful#ondragleave
  9549. * @type {Function}
  9550. * @default null
  9551. */
  9552. /**
  9553. * @event module:zrender/mixin/Eventful#ondragover
  9554. * @type {Function}
  9555. * @default null
  9556. */
  9557. /**
  9558. * @event module:zrender/mixin/Eventful#ondrop
  9559. * @type {Function}
  9560. * @default null
  9561. */
  9562. var _default = Eventful;
  9563. module.exports = _default;
  9564. /***/ }),
  9565. /* 43 */
  9566. /***/ (function(module, exports, __webpack_require__) {
  9567. var Animator = __webpack_require__(44);
  9568. var log = __webpack_require__(47);
  9569. var _util = __webpack_require__(0);
  9570. var isString = _util.isString;
  9571. var isFunction = _util.isFunction;
  9572. var isObject = _util.isObject;
  9573. var isArrayLike = _util.isArrayLike;
  9574. var indexOf = _util.indexOf;
  9575. /**
  9576. * @alias modue:zrender/mixin/Animatable
  9577. * @constructor
  9578. */
  9579. var Animatable = function () {
  9580. /**
  9581. * @type {Array.<module:zrender/animation/Animator>}
  9582. * @readOnly
  9583. */
  9584. this.animators = [];
  9585. };
  9586. Animatable.prototype = {
  9587. constructor: Animatable,
  9588. /**
  9589. * 动画
  9590. *
  9591. * @param {string} path The path to fetch value from object, like 'a.b.c'.
  9592. * @param {boolean} [loop] Whether to loop animation.
  9593. * @return {module:zrender/animation/Animator}
  9594. * @example:
  9595. * el.animate('style', false)
  9596. * .when(1000, {x: 10} )
  9597. * .done(function(){ // Animation done })
  9598. * .start()
  9599. */
  9600. animate: function (path, loop) {
  9601. var target;
  9602. var animatingShape = false;
  9603. var el = this;
  9604. var zr = this.__zr;
  9605. if (path) {
  9606. var pathSplitted = path.split('.');
  9607. var prop = el; // If animating shape
  9608. animatingShape = pathSplitted[0] === 'shape';
  9609. for (var i = 0, l = pathSplitted.length; i < l; i++) {
  9610. if (!prop) {
  9611. continue;
  9612. }
  9613. prop = prop[pathSplitted[i]];
  9614. }
  9615. if (prop) {
  9616. target = prop;
  9617. }
  9618. } else {
  9619. target = el;
  9620. }
  9621. if (!target) {
  9622. log('Property "' + path + '" is not existed in element ' + el.id);
  9623. return;
  9624. }
  9625. var animators = el.animators;
  9626. var animator = new Animator(target, loop);
  9627. animator.during(function (target) {
  9628. el.dirty(animatingShape);
  9629. }).done(function () {
  9630. // FIXME Animator will not be removed if use `Animator#stop` to stop animation
  9631. animators.splice(indexOf(animators, animator), 1);
  9632. });
  9633. animators.push(animator); // If animate after added to the zrender
  9634. if (zr) {
  9635. zr.animation.addAnimator(animator);
  9636. }
  9637. return animator;
  9638. },
  9639. /**
  9640. * 停止动画
  9641. * @param {boolean} forwardToLast If move to last frame before stop
  9642. */
  9643. stopAnimation: function (forwardToLast) {
  9644. var animators = this.animators;
  9645. var len = animators.length;
  9646. for (var i = 0; i < len; i++) {
  9647. animators[i].stop(forwardToLast);
  9648. }
  9649. animators.length = 0;
  9650. return this;
  9651. },
  9652. /**
  9653. * Caution: this method will stop previous animation.
  9654. * So do not use this method to one element twice before
  9655. * animation starts, unless you know what you are doing.
  9656. * @param {Object} target
  9657. * @param {number} [time=500] Time in ms
  9658. * @param {string} [easing='linear']
  9659. * @param {number} [delay=0]
  9660. * @param {Function} [callback]
  9661. * @param {Function} [forceAnimate] Prevent stop animation and callback
  9662. * immediently when target values are the same as current values.
  9663. *
  9664. * @example
  9665. * // Animate position
  9666. * el.animateTo({
  9667. * position: [10, 10]
  9668. * }, function () { // done })
  9669. *
  9670. * // Animate shape, style and position in 100ms, delayed 100ms, with cubicOut easing
  9671. * el.animateTo({
  9672. * shape: {
  9673. * width: 500
  9674. * },
  9675. * style: {
  9676. * fill: 'red'
  9677. * }
  9678. * position: [10, 10]
  9679. * }, 100, 100, 'cubicOut', function () { // done })
  9680. */
  9681. // TODO Return animation key
  9682. animateTo: function (target, time, delay, easing, callback, forceAnimate) {
  9683. // animateTo(target, time, easing, callback);
  9684. if (isString(delay)) {
  9685. callback = easing;
  9686. easing = delay;
  9687. delay = 0;
  9688. } // animateTo(target, time, delay, callback);
  9689. else if (isFunction(easing)) {
  9690. callback = easing;
  9691. easing = 'linear';
  9692. delay = 0;
  9693. } // animateTo(target, time, callback);
  9694. else if (isFunction(delay)) {
  9695. callback = delay;
  9696. delay = 0;
  9697. } // animateTo(target, callback)
  9698. else if (isFunction(time)) {
  9699. callback = time;
  9700. time = 500;
  9701. } // animateTo(target)
  9702. else if (!time) {
  9703. time = 500;
  9704. } // Stop all previous animations
  9705. this.stopAnimation();
  9706. this._animateToShallow('', this, target, time, delay); // Animators may be removed immediately after start
  9707. // if there is nothing to animate
  9708. var animators = this.animators.slice();
  9709. var count = animators.length;
  9710. function done() {
  9711. count--;
  9712. if (!count) {
  9713. callback && callback();
  9714. }
  9715. } // No animators. This should be checked before animators[i].start(),
  9716. // because 'done' may be executed immediately if no need to animate.
  9717. if (!count) {
  9718. callback && callback();
  9719. } // Start after all animators created
  9720. // Incase any animator is done immediately when all animation properties are not changed
  9721. for (var i = 0; i < animators.length; i++) {
  9722. animators[i].done(done).start(easing, forceAnimate);
  9723. }
  9724. },
  9725. /**
  9726. * @private
  9727. * @param {string} path=''
  9728. * @param {Object} source=this
  9729. * @param {Object} target
  9730. * @param {number} [time=500]
  9731. * @param {number} [delay=0]
  9732. *
  9733. * @example
  9734. * // Animate position
  9735. * el._animateToShallow({
  9736. * position: [10, 10]
  9737. * })
  9738. *
  9739. * // Animate shape, style and position in 100ms, delayed 100ms
  9740. * el._animateToShallow({
  9741. * shape: {
  9742. * width: 500
  9743. * },
  9744. * style: {
  9745. * fill: 'red'
  9746. * }
  9747. * position: [10, 10]
  9748. * }, 100, 100)
  9749. */
  9750. _animateToShallow: function (path, source, target, time, delay) {
  9751. var objShallow = {};
  9752. var propertyCount = 0;
  9753. for (var name in target) {
  9754. if (!target.hasOwnProperty(name)) {
  9755. continue;
  9756. }
  9757. if (source[name] != null) {
  9758. if (isObject(target[name]) && !isArrayLike(target[name])) {
  9759. this._animateToShallow(path ? path + '.' + name : name, source[name], target[name], time, delay);
  9760. } else {
  9761. objShallow[name] = target[name];
  9762. propertyCount++;
  9763. }
  9764. } else if (target[name] != null) {
  9765. // Attr directly if not has property
  9766. // FIXME, if some property not needed for element ?
  9767. if (!path) {
  9768. this.attr(name, target[name]);
  9769. } else {
  9770. // Shape or style
  9771. var props = {};
  9772. props[path] = {};
  9773. props[path][name] = target[name];
  9774. this.attr(props);
  9775. }
  9776. }
  9777. }
  9778. if (propertyCount > 0) {
  9779. this.animate(path, false).when(time == null ? 500 : time, objShallow).delay(delay || 0);
  9780. }
  9781. return this;
  9782. }
  9783. };
  9784. var _default = Animatable;
  9785. module.exports = _default;
  9786. /***/ }),
  9787. /* 44 */
  9788. /***/ (function(module, exports, __webpack_require__) {
  9789. var Clip = __webpack_require__(45);
  9790. var color = __webpack_require__(18);
  9791. var _util = __webpack_require__(0);
  9792. var isArrayLike = _util.isArrayLike;
  9793. /**
  9794. * @module echarts/animation/Animator
  9795. */
  9796. var arraySlice = Array.prototype.slice;
  9797. function defaultGetter(target, key) {
  9798. return target[key];
  9799. }
  9800. function defaultSetter(target, key, value) {
  9801. target[key] = value;
  9802. }
  9803. /**
  9804. * @param {number} p0
  9805. * @param {number} p1
  9806. * @param {number} percent
  9807. * @return {number}
  9808. */
  9809. function interpolateNumber(p0, p1, percent) {
  9810. return (p1 - p0) * percent + p0;
  9811. }
  9812. /**
  9813. * @param {string} p0
  9814. * @param {string} p1
  9815. * @param {number} percent
  9816. * @return {string}
  9817. */
  9818. function interpolateString(p0, p1, percent) {
  9819. return percent > 0.5 ? p1 : p0;
  9820. }
  9821. /**
  9822. * @param {Array} p0
  9823. * @param {Array} p1
  9824. * @param {number} percent
  9825. * @param {Array} out
  9826. * @param {number} arrDim
  9827. */
  9828. function interpolateArray(p0, p1, percent, out, arrDim) {
  9829. var len = p0.length;
  9830. if (arrDim == 1) {
  9831. for (var i = 0; i < len; i++) {
  9832. out[i] = interpolateNumber(p0[i], p1[i], percent);
  9833. }
  9834. } else {
  9835. var len2 = len && p0[0].length;
  9836. for (var i = 0; i < len; i++) {
  9837. for (var j = 0; j < len2; j++) {
  9838. out[i][j] = interpolateNumber(p0[i][j], p1[i][j], percent);
  9839. }
  9840. }
  9841. }
  9842. } // arr0 is source array, arr1 is target array.
  9843. // Do some preprocess to avoid error happened when interpolating from arr0 to arr1
  9844. function fillArr(arr0, arr1, arrDim) {
  9845. var arr0Len = arr0.length;
  9846. var arr1Len = arr1.length;
  9847. if (arr0Len !== arr1Len) {
  9848. // FIXME Not work for TypedArray
  9849. var isPreviousLarger = arr0Len > arr1Len;
  9850. if (isPreviousLarger) {
  9851. // Cut the previous
  9852. arr0.length = arr1Len;
  9853. } else {
  9854. // Fill the previous
  9855. for (var i = arr0Len; i < arr1Len; i++) {
  9856. arr0.push(arrDim === 1 ? arr1[i] : arraySlice.call(arr1[i]));
  9857. }
  9858. }
  9859. } // Handling NaN value
  9860. var len2 = arr0[0] && arr0[0].length;
  9861. for (var i = 0; i < arr0.length; i++) {
  9862. if (arrDim === 1) {
  9863. if (isNaN(arr0[i])) {
  9864. arr0[i] = arr1[i];
  9865. }
  9866. } else {
  9867. for (var j = 0; j < len2; j++) {
  9868. if (isNaN(arr0[i][j])) {
  9869. arr0[i][j] = arr1[i][j];
  9870. }
  9871. }
  9872. }
  9873. }
  9874. }
  9875. /**
  9876. * @param {Array} arr0
  9877. * @param {Array} arr1
  9878. * @param {number} arrDim
  9879. * @return {boolean}
  9880. */
  9881. function isArraySame(arr0, arr1, arrDim) {
  9882. if (arr0 === arr1) {
  9883. return true;
  9884. }
  9885. var len = arr0.length;
  9886. if (len !== arr1.length) {
  9887. return false;
  9888. }
  9889. if (arrDim === 1) {
  9890. for (var i = 0; i < len; i++) {
  9891. if (arr0[i] !== arr1[i]) {
  9892. return false;
  9893. }
  9894. }
  9895. } else {
  9896. var len2 = arr0[0].length;
  9897. for (var i = 0; i < len; i++) {
  9898. for (var j = 0; j < len2; j++) {
  9899. if (arr0[i][j] !== arr1[i][j]) {
  9900. return false;
  9901. }
  9902. }
  9903. }
  9904. }
  9905. return true;
  9906. }
  9907. /**
  9908. * Catmull Rom interpolate array
  9909. * @param {Array} p0
  9910. * @param {Array} p1
  9911. * @param {Array} p2
  9912. * @param {Array} p3
  9913. * @param {number} t
  9914. * @param {number} t2
  9915. * @param {number} t3
  9916. * @param {Array} out
  9917. * @param {number} arrDim
  9918. */
  9919. function catmullRomInterpolateArray(p0, p1, p2, p3, t, t2, t3, out, arrDim) {
  9920. var len = p0.length;
  9921. if (arrDim == 1) {
  9922. for (var i = 0; i < len; i++) {
  9923. out[i] = catmullRomInterpolate(p0[i], p1[i], p2[i], p3[i], t, t2, t3);
  9924. }
  9925. } else {
  9926. var len2 = p0[0].length;
  9927. for (var i = 0; i < len; i++) {
  9928. for (var j = 0; j < len2; j++) {
  9929. out[i][j] = catmullRomInterpolate(p0[i][j], p1[i][j], p2[i][j], p3[i][j], t, t2, t3);
  9930. }
  9931. }
  9932. }
  9933. }
  9934. /**
  9935. * Catmull Rom interpolate number
  9936. * @param {number} p0
  9937. * @param {number} p1
  9938. * @param {number} p2
  9939. * @param {number} p3
  9940. * @param {number} t
  9941. * @param {number} t2
  9942. * @param {number} t3
  9943. * @return {number}
  9944. */
  9945. function catmullRomInterpolate(p0, p1, p2, p3, t, t2, t3) {
  9946. var v0 = (p2 - p0) * 0.5;
  9947. var v1 = (p3 - p1) * 0.5;
  9948. return (2 * (p1 - p2) + v0 + v1) * t3 + (-3 * (p1 - p2) - 2 * v0 - v1) * t2 + v0 * t + p1;
  9949. }
  9950. function cloneValue(value) {
  9951. if (isArrayLike(value)) {
  9952. var len = value.length;
  9953. if (isArrayLike(value[0])) {
  9954. var ret = [];
  9955. for (var i = 0; i < len; i++) {
  9956. ret.push(arraySlice.call(value[i]));
  9957. }
  9958. return ret;
  9959. }
  9960. return arraySlice.call(value);
  9961. }
  9962. return value;
  9963. }
  9964. function rgba2String(rgba) {
  9965. rgba[0] = Math.floor(rgba[0]);
  9966. rgba[1] = Math.floor(rgba[1]);
  9967. rgba[2] = Math.floor(rgba[2]);
  9968. return 'rgba(' + rgba.join(',') + ')';
  9969. }
  9970. function getArrayDim(keyframes) {
  9971. var lastValue = keyframes[keyframes.length - 1].value;
  9972. return isArrayLike(lastValue && lastValue[0]) ? 2 : 1;
  9973. }
  9974. function createTrackClip(animator, easing, oneTrackDone, keyframes, propName, forceAnimate) {
  9975. var getter = animator._getter;
  9976. var setter = animator._setter;
  9977. var useSpline = easing === 'spline';
  9978. var trackLen = keyframes.length;
  9979. if (!trackLen) {
  9980. return;
  9981. } // Guess data type
  9982. var firstVal = keyframes[0].value;
  9983. var isValueArray = isArrayLike(firstVal);
  9984. var isValueColor = false;
  9985. var isValueString = false; // For vertices morphing
  9986. var arrDim = isValueArray ? getArrayDim(keyframes) : 0;
  9987. var trackMaxTime; // Sort keyframe as ascending
  9988. keyframes.sort(function (a, b) {
  9989. return a.time - b.time;
  9990. });
  9991. trackMaxTime = keyframes[trackLen - 1].time; // Percents of each keyframe
  9992. var kfPercents = []; // Value of each keyframe
  9993. var kfValues = [];
  9994. var prevValue = keyframes[0].value;
  9995. var isAllValueEqual = true;
  9996. for (var i = 0; i < trackLen; i++) {
  9997. kfPercents.push(keyframes[i].time / trackMaxTime); // Assume value is a color when it is a string
  9998. var value = keyframes[i].value; // Check if value is equal, deep check if value is array
  9999. if (!(isValueArray && isArraySame(value, prevValue, arrDim) || !isValueArray && value === prevValue)) {
  10000. isAllValueEqual = false;
  10001. }
  10002. prevValue = value; // Try converting a string to a color array
  10003. if (typeof value == 'string') {
  10004. var colorArray = color.parse(value);
  10005. if (colorArray) {
  10006. value = colorArray;
  10007. isValueColor = true;
  10008. } else {
  10009. isValueString = true;
  10010. }
  10011. }
  10012. kfValues.push(value);
  10013. }
  10014. if (!forceAnimate && isAllValueEqual) {
  10015. return;
  10016. }
  10017. var lastValue = kfValues[trackLen - 1]; // Polyfill array and NaN value
  10018. for (var i = 0; i < trackLen - 1; i++) {
  10019. if (isValueArray) {
  10020. fillArr(kfValues[i], lastValue, arrDim);
  10021. } else {
  10022. if (isNaN(kfValues[i]) && !isNaN(lastValue) && !isValueString && !isValueColor) {
  10023. kfValues[i] = lastValue;
  10024. }
  10025. }
  10026. }
  10027. isValueArray && fillArr(getter(animator._target, propName), lastValue, arrDim); // Cache the key of last frame to speed up when
  10028. // animation playback is sequency
  10029. var lastFrame = 0;
  10030. var lastFramePercent = 0;
  10031. var start;
  10032. var w;
  10033. var p0;
  10034. var p1;
  10035. var p2;
  10036. var p3;
  10037. if (isValueColor) {
  10038. var rgba = [0, 0, 0, 0];
  10039. }
  10040. var onframe = function (target, percent) {
  10041. // Find the range keyframes
  10042. // kf1-----kf2---------current--------kf3
  10043. // find kf2 and kf3 and do interpolation
  10044. var frame; // In the easing function like elasticOut, percent may less than 0
  10045. if (percent < 0) {
  10046. frame = 0;
  10047. } else if (percent < lastFramePercent) {
  10048. // Start from next key
  10049. // PENDING start from lastFrame ?
  10050. start = Math.min(lastFrame + 1, trackLen - 1);
  10051. for (frame = start; frame >= 0; frame--) {
  10052. if (kfPercents[frame] <= percent) {
  10053. break;
  10054. }
  10055. } // PENDING really need to do this ?
  10056. frame = Math.min(frame, trackLen - 2);
  10057. } else {
  10058. for (frame = lastFrame; frame < trackLen; frame++) {
  10059. if (kfPercents[frame] > percent) {
  10060. break;
  10061. }
  10062. }
  10063. frame = Math.min(frame - 1, trackLen - 2);
  10064. }
  10065. lastFrame = frame;
  10066. lastFramePercent = percent;
  10067. var range = kfPercents[frame + 1] - kfPercents[frame];
  10068. if (range === 0) {
  10069. return;
  10070. } else {
  10071. w = (percent - kfPercents[frame]) / range;
  10072. }
  10073. if (useSpline) {
  10074. p1 = kfValues[frame];
  10075. p0 = kfValues[frame === 0 ? frame : frame - 1];
  10076. p2 = kfValues[frame > trackLen - 2 ? trackLen - 1 : frame + 1];
  10077. p3 = kfValues[frame > trackLen - 3 ? trackLen - 1 : frame + 2];
  10078. if (isValueArray) {
  10079. catmullRomInterpolateArray(p0, p1, p2, p3, w, w * w, w * w * w, getter(target, propName), arrDim);
  10080. } else {
  10081. var value;
  10082. if (isValueColor) {
  10083. value = catmullRomInterpolateArray(p0, p1, p2, p3, w, w * w, w * w * w, rgba, 1);
  10084. value = rgba2String(rgba);
  10085. } else if (isValueString) {
  10086. // String is step(0.5)
  10087. return interpolateString(p1, p2, w);
  10088. } else {
  10089. value = catmullRomInterpolate(p0, p1, p2, p3, w, w * w, w * w * w);
  10090. }
  10091. setter(target, propName, value);
  10092. }
  10093. } else {
  10094. if (isValueArray) {
  10095. interpolateArray(kfValues[frame], kfValues[frame + 1], w, getter(target, propName), arrDim);
  10096. } else {
  10097. var value;
  10098. if (isValueColor) {
  10099. interpolateArray(kfValues[frame], kfValues[frame + 1], w, rgba, 1);
  10100. value = rgba2String(rgba);
  10101. } else if (isValueString) {
  10102. // String is step(0.5)
  10103. return interpolateString(kfValues[frame], kfValues[frame + 1], w);
  10104. } else {
  10105. value = interpolateNumber(kfValues[frame], kfValues[frame + 1], w);
  10106. }
  10107. setter(target, propName, value);
  10108. }
  10109. }
  10110. };
  10111. var clip = new Clip({
  10112. target: animator._target,
  10113. life: trackMaxTime,
  10114. loop: animator._loop,
  10115. delay: animator._delay,
  10116. onframe: onframe,
  10117. ondestroy: oneTrackDone
  10118. });
  10119. if (easing && easing !== 'spline') {
  10120. clip.easing = easing;
  10121. }
  10122. return clip;
  10123. }
  10124. /**
  10125. * @alias module:zrender/animation/Animator
  10126. * @constructor
  10127. * @param {Object} target
  10128. * @param {boolean} loop
  10129. * @param {Function} getter
  10130. * @param {Function} setter
  10131. */
  10132. var Animator = function (target, loop, getter, setter) {
  10133. this._tracks = {};
  10134. this._target = target;
  10135. this._loop = loop || false;
  10136. this._getter = getter || defaultGetter;
  10137. this._setter = setter || defaultSetter;
  10138. this._clipCount = 0;
  10139. this._delay = 0;
  10140. this._doneList = [];
  10141. this._onframeList = [];
  10142. this._clipList = [];
  10143. };
  10144. Animator.prototype = {
  10145. /**
  10146. * 设置动画关键帧
  10147. * @param {number} time 关键帧时间,单位是ms
  10148. * @param {Object} props 关键帧的属性值,key-value表示
  10149. * @return {module:zrender/animation/Animator}
  10150. */
  10151. when: function (time
  10152. /* ms */
  10153. , props) {
  10154. var tracks = this._tracks;
  10155. for (var propName in props) {
  10156. if (!props.hasOwnProperty(propName)) {
  10157. continue;
  10158. }
  10159. if (!tracks[propName]) {
  10160. tracks[propName] = []; // Invalid value
  10161. var value = this._getter(this._target, propName);
  10162. if (value == null) {
  10163. // zrLog('Invalid property ' + propName);
  10164. continue;
  10165. } // If time is 0
  10166. // Then props is given initialize value
  10167. // Else
  10168. // Initialize value from current prop value
  10169. if (time !== 0) {
  10170. tracks[propName].push({
  10171. time: 0,
  10172. value: cloneValue(value)
  10173. });
  10174. }
  10175. }
  10176. tracks[propName].push({
  10177. time: time,
  10178. value: props[propName]
  10179. });
  10180. }
  10181. return this;
  10182. },
  10183. /**
  10184. * 添加动画每一帧的回调函数
  10185. * @param {Function} callback
  10186. * @return {module:zrender/animation/Animator}
  10187. */
  10188. during: function (callback) {
  10189. this._onframeList.push(callback);
  10190. return this;
  10191. },
  10192. pause: function () {
  10193. for (var i = 0; i < this._clipList.length; i++) {
  10194. this._clipList[i].pause();
  10195. }
  10196. this._paused = true;
  10197. },
  10198. resume: function () {
  10199. for (var i = 0; i < this._clipList.length; i++) {
  10200. this._clipList[i].resume();
  10201. }
  10202. this._paused = false;
  10203. },
  10204. isPaused: function () {
  10205. return !!this._paused;
  10206. },
  10207. _doneCallback: function () {
  10208. // Clear all tracks
  10209. this._tracks = {}; // Clear all clips
  10210. this._clipList.length = 0;
  10211. var doneList = this._doneList;
  10212. var len = doneList.length;
  10213. for (var i = 0; i < len; i++) {
  10214. doneList[i].call(this);
  10215. }
  10216. },
  10217. /**
  10218. * 开始执行动画
  10219. * @param {string|Function} [easing]
  10220. * 动画缓动函数,详见{@link module:zrender/animation/easing}
  10221. * @param {boolean} forceAnimate
  10222. * @return {module:zrender/animation/Animator}
  10223. */
  10224. start: function (easing, forceAnimate) {
  10225. var self = this;
  10226. var clipCount = 0;
  10227. var oneTrackDone = function () {
  10228. clipCount--;
  10229. if (!clipCount) {
  10230. self._doneCallback();
  10231. }
  10232. };
  10233. var lastClip;
  10234. for (var propName in this._tracks) {
  10235. if (!this._tracks.hasOwnProperty(propName)) {
  10236. continue;
  10237. }
  10238. var clip = createTrackClip(this, easing, oneTrackDone, this._tracks[propName], propName, forceAnimate);
  10239. if (clip) {
  10240. this._clipList.push(clip);
  10241. clipCount++; // If start after added to animation
  10242. if (this.animation) {
  10243. this.animation.addClip(clip);
  10244. }
  10245. lastClip = clip;
  10246. }
  10247. } // Add during callback on the last clip
  10248. if (lastClip) {
  10249. var oldOnFrame = lastClip.onframe;
  10250. lastClip.onframe = function (target, percent) {
  10251. oldOnFrame(target, percent);
  10252. for (var i = 0; i < self._onframeList.length; i++) {
  10253. self._onframeList[i](target, percent);
  10254. }
  10255. };
  10256. } // This optimization will help the case that in the upper application
  10257. // the view may be refreshed frequently, where animation will be
  10258. // called repeatly but nothing changed.
  10259. if (!clipCount) {
  10260. this._doneCallback();
  10261. }
  10262. return this;
  10263. },
  10264. /**
  10265. * 停止动画
  10266. * @param {boolean} forwardToLast If move to last frame before stop
  10267. */
  10268. stop: function (forwardToLast) {
  10269. var clipList = this._clipList;
  10270. var animation = this.animation;
  10271. for (var i = 0; i < clipList.length; i++) {
  10272. var clip = clipList[i];
  10273. if (forwardToLast) {
  10274. // Move to last frame before stop
  10275. clip.onframe(this._target, 1);
  10276. }
  10277. animation && animation.removeClip(clip);
  10278. }
  10279. clipList.length = 0;
  10280. },
  10281. /**
  10282. * 设置动画延迟开始的时间
  10283. * @param {number} time 单位ms
  10284. * @return {module:zrender/animation/Animator}
  10285. */
  10286. delay: function (time) {
  10287. this._delay = time;
  10288. return this;
  10289. },
  10290. /**
  10291. * 添加动画结束的回调
  10292. * @param {Function} cb
  10293. * @return {module:zrender/animation/Animator}
  10294. */
  10295. done: function (cb) {
  10296. if (cb) {
  10297. this._doneList.push(cb);
  10298. }
  10299. return this;
  10300. },
  10301. /**
  10302. * @return {Array.<module:zrender/animation/Clip>}
  10303. */
  10304. getClips: function () {
  10305. return this._clipList;
  10306. }
  10307. };
  10308. var _default = Animator;
  10309. module.exports = _default;
  10310. /***/ }),
  10311. /* 45 */
  10312. /***/ (function(module, exports, __webpack_require__) {
  10313. var easingFuncs = __webpack_require__(46);
  10314. /**
  10315. * 动画主控制器
  10316. * @config target 动画对象,可以是数组,如果是数组的话会批量分发onframe等事件
  10317. * @config life(1000) 动画时长
  10318. * @config delay(0) 动画延迟时间
  10319. * @config loop(true)
  10320. * @config gap(0) 循环的间隔时间
  10321. * @config onframe
  10322. * @config easing(optional)
  10323. * @config ondestroy(optional)
  10324. * @config onrestart(optional)
  10325. *
  10326. * TODO pause
  10327. */
  10328. function Clip(options) {
  10329. this._target = options.target; // 生命周期
  10330. this._life = options.life || 1000; // 延时
  10331. this._delay = options.delay || 0; // 开始时间
  10332. // this._startTime = new Date().getTime() + this._delay;// 单位毫秒
  10333. this._initialized = false; // 是否循环
  10334. this.loop = options.loop == null ? false : options.loop;
  10335. this.gap = options.gap || 0;
  10336. this.easing = options.easing || 'Linear';
  10337. this.onframe = options.onframe;
  10338. this.ondestroy = options.ondestroy;
  10339. this.onrestart = options.onrestart;
  10340. this._pausedTime = 0;
  10341. this._paused = false;
  10342. }
  10343. Clip.prototype = {
  10344. constructor: Clip,
  10345. step: function (globalTime, deltaTime) {
  10346. // Set startTime on first step, or _startTime may has milleseconds different between clips
  10347. // PENDING
  10348. if (!this._initialized) {
  10349. this._startTime = globalTime + this._delay;
  10350. this._initialized = true;
  10351. }
  10352. if (this._paused) {
  10353. this._pausedTime += deltaTime;
  10354. return;
  10355. }
  10356. var percent = (globalTime - this._startTime - this._pausedTime) / this._life; // 还没开始
  10357. if (percent < 0) {
  10358. return;
  10359. }
  10360. percent = Math.min(percent, 1);
  10361. var easing = this.easing;
  10362. var easingFunc = typeof easing == 'string' ? easingFuncs[easing] : easing;
  10363. var schedule = typeof easingFunc === 'function' ? easingFunc(percent) : percent;
  10364. this.fire('frame', schedule); // 结束
  10365. if (percent == 1) {
  10366. if (this.loop) {
  10367. this.restart(globalTime); // 重新开始周期
  10368. // 抛出而不是直接调用事件直到 stage.update 后再统一调用这些事件
  10369. return 'restart';
  10370. } // 动画完成将这个控制器标识为待删除
  10371. // 在Animation.update中进行批量删除
  10372. this._needsRemove = true;
  10373. return 'destroy';
  10374. }
  10375. return null;
  10376. },
  10377. restart: function (globalTime) {
  10378. var remainder = (globalTime - this._startTime - this._pausedTime) % this._life;
  10379. this._startTime = globalTime - remainder + this.gap;
  10380. this._pausedTime = 0;
  10381. this._needsRemove = false;
  10382. },
  10383. fire: function (eventType, arg) {
  10384. eventType = 'on' + eventType;
  10385. if (this[eventType]) {
  10386. this[eventType](this._target, arg);
  10387. }
  10388. },
  10389. pause: function () {
  10390. this._paused = true;
  10391. },
  10392. resume: function () {
  10393. this._paused = false;
  10394. }
  10395. };
  10396. var _default = Clip;
  10397. module.exports = _default;
  10398. /***/ }),
  10399. /* 46 */
  10400. /***/ (function(module, exports) {
  10401. /**
  10402. * 缓动代码来自 https://github.com/sole/tween.js/blob/master/src/Tween.js
  10403. * @see http://sole.github.io/tween.js/examples/03_graphs.html
  10404. * @exports zrender/animation/easing
  10405. */
  10406. var easing = {
  10407. /**
  10408. * @param {number} k
  10409. * @return {number}
  10410. */
  10411. linear: function (k) {
  10412. return k;
  10413. },
  10414. /**
  10415. * @param {number} k
  10416. * @return {number}
  10417. */
  10418. quadraticIn: function (k) {
  10419. return k * k;
  10420. },
  10421. /**
  10422. * @param {number} k
  10423. * @return {number}
  10424. */
  10425. quadraticOut: function (k) {
  10426. return k * (2 - k);
  10427. },
  10428. /**
  10429. * @param {number} k
  10430. * @return {number}
  10431. */
  10432. quadraticInOut: function (k) {
  10433. if ((k *= 2) < 1) {
  10434. return 0.5 * k * k;
  10435. }
  10436. return -0.5 * (--k * (k - 2) - 1);
  10437. },
  10438. // 三次方的缓动(t^3)
  10439. /**
  10440. * @param {number} k
  10441. * @return {number}
  10442. */
  10443. cubicIn: function (k) {
  10444. return k * k * k;
  10445. },
  10446. /**
  10447. * @param {number} k
  10448. * @return {number}
  10449. */
  10450. cubicOut: function (k) {
  10451. return --k * k * k + 1;
  10452. },
  10453. /**
  10454. * @param {number} k
  10455. * @return {number}
  10456. */
  10457. cubicInOut: function (k) {
  10458. if ((k *= 2) < 1) {
  10459. return 0.5 * k * k * k;
  10460. }
  10461. return 0.5 * ((k -= 2) * k * k + 2);
  10462. },
  10463. // 四次方的缓动(t^4)
  10464. /**
  10465. * @param {number} k
  10466. * @return {number}
  10467. */
  10468. quarticIn: function (k) {
  10469. return k * k * k * k;
  10470. },
  10471. /**
  10472. * @param {number} k
  10473. * @return {number}
  10474. */
  10475. quarticOut: function (k) {
  10476. return 1 - --k * k * k * k;
  10477. },
  10478. /**
  10479. * @param {number} k
  10480. * @return {number}
  10481. */
  10482. quarticInOut: function (k) {
  10483. if ((k *= 2) < 1) {
  10484. return 0.5 * k * k * k * k;
  10485. }
  10486. return -0.5 * ((k -= 2) * k * k * k - 2);
  10487. },
  10488. // 五次方的缓动(t^5)
  10489. /**
  10490. * @param {number} k
  10491. * @return {number}
  10492. */
  10493. quinticIn: function (k) {
  10494. return k * k * k * k * k;
  10495. },
  10496. /**
  10497. * @param {number} k
  10498. * @return {number}
  10499. */
  10500. quinticOut: function (k) {
  10501. return --k * k * k * k * k + 1;
  10502. },
  10503. /**
  10504. * @param {number} k
  10505. * @return {number}
  10506. */
  10507. quinticInOut: function (k) {
  10508. if ((k *= 2) < 1) {
  10509. return 0.5 * k * k * k * k * k;
  10510. }
  10511. return 0.5 * ((k -= 2) * k * k * k * k + 2);
  10512. },
  10513. // 正弦曲线的缓动(sin(t))
  10514. /**
  10515. * @param {number} k
  10516. * @return {number}
  10517. */
  10518. sinusoidalIn: function (k) {
  10519. return 1 - Math.cos(k * Math.PI / 2);
  10520. },
  10521. /**
  10522. * @param {number} k
  10523. * @return {number}
  10524. */
  10525. sinusoidalOut: function (k) {
  10526. return Math.sin(k * Math.PI / 2);
  10527. },
  10528. /**
  10529. * @param {number} k
  10530. * @return {number}
  10531. */
  10532. sinusoidalInOut: function (k) {
  10533. return 0.5 * (1 - Math.cos(Math.PI * k));
  10534. },
  10535. // 指数曲线的缓动(2^t)
  10536. /**
  10537. * @param {number} k
  10538. * @return {number}
  10539. */
  10540. exponentialIn: function (k) {
  10541. return k === 0 ? 0 : Math.pow(1024, k - 1);
  10542. },
  10543. /**
  10544. * @param {number} k
  10545. * @return {number}
  10546. */
  10547. exponentialOut: function (k) {
  10548. return k === 1 ? 1 : 1 - Math.pow(2, -10 * k);
  10549. },
  10550. /**
  10551. * @param {number} k
  10552. * @return {number}
  10553. */
  10554. exponentialInOut: function (k) {
  10555. if (k === 0) {
  10556. return 0;
  10557. }
  10558. if (k === 1) {
  10559. return 1;
  10560. }
  10561. if ((k *= 2) < 1) {
  10562. return 0.5 * Math.pow(1024, k - 1);
  10563. }
  10564. return 0.5 * (-Math.pow(2, -10 * (k - 1)) + 2);
  10565. },
  10566. // 圆形曲线的缓动(sqrt(1-t^2))
  10567. /**
  10568. * @param {number} k
  10569. * @return {number}
  10570. */
  10571. circularIn: function (k) {
  10572. return 1 - Math.sqrt(1 - k * k);
  10573. },
  10574. /**
  10575. * @param {number} k
  10576. * @return {number}
  10577. */
  10578. circularOut: function (k) {
  10579. return Math.sqrt(1 - --k * k);
  10580. },
  10581. /**
  10582. * @param {number} k
  10583. * @return {number}
  10584. */
  10585. circularInOut: function (k) {
  10586. if ((k *= 2) < 1) {
  10587. return -0.5 * (Math.sqrt(1 - k * k) - 1);
  10588. }
  10589. return 0.5 * (Math.sqrt(1 - (k -= 2) * k) + 1);
  10590. },
  10591. // 创建类似于弹簧在停止前来回振荡的动画
  10592. /**
  10593. * @param {number} k
  10594. * @return {number}
  10595. */
  10596. elasticIn: function (k) {
  10597. var s;
  10598. var a = 0.1;
  10599. var p = 0.4;
  10600. if (k === 0) {
  10601. return 0;
  10602. }
  10603. if (k === 1) {
  10604. return 1;
  10605. }
  10606. if (!a || a < 1) {
  10607. a = 1;
  10608. s = p / 4;
  10609. } else {
  10610. s = p * Math.asin(1 / a) / (2 * Math.PI);
  10611. }
  10612. return -(a * Math.pow(2, 10 * (k -= 1)) * Math.sin((k - s) * (2 * Math.PI) / p));
  10613. },
  10614. /**
  10615. * @param {number} k
  10616. * @return {number}
  10617. */
  10618. elasticOut: function (k) {
  10619. var s;
  10620. var a = 0.1;
  10621. var p = 0.4;
  10622. if (k === 0) {
  10623. return 0;
  10624. }
  10625. if (k === 1) {
  10626. return 1;
  10627. }
  10628. if (!a || a < 1) {
  10629. a = 1;
  10630. s = p / 4;
  10631. } else {
  10632. s = p * Math.asin(1 / a) / (2 * Math.PI);
  10633. }
  10634. return a * Math.pow(2, -10 * k) * Math.sin((k - s) * (2 * Math.PI) / p) + 1;
  10635. },
  10636. /**
  10637. * @param {number} k
  10638. * @return {number}
  10639. */
  10640. elasticInOut: function (k) {
  10641. var s;
  10642. var a = 0.1;
  10643. var p = 0.4;
  10644. if (k === 0) {
  10645. return 0;
  10646. }
  10647. if (k === 1) {
  10648. return 1;
  10649. }
  10650. if (!a || a < 1) {
  10651. a = 1;
  10652. s = p / 4;
  10653. } else {
  10654. s = p * Math.asin(1 / a) / (2 * Math.PI);
  10655. }
  10656. if ((k *= 2) < 1) {
  10657. return -0.5 * (a * Math.pow(2, 10 * (k -= 1)) * Math.sin((k - s) * (2 * Math.PI) / p));
  10658. }
  10659. return a * Math.pow(2, -10 * (k -= 1)) * Math.sin((k - s) * (2 * Math.PI) / p) * 0.5 + 1;
  10660. },
  10661. // 在某一动画开始沿指示的路径进行动画处理前稍稍收回该动画的移动
  10662. /**
  10663. * @param {number} k
  10664. * @return {number}
  10665. */
  10666. backIn: function (k) {
  10667. var s = 1.70158;
  10668. return k * k * ((s + 1) * k - s);
  10669. },
  10670. /**
  10671. * @param {number} k
  10672. * @return {number}
  10673. */
  10674. backOut: function (k) {
  10675. var s = 1.70158;
  10676. return --k * k * ((s + 1) * k + s) + 1;
  10677. },
  10678. /**
  10679. * @param {number} k
  10680. * @return {number}
  10681. */
  10682. backInOut: function (k) {
  10683. var s = 1.70158 * 1.525;
  10684. if ((k *= 2) < 1) {
  10685. return 0.5 * (k * k * ((s + 1) * k - s));
  10686. }
  10687. return 0.5 * ((k -= 2) * k * ((s + 1) * k + s) + 2);
  10688. },
  10689. // 创建弹跳效果
  10690. /**
  10691. * @param {number} k
  10692. * @return {number}
  10693. */
  10694. bounceIn: function (k) {
  10695. return 1 - easing.bounceOut(1 - k);
  10696. },
  10697. /**
  10698. * @param {number} k
  10699. * @return {number}
  10700. */
  10701. bounceOut: function (k) {
  10702. if (k < 1 / 2.75) {
  10703. return 7.5625 * k * k;
  10704. } else if (k < 2 / 2.75) {
  10705. return 7.5625 * (k -= 1.5 / 2.75) * k + 0.75;
  10706. } else if (k < 2.5 / 2.75) {
  10707. return 7.5625 * (k -= 2.25 / 2.75) * k + 0.9375;
  10708. } else {
  10709. return 7.5625 * (k -= 2.625 / 2.75) * k + 0.984375;
  10710. }
  10711. },
  10712. /**
  10713. * @param {number} k
  10714. * @return {number}
  10715. */
  10716. bounceInOut: function (k) {
  10717. if (k < 0.5) {
  10718. return easing.bounceIn(k * 2) * 0.5;
  10719. }
  10720. return easing.bounceOut(k * 2 - 1) * 0.5 + 0.5;
  10721. }
  10722. };
  10723. var _default = easing;
  10724. module.exports = _default;
  10725. /***/ }),
  10726. /* 47 */
  10727. /***/ (function(module, exports, __webpack_require__) {
  10728. var _config = __webpack_require__(19);
  10729. var debugMode = _config.debugMode;
  10730. var log = function () {};
  10731. if (debugMode === 1) {
  10732. log = function () {
  10733. for (var k in arguments) {
  10734. throw new Error(arguments[k]);
  10735. }
  10736. };
  10737. } else if (debugMode > 1) {
  10738. log = function () {
  10739. for (var k in arguments) {
  10740. console.log(arguments[k]);
  10741. }
  10742. };
  10743. }
  10744. var _default = log;
  10745. module.exports = _default;
  10746. /***/ }),
  10747. /* 48 */
  10748. /***/ (function(module, exports, __webpack_require__) {
  10749. var textHelper = __webpack_require__(20);
  10750. var BoundingRect = __webpack_require__(3);
  10751. /**
  10752. * Mixin for drawing text in a element bounding rect
  10753. * @module zrender/mixin/RectText
  10754. */
  10755. var tmpRect = new BoundingRect();
  10756. var RectText = function () {};
  10757. RectText.prototype = {
  10758. constructor: RectText,
  10759. /**
  10760. * Draw text in a rect with specified position.
  10761. * @param {CanvasRenderingContext2D} ctx
  10762. * @param {Object} rect Displayable rect
  10763. */
  10764. drawRectText: function (ctx, rect) {
  10765. var style = this.style;
  10766. rect = style.textRect || rect; // Optimize, avoid normalize every time.
  10767. this.__dirty && textHelper.normalizeTextStyle(style, true);
  10768. var text = style.text; // Convert to string
  10769. text != null && (text += '');
  10770. if (!textHelper.needDrawText(text, style)) {
  10771. return;
  10772. } // FIXME
  10773. ctx.save(); // Transform rect to view space
  10774. var transform = this.transform;
  10775. if (!style.transformText) {
  10776. if (transform) {
  10777. tmpRect.copy(rect);
  10778. tmpRect.applyTransform(transform);
  10779. rect = tmpRect;
  10780. }
  10781. } else {
  10782. this.setTransform(ctx);
  10783. } // transformText and textRotation can not be used at the same time.
  10784. textHelper.renderText(this, ctx, text, style, rect);
  10785. ctx.restore();
  10786. }
  10787. };
  10788. var _default = RectText;
  10789. module.exports = _default;
  10790. /***/ }),
  10791. /* 49 */
  10792. /***/ (function(module, exports, __webpack_require__) {
  10793. var vec2 = __webpack_require__(2);
  10794. var curve = __webpack_require__(4);
  10795. /**
  10796. * @author Yi Shen(https://github.com/pissang)
  10797. */
  10798. var mathMin = Math.min;
  10799. var mathMax = Math.max;
  10800. var mathSin = Math.sin;
  10801. var mathCos = Math.cos;
  10802. var PI2 = Math.PI * 2;
  10803. var start = vec2.create();
  10804. var end = vec2.create();
  10805. var extremity = vec2.create();
  10806. /**
  10807. * 从顶点数组中计算出最小包围盒,写入`min`和`max`中
  10808. * @module zrender/core/bbox
  10809. * @param {Array<Object>} points 顶点数组
  10810. * @param {number} min
  10811. * @param {number} max
  10812. */
  10813. function fromPoints(points, min, max) {
  10814. if (points.length === 0) {
  10815. return;
  10816. }
  10817. var p = points[0];
  10818. var left = p[0];
  10819. var right = p[0];
  10820. var top = p[1];
  10821. var bottom = p[1];
  10822. var i;
  10823. for (i = 1; i < points.length; i++) {
  10824. p = points[i];
  10825. left = mathMin(left, p[0]);
  10826. right = mathMax(right, p[0]);
  10827. top = mathMin(top, p[1]);
  10828. bottom = mathMax(bottom, p[1]);
  10829. }
  10830. min[0] = left;
  10831. min[1] = top;
  10832. max[0] = right;
  10833. max[1] = bottom;
  10834. }
  10835. /**
  10836. * @memberOf module:zrender/core/bbox
  10837. * @param {number} x0
  10838. * @param {number} y0
  10839. * @param {number} x1
  10840. * @param {number} y1
  10841. * @param {Array.<number>} min
  10842. * @param {Array.<number>} max
  10843. */
  10844. function fromLine(x0, y0, x1, y1, min, max) {
  10845. min[0] = mathMin(x0, x1);
  10846. min[1] = mathMin(y0, y1);
  10847. max[0] = mathMax(x0, x1);
  10848. max[1] = mathMax(y0, y1);
  10849. }
  10850. var xDim = [];
  10851. var yDim = [];
  10852. /**
  10853. * 从三阶贝塞尔曲线(p0, p1, p2, p3)中计算出最小包围盒,写入`min`和`max`中
  10854. * @memberOf module:zrender/core/bbox
  10855. * @param {number} x0
  10856. * @param {number} y0
  10857. * @param {number} x1
  10858. * @param {number} y1
  10859. * @param {number} x2
  10860. * @param {number} y2
  10861. * @param {number} x3
  10862. * @param {number} y3
  10863. * @param {Array.<number>} min
  10864. * @param {Array.<number>} max
  10865. */
  10866. function fromCubic(x0, y0, x1, y1, x2, y2, x3, y3, min, max) {
  10867. var cubicExtrema = curve.cubicExtrema;
  10868. var cubicAt = curve.cubicAt;
  10869. var i;
  10870. var n = cubicExtrema(x0, x1, x2, x3, xDim);
  10871. min[0] = Infinity;
  10872. min[1] = Infinity;
  10873. max[0] = -Infinity;
  10874. max[1] = -Infinity;
  10875. for (i = 0; i < n; i++) {
  10876. var x = cubicAt(x0, x1, x2, x3, xDim[i]);
  10877. min[0] = mathMin(x, min[0]);
  10878. max[0] = mathMax(x, max[0]);
  10879. }
  10880. n = cubicExtrema(y0, y1, y2, y3, yDim);
  10881. for (i = 0; i < n; i++) {
  10882. var y = cubicAt(y0, y1, y2, y3, yDim[i]);
  10883. min[1] = mathMin(y, min[1]);
  10884. max[1] = mathMax(y, max[1]);
  10885. }
  10886. min[0] = mathMin(x0, min[0]);
  10887. max[0] = mathMax(x0, max[0]);
  10888. min[0] = mathMin(x3, min[0]);
  10889. max[0] = mathMax(x3, max[0]);
  10890. min[1] = mathMin(y0, min[1]);
  10891. max[1] = mathMax(y0, max[1]);
  10892. min[1] = mathMin(y3, min[1]);
  10893. max[1] = mathMax(y3, max[1]);
  10894. }
  10895. /**
  10896. * 从二阶贝塞尔曲线(p0, p1, p2)中计算出最小包围盒,写入`min`和`max`中
  10897. * @memberOf module:zrender/core/bbox
  10898. * @param {number} x0
  10899. * @param {number} y0
  10900. * @param {number} x1
  10901. * @param {number} y1
  10902. * @param {number} x2
  10903. * @param {number} y2
  10904. * @param {Array.<number>} min
  10905. * @param {Array.<number>} max
  10906. */
  10907. function fromQuadratic(x0, y0, x1, y1, x2, y2, min, max) {
  10908. var quadraticExtremum = curve.quadraticExtremum;
  10909. var quadraticAt = curve.quadraticAt; // Find extremities, where derivative in x dim or y dim is zero
  10910. var tx = mathMax(mathMin(quadraticExtremum(x0, x1, x2), 1), 0);
  10911. var ty = mathMax(mathMin(quadraticExtremum(y0, y1, y2), 1), 0);
  10912. var x = quadraticAt(x0, x1, x2, tx);
  10913. var y = quadraticAt(y0, y1, y2, ty);
  10914. min[0] = mathMin(x0, x2, x);
  10915. min[1] = mathMin(y0, y2, y);
  10916. max[0] = mathMax(x0, x2, x);
  10917. max[1] = mathMax(y0, y2, y);
  10918. }
  10919. /**
  10920. * 从圆弧中计算出最小包围盒,写入`min`和`max`中
  10921. * @method
  10922. * @memberOf module:zrender/core/bbox
  10923. * @param {number} x
  10924. * @param {number} y
  10925. * @param {number} rx
  10926. * @param {number} ry
  10927. * @param {number} startAngle
  10928. * @param {number} endAngle
  10929. * @param {number} anticlockwise
  10930. * @param {Array.<number>} min
  10931. * @param {Array.<number>} max
  10932. */
  10933. function fromArc(x, y, rx, ry, startAngle, endAngle, anticlockwise, min, max) {
  10934. var vec2Min = vec2.min;
  10935. var vec2Max = vec2.max;
  10936. var diff = Math.abs(startAngle - endAngle);
  10937. if (diff % PI2 < 1e-4 && diff > 1e-4) {
  10938. // Is a circle
  10939. min[0] = x - rx;
  10940. min[1] = y - ry;
  10941. max[0] = x + rx;
  10942. max[1] = y + ry;
  10943. return;
  10944. }
  10945. start[0] = mathCos(startAngle) * rx + x;
  10946. start[1] = mathSin(startAngle) * ry + y;
  10947. end[0] = mathCos(endAngle) * rx + x;
  10948. end[1] = mathSin(endAngle) * ry + y;
  10949. vec2Min(min, start, end);
  10950. vec2Max(max, start, end); // Thresh to [0, Math.PI * 2]
  10951. startAngle = startAngle % PI2;
  10952. if (startAngle < 0) {
  10953. startAngle = startAngle + PI2;
  10954. }
  10955. endAngle = endAngle % PI2;
  10956. if (endAngle < 0) {
  10957. endAngle = endAngle + PI2;
  10958. }
  10959. if (startAngle > endAngle && !anticlockwise) {
  10960. endAngle += PI2;
  10961. } else if (startAngle < endAngle && anticlockwise) {
  10962. startAngle += PI2;
  10963. }
  10964. if (anticlockwise) {
  10965. var tmp = endAngle;
  10966. endAngle = startAngle;
  10967. startAngle = tmp;
  10968. } // var number = 0;
  10969. // var step = (anticlockwise ? -Math.PI : Math.PI) / 2;
  10970. for (var angle = 0; angle < endAngle; angle += Math.PI / 2) {
  10971. if (angle > startAngle) {
  10972. extremity[0] = mathCos(angle) * rx + x;
  10973. extremity[1] = mathSin(angle) * ry + y;
  10974. vec2Min(min, extremity, min);
  10975. vec2Max(max, extremity, max);
  10976. }
  10977. }
  10978. }
  10979. exports.fromPoints = fromPoints;
  10980. exports.fromLine = fromLine;
  10981. exports.fromCubic = fromCubic;
  10982. exports.fromQuadratic = fromQuadratic;
  10983. exports.fromArc = fromArc;
  10984. /***/ }),
  10985. /* 50 */
  10986. /***/ (function(module, exports, __webpack_require__) {
  10987. var PathProxy = __webpack_require__(6);
  10988. var line = __webpack_require__(51);
  10989. var cubic = __webpack_require__(52);
  10990. var quadratic = __webpack_require__(53);
  10991. var arc = __webpack_require__(54);
  10992. var _util = __webpack_require__(22);
  10993. var normalizeRadian = _util.normalizeRadian;
  10994. var curve = __webpack_require__(4);
  10995. var windingLine = __webpack_require__(55);
  10996. var CMD = PathProxy.CMD;
  10997. var PI2 = Math.PI * 2;
  10998. var EPSILON = 1e-4;
  10999. function isAroundEqual(a, b) {
  11000. return Math.abs(a - b) < EPSILON;
  11001. } // 临时数组
  11002. var roots = [-1, -1, -1];
  11003. var extrema = [-1, -1];
  11004. function swapExtrema() {
  11005. var tmp = extrema[0];
  11006. extrema[0] = extrema[1];
  11007. extrema[1] = tmp;
  11008. }
  11009. function windingCubic(x0, y0, x1, y1, x2, y2, x3, y3, x, y) {
  11010. // Quick reject
  11011. if (y > y0 && y > y1 && y > y2 && y > y3 || y < y0 && y < y1 && y < y2 && y < y3) {
  11012. return 0;
  11013. }
  11014. var nRoots = curve.cubicRootAt(y0, y1, y2, y3, y, roots);
  11015. if (nRoots === 0) {
  11016. return 0;
  11017. } else {
  11018. var w = 0;
  11019. var nExtrema = -1;
  11020. var y0_, y1_;
  11021. for (var i = 0; i < nRoots; i++) {
  11022. var t = roots[i]; // Avoid winding error when intersection point is the connect point of two line of polygon
  11023. var unit = t === 0 || t === 1 ? 0.5 : 1;
  11024. var x_ = curve.cubicAt(x0, x1, x2, x3, t);
  11025. if (x_ < x) {
  11026. // Quick reject
  11027. continue;
  11028. }
  11029. if (nExtrema < 0) {
  11030. nExtrema = curve.cubicExtrema(y0, y1, y2, y3, extrema);
  11031. if (extrema[1] < extrema[0] && nExtrema > 1) {
  11032. swapExtrema();
  11033. }
  11034. y0_ = curve.cubicAt(y0, y1, y2, y3, extrema[0]);
  11035. if (nExtrema > 1) {
  11036. y1_ = curve.cubicAt(y0, y1, y2, y3, extrema[1]);
  11037. }
  11038. }
  11039. if (nExtrema == 2) {
  11040. // 分成三段单调函数
  11041. if (t < extrema[0]) {
  11042. w += y0_ < y0 ? unit : -unit;
  11043. } else if (t < extrema[1]) {
  11044. w += y1_ < y0_ ? unit : -unit;
  11045. } else {
  11046. w += y3 < y1_ ? unit : -unit;
  11047. }
  11048. } else {
  11049. // 分成两段单调函数
  11050. if (t < extrema[0]) {
  11051. w += y0_ < y0 ? unit : -unit;
  11052. } else {
  11053. w += y3 < y0_ ? unit : -unit;
  11054. }
  11055. }
  11056. }
  11057. return w;
  11058. }
  11059. }
  11060. function windingQuadratic(x0, y0, x1, y1, x2, y2, x, y) {
  11061. // Quick reject
  11062. if (y > y0 && y > y1 && y > y2 || y < y0 && y < y1 && y < y2) {
  11063. return 0;
  11064. }
  11065. var nRoots = curve.quadraticRootAt(y0, y1, y2, y, roots);
  11066. if (nRoots === 0) {
  11067. return 0;
  11068. } else {
  11069. var t = curve.quadraticExtremum(y0, y1, y2);
  11070. if (t >= 0 && t <= 1) {
  11071. var w = 0;
  11072. var y_ = curve.quadraticAt(y0, y1, y2, t);
  11073. for (var i = 0; i < nRoots; i++) {
  11074. // Remove one endpoint.
  11075. var unit = roots[i] === 0 || roots[i] === 1 ? 0.5 : 1;
  11076. var x_ = curve.quadraticAt(x0, x1, x2, roots[i]);
  11077. if (x_ < x) {
  11078. // Quick reject
  11079. continue;
  11080. }
  11081. if (roots[i] < t) {
  11082. w += y_ < y0 ? unit : -unit;
  11083. } else {
  11084. w += y2 < y_ ? unit : -unit;
  11085. }
  11086. }
  11087. return w;
  11088. } else {
  11089. // Remove one endpoint.
  11090. var unit = roots[0] === 0 || roots[0] === 1 ? 0.5 : 1;
  11091. var x_ = curve.quadraticAt(x0, x1, x2, roots[0]);
  11092. if (x_ < x) {
  11093. // Quick reject
  11094. return 0;
  11095. }
  11096. return y2 < y0 ? unit : -unit;
  11097. }
  11098. }
  11099. } // TODO
  11100. // Arc 旋转
  11101. function windingArc(cx, cy, r, startAngle, endAngle, anticlockwise, x, y) {
  11102. y -= cy;
  11103. if (y > r || y < -r) {
  11104. return 0;
  11105. }
  11106. var tmp = Math.sqrt(r * r - y * y);
  11107. roots[0] = -tmp;
  11108. roots[1] = tmp;
  11109. var diff = Math.abs(startAngle - endAngle);
  11110. if (diff < 1e-4) {
  11111. return 0;
  11112. }
  11113. if (diff % PI2 < 1e-4) {
  11114. // Is a circle
  11115. startAngle = 0;
  11116. endAngle = PI2;
  11117. var dir = anticlockwise ? 1 : -1;
  11118. if (x >= roots[0] + cx && x <= roots[1] + cx) {
  11119. return dir;
  11120. } else {
  11121. return 0;
  11122. }
  11123. }
  11124. if (anticlockwise) {
  11125. var tmp = startAngle;
  11126. startAngle = normalizeRadian(endAngle);
  11127. endAngle = normalizeRadian(tmp);
  11128. } else {
  11129. startAngle = normalizeRadian(startAngle);
  11130. endAngle = normalizeRadian(endAngle);
  11131. }
  11132. if (startAngle > endAngle) {
  11133. endAngle += PI2;
  11134. }
  11135. var w = 0;
  11136. for (var i = 0; i < 2; i++) {
  11137. var x_ = roots[i];
  11138. if (x_ + cx > x) {
  11139. var angle = Math.atan2(y, x_);
  11140. var dir = anticlockwise ? 1 : -1;
  11141. if (angle < 0) {
  11142. angle = PI2 + angle;
  11143. }
  11144. if (angle >= startAngle && angle <= endAngle || angle + PI2 >= startAngle && angle + PI2 <= endAngle) {
  11145. if (angle > Math.PI / 2 && angle < Math.PI * 1.5) {
  11146. dir = -dir;
  11147. }
  11148. w += dir;
  11149. }
  11150. }
  11151. }
  11152. return w;
  11153. }
  11154. function containPath(data, lineWidth, isStroke, x, y) {
  11155. var w = 0;
  11156. var xi = 0;
  11157. var yi = 0;
  11158. var x0 = 0;
  11159. var y0 = 0;
  11160. for (var i = 0; i < data.length;) {
  11161. var cmd = data[i++]; // Begin a new subpath
  11162. if (cmd === CMD.M && i > 1) {
  11163. // Close previous subpath
  11164. if (!isStroke) {
  11165. w += windingLine(xi, yi, x0, y0, x, y);
  11166. } // 如果被任何一个 subpath 包含
  11167. // if (w !== 0) {
  11168. // return true;
  11169. // }
  11170. }
  11171. if (i == 1) {
  11172. // 如果第一个命令是 L, C, Q
  11173. // 则 previous point 同绘制命令的第一个 point
  11174. //
  11175. // 第一个命令为 Arc 的情况下会在后面特殊处理
  11176. xi = data[i];
  11177. yi = data[i + 1];
  11178. x0 = xi;
  11179. y0 = yi;
  11180. }
  11181. switch (cmd) {
  11182. case CMD.M:
  11183. // moveTo 命令重新创建一个新的 subpath, 并且更新新的起点
  11184. // 在 closePath 的时候使用
  11185. x0 = data[i++];
  11186. y0 = data[i++];
  11187. xi = x0;
  11188. yi = y0;
  11189. break;
  11190. case CMD.L:
  11191. if (isStroke) {
  11192. if (line.containStroke(xi, yi, data[i], data[i + 1], lineWidth, x, y)) {
  11193. return true;
  11194. }
  11195. } else {
  11196. // NOTE 在第一个命令为 L, C, Q 的时候会计算出 NaN
  11197. w += windingLine(xi, yi, data[i], data[i + 1], x, y) || 0;
  11198. }
  11199. xi = data[i++];
  11200. yi = data[i++];
  11201. break;
  11202. case CMD.C:
  11203. if (isStroke) {
  11204. if (cubic.containStroke(xi, yi, data[i++], data[i++], data[i++], data[i++], data[i], data[i + 1], lineWidth, x, y)) {
  11205. return true;
  11206. }
  11207. } else {
  11208. w += windingCubic(xi, yi, data[i++], data[i++], data[i++], data[i++], data[i], data[i + 1], x, y) || 0;
  11209. }
  11210. xi = data[i++];
  11211. yi = data[i++];
  11212. break;
  11213. case CMD.Q:
  11214. if (isStroke) {
  11215. if (quadratic.containStroke(xi, yi, data[i++], data[i++], data[i], data[i + 1], lineWidth, x, y)) {
  11216. return true;
  11217. }
  11218. } else {
  11219. w += windingQuadratic(xi, yi, data[i++], data[i++], data[i], data[i + 1], x, y) || 0;
  11220. }
  11221. xi = data[i++];
  11222. yi = data[i++];
  11223. break;
  11224. case CMD.A:
  11225. // TODO Arc 判断的开销比较大
  11226. var cx = data[i++];
  11227. var cy = data[i++];
  11228. var rx = data[i++];
  11229. var ry = data[i++];
  11230. var theta = data[i++];
  11231. var dTheta = data[i++]; // TODO Arc 旋转
  11232. var psi = data[i++];
  11233. var anticlockwise = 1 - data[i++];
  11234. var x1 = Math.cos(theta) * rx + cx;
  11235. var y1 = Math.sin(theta) * ry + cy; // 不是直接使用 arc 命令
  11236. if (i > 1) {
  11237. w += windingLine(xi, yi, x1, y1, x, y);
  11238. } else {
  11239. // 第一个命令起点还未定义
  11240. x0 = x1;
  11241. y0 = y1;
  11242. } // zr 使用scale来模拟椭圆, 这里也对x做一定的缩放
  11243. var _x = (x - cx) * ry / rx + cx;
  11244. if (isStroke) {
  11245. if (arc.containStroke(cx, cy, ry, theta, theta + dTheta, anticlockwise, lineWidth, _x, y)) {
  11246. return true;
  11247. }
  11248. } else {
  11249. w += windingArc(cx, cy, ry, theta, theta + dTheta, anticlockwise, _x, y);
  11250. }
  11251. xi = Math.cos(theta + dTheta) * rx + cx;
  11252. yi = Math.sin(theta + dTheta) * ry + cy;
  11253. break;
  11254. case CMD.R:
  11255. x0 = xi = data[i++];
  11256. y0 = yi = data[i++];
  11257. var width = data[i++];
  11258. var height = data[i++];
  11259. var x1 = x0 + width;
  11260. var y1 = y0 + height;
  11261. if (isStroke) {
  11262. if (line.containStroke(x0, y0, x1, y0, lineWidth, x, y) || line.containStroke(x1, y0, x1, y1, lineWidth, x, y) || line.containStroke(x1, y1, x0, y1, lineWidth, x, y) || line.containStroke(x0, y1, x0, y0, lineWidth, x, y)) {
  11263. return true;
  11264. }
  11265. } else {
  11266. // FIXME Clockwise ?
  11267. w += windingLine(x1, y0, x1, y1, x, y);
  11268. w += windingLine(x0, y1, x0, y0, x, y);
  11269. }
  11270. break;
  11271. case CMD.Z:
  11272. if (isStroke) {
  11273. if (line.containStroke(xi, yi, x0, y0, lineWidth, x, y)) {
  11274. return true;
  11275. }
  11276. } else {
  11277. // Close a subpath
  11278. w += windingLine(xi, yi, x0, y0, x, y); // 如果被任何一个 subpath 包含
  11279. // FIXME subpaths may overlap
  11280. // if (w !== 0) {
  11281. // return true;
  11282. // }
  11283. }
  11284. xi = x0;
  11285. yi = y0;
  11286. break;
  11287. }
  11288. }
  11289. if (!isStroke && !isAroundEqual(yi, y0)) {
  11290. w += windingLine(xi, yi, x0, y0, x, y) || 0;
  11291. }
  11292. return w !== 0;
  11293. }
  11294. function contain(pathData, x, y) {
  11295. return containPath(pathData, 0, false, x, y);
  11296. }
  11297. function containStroke(pathData, lineWidth, x, y) {
  11298. return containPath(pathData, lineWidth, true, x, y);
  11299. }
  11300. exports.contain = contain;
  11301. exports.containStroke = containStroke;
  11302. /***/ }),
  11303. /* 51 */
  11304. /***/ (function(module, exports) {
  11305. /**
  11306. * 线段包含判断
  11307. * @param {number} x0
  11308. * @param {number} y0
  11309. * @param {number} x1
  11310. * @param {number} y1
  11311. * @param {number} lineWidth
  11312. * @param {number} x
  11313. * @param {number} y
  11314. * @return {boolean}
  11315. */
  11316. function containStroke(x0, y0, x1, y1, lineWidth, x, y) {
  11317. if (lineWidth === 0) {
  11318. return false;
  11319. }
  11320. var _l = lineWidth;
  11321. var _a = 0;
  11322. var _b = x0; // Quick reject
  11323. if (y > y0 + _l && y > y1 + _l || y < y0 - _l && y < y1 - _l || x > x0 + _l && x > x1 + _l || x < x0 - _l && x < x1 - _l) {
  11324. return false;
  11325. }
  11326. if (x0 !== x1) {
  11327. _a = (y0 - y1) / (x0 - x1);
  11328. _b = (x0 * y1 - x1 * y0) / (x0 - x1);
  11329. } else {
  11330. return Math.abs(x - x0) <= _l / 2;
  11331. }
  11332. var tmp = _a * x - y + _b;
  11333. var _s = tmp * tmp / (_a * _a + 1);
  11334. return _s <= _l / 2 * _l / 2;
  11335. }
  11336. exports.containStroke = containStroke;
  11337. /***/ }),
  11338. /* 52 */
  11339. /***/ (function(module, exports, __webpack_require__) {
  11340. var curve = __webpack_require__(4);
  11341. /**
  11342. * 三次贝塞尔曲线描边包含判断
  11343. * @param {number} x0
  11344. * @param {number} y0
  11345. * @param {number} x1
  11346. * @param {number} y1
  11347. * @param {number} x2
  11348. * @param {number} y2
  11349. * @param {number} x3
  11350. * @param {number} y3
  11351. * @param {number} lineWidth
  11352. * @param {number} x
  11353. * @param {number} y
  11354. * @return {boolean}
  11355. */
  11356. function containStroke(x0, y0, x1, y1, x2, y2, x3, y3, lineWidth, x, y) {
  11357. if (lineWidth === 0) {
  11358. return false;
  11359. }
  11360. var _l = lineWidth; // Quick reject
  11361. if (y > y0 + _l && y > y1 + _l && y > y2 + _l && y > y3 + _l || y < y0 - _l && y < y1 - _l && y < y2 - _l && y < y3 - _l || x > x0 + _l && x > x1 + _l && x > x2 + _l && x > x3 + _l || x < x0 - _l && x < x1 - _l && x < x2 - _l && x < x3 - _l) {
  11362. return false;
  11363. }
  11364. var d = curve.cubicProjectPoint(x0, y0, x1, y1, x2, y2, x3, y3, x, y, null);
  11365. return d <= _l / 2;
  11366. }
  11367. exports.containStroke = containStroke;
  11368. /***/ }),
  11369. /* 53 */
  11370. /***/ (function(module, exports, __webpack_require__) {
  11371. var _curve = __webpack_require__(4);
  11372. var quadraticProjectPoint = _curve.quadraticProjectPoint;
  11373. /**
  11374. * 二次贝塞尔曲线描边包含判断
  11375. * @param {number} x0
  11376. * @param {number} y0
  11377. * @param {number} x1
  11378. * @param {number} y1
  11379. * @param {number} x2
  11380. * @param {number} y2
  11381. * @param {number} lineWidth
  11382. * @param {number} x
  11383. * @param {number} y
  11384. * @return {boolean}
  11385. */
  11386. function containStroke(x0, y0, x1, y1, x2, y2, lineWidth, x, y) {
  11387. if (lineWidth === 0) {
  11388. return false;
  11389. }
  11390. var _l = lineWidth; // Quick reject
  11391. if (y > y0 + _l && y > y1 + _l && y > y2 + _l || y < y0 - _l && y < y1 - _l && y < y2 - _l || x > x0 + _l && x > x1 + _l && x > x2 + _l || x < x0 - _l && x < x1 - _l && x < x2 - _l) {
  11392. return false;
  11393. }
  11394. var d = quadraticProjectPoint(x0, y0, x1, y1, x2, y2, x, y, null);
  11395. return d <= _l / 2;
  11396. }
  11397. exports.containStroke = containStroke;
  11398. /***/ }),
  11399. /* 54 */
  11400. /***/ (function(module, exports, __webpack_require__) {
  11401. var _util = __webpack_require__(22);
  11402. var normalizeRadian = _util.normalizeRadian;
  11403. var PI2 = Math.PI * 2;
  11404. /**
  11405. * 圆弧描边包含判断
  11406. * @param {number} cx
  11407. * @param {number} cy
  11408. * @param {number} r
  11409. * @param {number} startAngle
  11410. * @param {number} endAngle
  11411. * @param {boolean} anticlockwise
  11412. * @param {number} lineWidth
  11413. * @param {number} x
  11414. * @param {number} y
  11415. * @return {Boolean}
  11416. */
  11417. function containStroke(cx, cy, r, startAngle, endAngle, anticlockwise, lineWidth, x, y) {
  11418. if (lineWidth === 0) {
  11419. return false;
  11420. }
  11421. var _l = lineWidth;
  11422. x -= cx;
  11423. y -= cy;
  11424. var d = Math.sqrt(x * x + y * y);
  11425. if (d - _l > r || d + _l < r) {
  11426. return false;
  11427. }
  11428. if (Math.abs(startAngle - endAngle) % PI2 < 1e-4) {
  11429. // Is a circle
  11430. return true;
  11431. }
  11432. if (anticlockwise) {
  11433. var tmp = startAngle;
  11434. startAngle = normalizeRadian(endAngle);
  11435. endAngle = normalizeRadian(tmp);
  11436. } else {
  11437. startAngle = normalizeRadian(startAngle);
  11438. endAngle = normalizeRadian(endAngle);
  11439. }
  11440. if (startAngle > endAngle) {
  11441. endAngle += PI2;
  11442. }
  11443. var angle = Math.atan2(y, x);
  11444. if (angle < 0) {
  11445. angle += PI2;
  11446. }
  11447. return angle >= startAngle && angle <= endAngle || angle + PI2 >= startAngle && angle + PI2 <= endAngle;
  11448. }
  11449. exports.containStroke = containStroke;
  11450. /***/ }),
  11451. /* 55 */
  11452. /***/ (function(module, exports) {
  11453. function windingLine(x0, y0, x1, y1, x, y) {
  11454. if (y > y0 && y > y1 || y < y0 && y < y1) {
  11455. return 0;
  11456. } // Ignore horizontal line
  11457. if (y1 === y0) {
  11458. return 0;
  11459. }
  11460. var dir = y1 < y0 ? 1 : -1;
  11461. var t = (y - y0) / (y1 - y0); // Avoid winding error when intersection point is the connect point of two line of polygon
  11462. if (t === 1 || t === 0) {
  11463. dir = y1 < y0 ? 0.5 : -0.5;
  11464. }
  11465. var x_ = t * (x1 - x0) + x0;
  11466. return x_ > x ? dir : 0;
  11467. }
  11468. module.exports = windingLine;
  11469. /***/ }),
  11470. /* 56 */
  11471. /***/ (function(module, exports) {
  11472. var Pattern = function (image, repeat) {
  11473. // Should do nothing more in this constructor. Because gradient can be
  11474. // declard by `color: {image: ...}`, where this constructor will not be called.
  11475. this.image = image;
  11476. this.repeat = repeat; // Can be cloned
  11477. this.type = 'pattern';
  11478. };
  11479. Pattern.prototype.getCanvasPattern = function (ctx) {
  11480. return ctx.createPattern(this.image, this.repeat || 'repeat');
  11481. };
  11482. var _default = Pattern;
  11483. module.exports = _default;
  11484. /***/ }),
  11485. /* 57 */
  11486. /***/ (function(module, exports, __webpack_require__) {
  11487. var PathProxy = __webpack_require__(6);
  11488. var _vector = __webpack_require__(2);
  11489. var v2ApplyTransform = _vector.applyTransform;
  11490. var CMD = PathProxy.CMD;
  11491. var points = [[], [], []];
  11492. var mathSqrt = Math.sqrt;
  11493. var mathAtan2 = Math.atan2;
  11494. function _default(path, m) {
  11495. var data = path.data;
  11496. var cmd;
  11497. var nPoint;
  11498. var i;
  11499. var j;
  11500. var k;
  11501. var p;
  11502. var M = CMD.M;
  11503. var C = CMD.C;
  11504. var L = CMD.L;
  11505. var R = CMD.R;
  11506. var A = CMD.A;
  11507. var Q = CMD.Q;
  11508. for (i = 0, j = 0; i < data.length;) {
  11509. cmd = data[i++];
  11510. j = i;
  11511. nPoint = 0;
  11512. switch (cmd) {
  11513. case M:
  11514. nPoint = 1;
  11515. break;
  11516. case L:
  11517. nPoint = 1;
  11518. break;
  11519. case C:
  11520. nPoint = 3;
  11521. break;
  11522. case Q:
  11523. nPoint = 2;
  11524. break;
  11525. case A:
  11526. var x = m[4];
  11527. var y = m[5];
  11528. var sx = mathSqrt(m[0] * m[0] + m[1] * m[1]);
  11529. var sy = mathSqrt(m[2] * m[2] + m[3] * m[3]);
  11530. var angle = mathAtan2(-m[1] / sy, m[0] / sx); // cx
  11531. data[i] *= sx;
  11532. data[i++] += x; // cy
  11533. data[i] *= sy;
  11534. data[i++] += y; // Scale rx and ry
  11535. // FIXME Assume psi is 0 here
  11536. data[i++] *= sx;
  11537. data[i++] *= sy; // Start angle
  11538. data[i++] += angle; // end angle
  11539. data[i++] += angle; // FIXME psi
  11540. i += 2;
  11541. j = i;
  11542. break;
  11543. case R:
  11544. // x0, y0
  11545. p[0] = data[i++];
  11546. p[1] = data[i++];
  11547. v2ApplyTransform(p, p, m);
  11548. data[j++] = p[0];
  11549. data[j++] = p[1]; // x1, y1
  11550. p[0] += data[i++];
  11551. p[1] += data[i++];
  11552. v2ApplyTransform(p, p, m);
  11553. data[j++] = p[0];
  11554. data[j++] = p[1];
  11555. }
  11556. for (k = 0; k < nPoint; k++) {
  11557. var p = points[k];
  11558. p[0] = data[i++];
  11559. p[1] = data[i++];
  11560. v2ApplyTransform(p, p, m); // Write back
  11561. data[j++] = p[0];
  11562. data[j++] = p[1];
  11563. }
  11564. }
  11565. }
  11566. module.exports = _default;
  11567. /***/ }),
  11568. /* 58 */
  11569. /***/ (function(module, exports, __webpack_require__) {
  11570. var Displayable = __webpack_require__(12);
  11571. var BoundingRect = __webpack_require__(3);
  11572. var zrUtil = __webpack_require__(0);
  11573. var imageHelper = __webpack_require__(10);
  11574. /**
  11575. * @alias zrender/graphic/Image
  11576. * @extends module:zrender/graphic/Displayable
  11577. * @constructor
  11578. * @param {Object} opts
  11579. */
  11580. function ZImage(opts) {
  11581. Displayable.call(this, opts);
  11582. }
  11583. ZImage.prototype = {
  11584. constructor: ZImage,
  11585. type: 'image',
  11586. brush: function (ctx, prevEl) {
  11587. var style = this.style;
  11588. var src = style.image; // Must bind each time
  11589. style.bind(ctx, this, prevEl);
  11590. var image = this._image = imageHelper.createOrUpdateImage(src, this._image, this, this.onload);
  11591. if (!image || !imageHelper.isImageReady(image)) {
  11592. return;
  11593. } // 图片已经加载完成
  11594. // if (image.nodeName.toUpperCase() == 'IMG') {
  11595. // if (!image.complete) {
  11596. // return;
  11597. // }
  11598. // }
  11599. // Else is canvas
  11600. var x = style.x || 0;
  11601. var y = style.y || 0;
  11602. var width = style.width;
  11603. var height = style.height;
  11604. var aspect = image.width / image.height;
  11605. if (width == null && height != null) {
  11606. // Keep image/height ratio
  11607. width = height * aspect;
  11608. } else if (height == null && width != null) {
  11609. height = width / aspect;
  11610. } else if (width == null && height == null) {
  11611. width = image.width;
  11612. height = image.height;
  11613. } // 设置transform
  11614. this.setTransform(ctx);
  11615. if (style.sWidth && style.sHeight) {
  11616. var sx = style.sx || 0;
  11617. var sy = style.sy || 0;
  11618. ctx.drawImage(image, sx, sy, style.sWidth, style.sHeight, x, y, width, height);
  11619. } else if (style.sx && style.sy) {
  11620. var sx = style.sx;
  11621. var sy = style.sy;
  11622. var sWidth = width - sx;
  11623. var sHeight = height - sy;
  11624. ctx.drawImage(image, sx, sy, sWidth, sHeight, x, y, width, height);
  11625. } else {
  11626. ctx.drawImage(image, x, y, width, height);
  11627. }
  11628. this.restoreTransform(ctx); // Draw rect text
  11629. if (style.text != null) {
  11630. this.drawRectText(ctx, this.getBoundingRect());
  11631. }
  11632. },
  11633. getBoundingRect: function () {
  11634. var style = this.style;
  11635. if (!this._rect) {
  11636. this._rect = new BoundingRect(style.x || 0, style.y || 0, style.width || 0, style.height || 0);
  11637. }
  11638. return this._rect;
  11639. }
  11640. };
  11641. zrUtil.inherits(ZImage, Displayable);
  11642. var _default = ZImage;
  11643. module.exports = _default;
  11644. /***/ }),
  11645. /* 59 */
  11646. /***/ (function(module, exports, __webpack_require__) {
  11647. var zrUtil = __webpack_require__(0);
  11648. var Element = __webpack_require__(16);
  11649. var BoundingRect = __webpack_require__(3);
  11650. /**
  11651. * Group是一个容器,可以插入子节点,Group的变换也会被应用到子节点上
  11652. * @module zrender/graphic/Group
  11653. * @example
  11654. * var Group = require('zrender/container/Group');
  11655. * var Circle = require('zrender/graphic/shape/Circle');
  11656. * var g = new Group();
  11657. * g.position[0] = 100;
  11658. * g.position[1] = 100;
  11659. * g.add(new Circle({
  11660. * style: {
  11661. * x: 100,
  11662. * y: 100,
  11663. * r: 20,
  11664. * }
  11665. * }));
  11666. * zr.add(g);
  11667. */
  11668. /**
  11669. * @alias module:zrender/graphic/Group
  11670. * @constructor
  11671. * @extends module:zrender/mixin/Transformable
  11672. * @extends module:zrender/mixin/Eventful
  11673. */
  11674. var Group = function (opts) {
  11675. opts = opts || {};
  11676. Element.call(this, opts);
  11677. for (var key in opts) {
  11678. if (opts.hasOwnProperty(key)) {
  11679. this[key] = opts[key];
  11680. }
  11681. }
  11682. this._children = [];
  11683. this.__storage = null;
  11684. this.__dirty = true;
  11685. };
  11686. Group.prototype = {
  11687. constructor: Group,
  11688. isGroup: true,
  11689. /**
  11690. * @type {string}
  11691. */
  11692. type: 'group',
  11693. /**
  11694. * 所有子孙元素是否响应鼠标事件
  11695. * @name module:/zrender/container/Group#silent
  11696. * @type {boolean}
  11697. * @default false
  11698. */
  11699. silent: false,
  11700. /**
  11701. * @return {Array.<module:zrender/Element>}
  11702. */
  11703. children: function () {
  11704. return this._children.slice();
  11705. },
  11706. /**
  11707. * 获取指定 index 的儿子节点
  11708. * @param {number} idx
  11709. * @return {module:zrender/Element}
  11710. */
  11711. childAt: function (idx) {
  11712. return this._children[idx];
  11713. },
  11714. /**
  11715. * 获取指定名字的儿子节点
  11716. * @param {string} name
  11717. * @return {module:zrender/Element}
  11718. */
  11719. childOfName: function (name) {
  11720. var children = this._children;
  11721. for (var i = 0; i < children.length; i++) {
  11722. if (children[i].name === name) {
  11723. return children[i];
  11724. }
  11725. }
  11726. },
  11727. /**
  11728. * @return {number}
  11729. */
  11730. childCount: function () {
  11731. return this._children.length;
  11732. },
  11733. /**
  11734. * 添加子节点到最后
  11735. * @param {module:zrender/Element} child
  11736. */
  11737. add: function (child) {
  11738. if (child && child !== this && child.parent !== this) {
  11739. this._children.push(child);
  11740. this._doAdd(child);
  11741. }
  11742. return this;
  11743. },
  11744. /**
  11745. * 添加子节点在 nextSibling 之前
  11746. * @param {module:zrender/Element} child
  11747. * @param {module:zrender/Element} nextSibling
  11748. */
  11749. addBefore: function (child, nextSibling) {
  11750. if (child && child !== this && child.parent !== this && nextSibling && nextSibling.parent === this) {
  11751. var children = this._children;
  11752. var idx = children.indexOf(nextSibling);
  11753. if (idx >= 0) {
  11754. children.splice(idx, 0, child);
  11755. this._doAdd(child);
  11756. }
  11757. }
  11758. return this;
  11759. },
  11760. _doAdd: function (child) {
  11761. if (child.parent) {
  11762. child.parent.remove(child);
  11763. }
  11764. child.parent = this;
  11765. var storage = this.__storage;
  11766. var zr = this.__zr;
  11767. if (storage && storage !== child.__storage) {
  11768. storage.addToStorage(child);
  11769. if (child instanceof Group) {
  11770. child.addChildrenToStorage(storage);
  11771. }
  11772. }
  11773. zr && zr.refresh();
  11774. },
  11775. /**
  11776. * 移除子节点
  11777. * @param {module:zrender/Element} child
  11778. */
  11779. remove: function (child) {
  11780. var zr = this.__zr;
  11781. var storage = this.__storage;
  11782. var children = this._children;
  11783. var idx = zrUtil.indexOf(children, child);
  11784. if (idx < 0) {
  11785. return this;
  11786. }
  11787. children.splice(idx, 1);
  11788. child.parent = null;
  11789. if (storage) {
  11790. storage.delFromStorage(child);
  11791. if (child instanceof Group) {
  11792. child.delChildrenFromStorage(storage);
  11793. }
  11794. }
  11795. zr && zr.refresh();
  11796. return this;
  11797. },
  11798. /**
  11799. * 移除所有子节点
  11800. */
  11801. removeAll: function () {
  11802. var children = this._children;
  11803. var storage = this.__storage;
  11804. var child;
  11805. var i;
  11806. for (i = 0; i < children.length; i++) {
  11807. child = children[i];
  11808. if (storage) {
  11809. storage.delFromStorage(child);
  11810. if (child instanceof Group) {
  11811. child.delChildrenFromStorage(storage);
  11812. }
  11813. }
  11814. child.parent = null;
  11815. }
  11816. children.length = 0;
  11817. return this;
  11818. },
  11819. /**
  11820. * 遍历所有子节点
  11821. * @param {Function} cb
  11822. * @param {} context
  11823. */
  11824. eachChild: function (cb, context) {
  11825. var children = this._children;
  11826. for (var i = 0; i < children.length; i++) {
  11827. var child = children[i];
  11828. cb.call(context, child, i);
  11829. }
  11830. return this;
  11831. },
  11832. /**
  11833. * 深度优先遍历所有子孙节点
  11834. * @param {Function} cb
  11835. * @param {} context
  11836. */
  11837. traverse: function (cb, context) {
  11838. for (var i = 0; i < this._children.length; i++) {
  11839. var child = this._children[i];
  11840. cb.call(context, child);
  11841. if (child.type === 'group') {
  11842. child.traverse(cb, context);
  11843. }
  11844. }
  11845. return this;
  11846. },
  11847. addChildrenToStorage: function (storage) {
  11848. for (var i = 0; i < this._children.length; i++) {
  11849. var child = this._children[i];
  11850. storage.addToStorage(child);
  11851. if (child instanceof Group) {
  11852. child.addChildrenToStorage(storage);
  11853. }
  11854. }
  11855. },
  11856. delChildrenFromStorage: function (storage) {
  11857. for (var i = 0; i < this._children.length; i++) {
  11858. var child = this._children[i];
  11859. storage.delFromStorage(child);
  11860. if (child instanceof Group) {
  11861. child.delChildrenFromStorage(storage);
  11862. }
  11863. }
  11864. },
  11865. dirty: function () {
  11866. this.__dirty = true;
  11867. this.__zr && this.__zr.refresh();
  11868. return this;
  11869. },
  11870. /**
  11871. * @return {module:zrender/core/BoundingRect}
  11872. */
  11873. getBoundingRect: function (includeChildren) {
  11874. // TODO Caching
  11875. var rect = null;
  11876. var tmpRect = new BoundingRect(0, 0, 0, 0);
  11877. var children = includeChildren || this._children;
  11878. var tmpMat = [];
  11879. for (var i = 0; i < children.length; i++) {
  11880. var child = children[i];
  11881. if (child.ignore || child.invisible) {
  11882. continue;
  11883. }
  11884. var childRect = child.getBoundingRect();
  11885. var transform = child.getLocalTransform(tmpMat); // TODO
  11886. // The boundingRect cacluated by transforming original
  11887. // rect may be bigger than the actual bundingRect when rotation
  11888. // is used. (Consider a circle rotated aginst its center, where
  11889. // the actual boundingRect should be the same as that not be
  11890. // rotated.) But we can not find better approach to calculate
  11891. // actual boundingRect yet, considering performance.
  11892. if (transform) {
  11893. tmpRect.copy(childRect);
  11894. tmpRect.applyTransform(transform);
  11895. rect = rect || tmpRect.clone();
  11896. rect.union(tmpRect);
  11897. } else {
  11898. rect = rect || childRect.clone();
  11899. rect.union(childRect);
  11900. }
  11901. }
  11902. return rect || tmpRect;
  11903. }
  11904. };
  11905. zrUtil.inherits(Group, Element);
  11906. var _default = Group;
  11907. module.exports = _default;
  11908. /***/ }),
  11909. /* 60 */
  11910. /***/ (function(module, exports, __webpack_require__) {
  11911. var Displayable = __webpack_require__(12);
  11912. var zrUtil = __webpack_require__(0);
  11913. var textContain = __webpack_require__(5);
  11914. var textHelper = __webpack_require__(20);
  11915. /**
  11916. * @alias zrender/graphic/Text
  11917. * @extends module:zrender/graphic/Displayable
  11918. * @constructor
  11919. * @param {Object} opts
  11920. */
  11921. var Text = function (opts) {
  11922. // jshint ignore:line
  11923. Displayable.call(this, opts);
  11924. };
  11925. Text.prototype = {
  11926. constructor: Text,
  11927. type: 'text',
  11928. brush: function (ctx, prevEl) {
  11929. var style = this.style; // Optimize, avoid normalize every time.
  11930. this.__dirty && textHelper.normalizeTextStyle(style, true); // Use props with prefix 'text'.
  11931. style.fill = style.stroke = style.shadowBlur = style.shadowColor = style.shadowOffsetX = style.shadowOffsetY = null;
  11932. var text = style.text; // Convert to string
  11933. text != null && (text += ''); // Always bind style
  11934. style.bind(ctx, this, prevEl);
  11935. if (!textHelper.needDrawText(text, style)) {
  11936. return;
  11937. }
  11938. this.setTransform(ctx);
  11939. textHelper.renderText(this, ctx, text, style);
  11940. this.restoreTransform(ctx);
  11941. },
  11942. getBoundingRect: function () {
  11943. var style = this.style; // Optimize, avoid normalize every time.
  11944. this.__dirty && textHelper.normalizeTextStyle(style, true);
  11945. if (!this._rect) {
  11946. var text = style.text;
  11947. text != null ? text += '' : text = '';
  11948. var rect = textContain.getBoundingRect(style.text + '', style.font, style.textAlign, style.textVerticalAlign, style.textPadding, style.rich);
  11949. rect.x += style.x || 0;
  11950. rect.y += style.y || 0;
  11951. if (textHelper.getStroke(style.textStroke, style.textStrokeWidth)) {
  11952. var w = style.textStrokeWidth;
  11953. rect.x -= w / 2;
  11954. rect.y -= w / 2;
  11955. rect.width += w;
  11956. rect.height += w;
  11957. }
  11958. this._rect = rect;
  11959. }
  11960. return this._rect;
  11961. }
  11962. };
  11963. zrUtil.inherits(Text, Displayable);
  11964. var _default = Text;
  11965. module.exports = _default;
  11966. /***/ }),
  11967. /* 61 */
  11968. /***/ (function(module, exports, __webpack_require__) {
  11969. var Path = __webpack_require__(1);
  11970. /**
  11971. * 圆形
  11972. * @module zrender/shape/Circle
  11973. */
  11974. var _default = Path.extend({
  11975. type: 'circle',
  11976. shape: {
  11977. cx: 0,
  11978. cy: 0,
  11979. r: 0
  11980. },
  11981. buildPath: function (ctx, shape, inBundle) {
  11982. // Better stroking in ShapeBundle
  11983. // Always do it may have performence issue ( fill may be 2x more cost)
  11984. if (inBundle) {
  11985. ctx.moveTo(shape.cx + shape.r, shape.cy);
  11986. } // else {
  11987. // if (ctx.allocate && !ctx.data.length) {
  11988. // ctx.allocate(ctx.CMD_MEM_SIZE.A);
  11989. // }
  11990. // }
  11991. // Better stroking in ShapeBundle
  11992. // ctx.moveTo(shape.cx + shape.r, shape.cy);
  11993. ctx.arc(shape.cx, shape.cy, shape.r, 0, Math.PI * 2, true);
  11994. }
  11995. });
  11996. module.exports = _default;
  11997. /***/ }),
  11998. /* 62 */
  11999. /***/ (function(module, exports, __webpack_require__) {
  12000. var Path = __webpack_require__(1);
  12001. var fixClipWithShadow = __webpack_require__(63);
  12002. /**
  12003. * 扇形
  12004. * @module zrender/graphic/shape/Sector
  12005. */
  12006. var _default = Path.extend({
  12007. type: 'sector',
  12008. shape: {
  12009. cx: 0,
  12010. cy: 0,
  12011. r0: 0,
  12012. r: 0,
  12013. startAngle: 0,
  12014. endAngle: Math.PI * 2,
  12015. clockwise: true
  12016. },
  12017. brush: fixClipWithShadow(Path.prototype.brush),
  12018. buildPath: function (ctx, shape) {
  12019. var x = shape.cx;
  12020. var y = shape.cy;
  12021. var r0 = Math.max(shape.r0 || 0, 0);
  12022. var r = Math.max(shape.r, 0);
  12023. var startAngle = shape.startAngle;
  12024. var endAngle = shape.endAngle;
  12025. var clockwise = shape.clockwise;
  12026. var unitX = Math.cos(startAngle);
  12027. var unitY = Math.sin(startAngle);
  12028. ctx.moveTo(unitX * r0 + x, unitY * r0 + y);
  12029. ctx.lineTo(unitX * r + x, unitY * r + y);
  12030. ctx.arc(x, y, r, startAngle, endAngle, !clockwise);
  12031. ctx.lineTo(Math.cos(endAngle) * r0 + x, Math.sin(endAngle) * r0 + y);
  12032. if (r0 !== 0) {
  12033. ctx.arc(x, y, r0, endAngle, startAngle, clockwise);
  12034. }
  12035. ctx.closePath();
  12036. }
  12037. });
  12038. module.exports = _default;
  12039. /***/ }),
  12040. /* 63 */
  12041. /***/ (function(module, exports, __webpack_require__) {
  12042. var env = __webpack_require__(15);
  12043. // Fix weird bug in some version of IE11 (like 11.0.9600.178**),
  12044. // where exception "unexpected call to method or property access"
  12045. // might be thrown when calling ctx.fill or ctx.stroke after a path
  12046. // whose area size is zero is drawn and ctx.clip() is called and
  12047. // shadowBlur is set. See #4572, #3112, #5777.
  12048. // (e.g.,
  12049. // ctx.moveTo(10, 10);
  12050. // ctx.lineTo(20, 10);
  12051. // ctx.closePath();
  12052. // ctx.clip();
  12053. // ctx.shadowBlur = 10;
  12054. // ...
  12055. // ctx.fill();
  12056. // )
  12057. var shadowTemp = [['shadowBlur', 0], ['shadowColor', '#000'], ['shadowOffsetX', 0], ['shadowOffsetY', 0]];
  12058. function _default(orignalBrush) {
  12059. // version string can be: '11.0'
  12060. return env.browser.ie && env.browser.version >= 11 ? function () {
  12061. var clipPaths = this.__clipPaths;
  12062. var style = this.style;
  12063. var modified;
  12064. if (clipPaths) {
  12065. for (var i = 0; i < clipPaths.length; i++) {
  12066. var clipPath = clipPaths[i];
  12067. var shape = clipPath && clipPath.shape;
  12068. var type = clipPath && clipPath.type;
  12069. if (shape && (type === 'sector' && shape.startAngle === shape.endAngle || type === 'rect' && (!shape.width || !shape.height))) {
  12070. for (var j = 0; j < shadowTemp.length; j++) {
  12071. // It is save to put shadowTemp static, because shadowTemp
  12072. // will be all modified each item brush called.
  12073. shadowTemp[j][2] = style[shadowTemp[j][0]];
  12074. style[shadowTemp[j][0]] = shadowTemp[j][1];
  12075. }
  12076. modified = true;
  12077. break;
  12078. }
  12079. }
  12080. }
  12081. orignalBrush.apply(this, arguments);
  12082. if (modified) {
  12083. for (var j = 0; j < shadowTemp.length; j++) {
  12084. style[shadowTemp[j][0]] = shadowTemp[j][2];
  12085. }
  12086. }
  12087. } : orignalBrush;
  12088. }
  12089. module.exports = _default;
  12090. /***/ }),
  12091. /* 64 */
  12092. /***/ (function(module, exports, __webpack_require__) {
  12093. var Path = __webpack_require__(1);
  12094. /**
  12095. * 圆环
  12096. * @module zrender/graphic/shape/Ring
  12097. */
  12098. var _default = Path.extend({
  12099. type: 'ring',
  12100. shape: {
  12101. cx: 0,
  12102. cy: 0,
  12103. r: 0,
  12104. r0: 0
  12105. },
  12106. buildPath: function (ctx, shape) {
  12107. var x = shape.cx;
  12108. var y = shape.cy;
  12109. var PI2 = Math.PI * 2;
  12110. ctx.moveTo(x + shape.r, y);
  12111. ctx.arc(x, y, shape.r, 0, PI2, false);
  12112. ctx.moveTo(x + shape.r0, y);
  12113. ctx.arc(x, y, shape.r0, 0, PI2, true);
  12114. }
  12115. });
  12116. module.exports = _default;
  12117. /***/ }),
  12118. /* 65 */
  12119. /***/ (function(module, exports, __webpack_require__) {
  12120. var Path = __webpack_require__(1);
  12121. var polyHelper = __webpack_require__(23);
  12122. /**
  12123. * 多边形
  12124. * @module zrender/shape/Polygon
  12125. */
  12126. var _default = Path.extend({
  12127. type: 'polygon',
  12128. shape: {
  12129. points: null,
  12130. smooth: false,
  12131. smoothConstraint: null
  12132. },
  12133. buildPath: function (ctx, shape) {
  12134. polyHelper.buildPath(ctx, shape, true);
  12135. }
  12136. });
  12137. module.exports = _default;
  12138. /***/ }),
  12139. /* 66 */
  12140. /***/ (function(module, exports, __webpack_require__) {
  12141. var _vector = __webpack_require__(2);
  12142. var v2Distance = _vector.distance;
  12143. /**
  12144. * Catmull-Rom spline 插值折线
  12145. * @module zrender/shape/util/smoothSpline
  12146. * @author pissang (https://www.github.com/pissang)
  12147. * Kener (@Kener-林峰, kener.linfeng@gmail.com)
  12148. * errorrik (errorrik@gmail.com)
  12149. */
  12150. /**
  12151. * @inner
  12152. */
  12153. function interpolate(p0, p1, p2, p3, t, t2, t3) {
  12154. var v0 = (p2 - p0) * 0.5;
  12155. var v1 = (p3 - p1) * 0.5;
  12156. return (2 * (p1 - p2) + v0 + v1) * t3 + (-3 * (p1 - p2) - 2 * v0 - v1) * t2 + v0 * t + p1;
  12157. }
  12158. /**
  12159. * @alias module:zrender/shape/util/smoothSpline
  12160. * @param {Array} points 线段顶点数组
  12161. * @param {boolean} isLoop
  12162. * @return {Array}
  12163. */
  12164. function _default(points, isLoop) {
  12165. var len = points.length;
  12166. var ret = [];
  12167. var distance = 0;
  12168. for (var i = 1; i < len; i++) {
  12169. distance += v2Distance(points[i - 1], points[i]);
  12170. }
  12171. var segs = distance / 2;
  12172. segs = segs < len ? len : segs;
  12173. for (var i = 0; i < segs; i++) {
  12174. var pos = i / (segs - 1) * (isLoop ? len : len - 1);
  12175. var idx = Math.floor(pos);
  12176. var w = pos - idx;
  12177. var p0;
  12178. var p1 = points[idx % len];
  12179. var p2;
  12180. var p3;
  12181. if (!isLoop) {
  12182. p0 = points[idx === 0 ? idx : idx - 1];
  12183. p2 = points[idx > len - 2 ? len - 1 : idx + 1];
  12184. p3 = points[idx > len - 3 ? len - 1 : idx + 2];
  12185. } else {
  12186. p0 = points[(idx - 1 + len) % len];
  12187. p2 = points[(idx + 1) % len];
  12188. p3 = points[(idx + 2) % len];
  12189. }
  12190. var w2 = w * w;
  12191. var w3 = w * w2;
  12192. ret.push([interpolate(p0[0], p1[0], p2[0], p3[0], w, w2, w3), interpolate(p0[1], p1[1], p2[1], p3[1], w, w2, w3)]);
  12193. }
  12194. return ret;
  12195. }
  12196. module.exports = _default;
  12197. /***/ }),
  12198. /* 67 */
  12199. /***/ (function(module, exports, __webpack_require__) {
  12200. var _vector = __webpack_require__(2);
  12201. var v2Min = _vector.min;
  12202. var v2Max = _vector.max;
  12203. var v2Scale = _vector.scale;
  12204. var v2Distance = _vector.distance;
  12205. var v2Add = _vector.add;
  12206. var v2Clone = _vector.clone;
  12207. var v2Sub = _vector.sub;
  12208. /**
  12209. * 贝塞尔平滑曲线
  12210. * @module zrender/shape/util/smoothBezier
  12211. * @author pissang (https://www.github.com/pissang)
  12212. * Kener (@Kener-林峰, kener.linfeng@gmail.com)
  12213. * errorrik (errorrik@gmail.com)
  12214. */
  12215. /**
  12216. * 贝塞尔平滑曲线
  12217. * @alias module:zrender/shape/util/smoothBezier
  12218. * @param {Array} points 线段顶点数组
  12219. * @param {number} smooth 平滑等级, 0-1
  12220. * @param {boolean} isLoop
  12221. * @param {Array} constraint 将计算出来的控制点约束在一个包围盒内
  12222. * 比如 [[0, 0], [100, 100]], 这个包围盒会与
  12223. * 整个折线的包围盒做一个并集用来约束控制点。
  12224. * @param {Array} 计算出来的控制点数组
  12225. */
  12226. function _default(points, smooth, isLoop, constraint) {
  12227. var cps = [];
  12228. var v = [];
  12229. var v1 = [];
  12230. var v2 = [];
  12231. var prevPoint;
  12232. var nextPoint;
  12233. var min, max;
  12234. if (constraint) {
  12235. min = [Infinity, Infinity];
  12236. max = [-Infinity, -Infinity];
  12237. for (var i = 0, len = points.length; i < len; i++) {
  12238. v2Min(min, min, points[i]);
  12239. v2Max(max, max, points[i]);
  12240. } // 与指定的包围盒做并集
  12241. v2Min(min, min, constraint[0]);
  12242. v2Max(max, max, constraint[1]);
  12243. }
  12244. for (var i = 0, len = points.length; i < len; i++) {
  12245. var point = points[i];
  12246. if (isLoop) {
  12247. prevPoint = points[i ? i - 1 : len - 1];
  12248. nextPoint = points[(i + 1) % len];
  12249. } else {
  12250. if (i === 0 || i === len - 1) {
  12251. cps.push(v2Clone(points[i]));
  12252. continue;
  12253. } else {
  12254. prevPoint = points[i - 1];
  12255. nextPoint = points[i + 1];
  12256. }
  12257. }
  12258. v2Sub(v, nextPoint, prevPoint); // use degree to scale the handle length
  12259. v2Scale(v, v, smooth);
  12260. var d0 = v2Distance(point, prevPoint);
  12261. var d1 = v2Distance(point, nextPoint);
  12262. var sum = d0 + d1;
  12263. if (sum !== 0) {
  12264. d0 /= sum;
  12265. d1 /= sum;
  12266. }
  12267. v2Scale(v1, v, -d0);
  12268. v2Scale(v2, v, d1);
  12269. var cp0 = v2Add([], point, v1);
  12270. var cp1 = v2Add([], point, v2);
  12271. if (constraint) {
  12272. v2Max(cp0, cp0, min);
  12273. v2Min(cp0, cp0, max);
  12274. v2Max(cp1, cp1, min);
  12275. v2Min(cp1, cp1, max);
  12276. }
  12277. cps.push(cp0);
  12278. cps.push(cp1);
  12279. }
  12280. if (isLoop) {
  12281. cps.push(cps.shift());
  12282. }
  12283. return cps;
  12284. }
  12285. module.exports = _default;
  12286. /***/ }),
  12287. /* 68 */
  12288. /***/ (function(module, exports, __webpack_require__) {
  12289. var Path = __webpack_require__(1);
  12290. var polyHelper = __webpack_require__(23);
  12291. /**
  12292. * @module zrender/graphic/shape/Polyline
  12293. */
  12294. var _default = Path.extend({
  12295. type: 'polyline',
  12296. shape: {
  12297. points: null,
  12298. smooth: false,
  12299. smoothConstraint: null
  12300. },
  12301. style: {
  12302. stroke: '#000',
  12303. fill: null
  12304. },
  12305. buildPath: function (ctx, shape) {
  12306. polyHelper.buildPath(ctx, shape, false);
  12307. }
  12308. });
  12309. module.exports = _default;
  12310. /***/ }),
  12311. /* 69 */
  12312. /***/ (function(module, exports, __webpack_require__) {
  12313. var Path = __webpack_require__(1);
  12314. var roundRectHelper = __webpack_require__(21);
  12315. /**
  12316. * 矩形
  12317. * @module zrender/graphic/shape/Rect
  12318. */
  12319. var _default = Path.extend({
  12320. type: 'rect',
  12321. shape: {
  12322. // 左上、右上、右下、左下角的半径依次为r1、r2、r3、r4
  12323. // r缩写为1 相当于 [1, 1, 1, 1]
  12324. // r缩写为[1] 相当于 [1, 1, 1, 1]
  12325. // r缩写为[1, 2] 相当于 [1, 2, 1, 2]
  12326. // r缩写为[1, 2, 3] 相当于 [1, 2, 3, 2]
  12327. r: 0,
  12328. x: 0,
  12329. y: 0,
  12330. width: 0,
  12331. height: 0
  12332. },
  12333. buildPath: function (ctx, shape) {
  12334. var x = shape.x;
  12335. var y = shape.y;
  12336. var width = shape.width;
  12337. var height = shape.height;
  12338. if (!shape.r) {
  12339. ctx.rect(x, y, width, height);
  12340. } else {
  12341. roundRectHelper.buildPath(ctx, shape);
  12342. }
  12343. ctx.closePath();
  12344. return;
  12345. }
  12346. });
  12347. module.exports = _default;
  12348. /***/ }),
  12349. /* 70 */
  12350. /***/ (function(module, exports, __webpack_require__) {
  12351. var Path = __webpack_require__(1);
  12352. /**
  12353. * 直线
  12354. * @module zrender/graphic/shape/Line
  12355. */
  12356. var _default = Path.extend({
  12357. type: 'line',
  12358. shape: {
  12359. // Start point
  12360. x1: 0,
  12361. y1: 0,
  12362. // End point
  12363. x2: 0,
  12364. y2: 0,
  12365. percent: 1
  12366. },
  12367. style: {
  12368. stroke: '#000',
  12369. fill: null
  12370. },
  12371. buildPath: function (ctx, shape) {
  12372. var x1 = shape.x1;
  12373. var y1 = shape.y1;
  12374. var x2 = shape.x2;
  12375. var y2 = shape.y2;
  12376. var percent = shape.percent;
  12377. if (percent === 0) {
  12378. return;
  12379. }
  12380. ctx.moveTo(x1, y1);
  12381. if (percent < 1) {
  12382. x2 = x1 * (1 - percent) + x2 * percent;
  12383. y2 = y1 * (1 - percent) + y2 * percent;
  12384. }
  12385. ctx.lineTo(x2, y2);
  12386. },
  12387. /**
  12388. * Get point at percent
  12389. * @param {number} percent
  12390. * @return {Array.<number>}
  12391. */
  12392. pointAt: function (p) {
  12393. var shape = this.shape;
  12394. return [shape.x1 * (1 - p) + shape.x2 * p, shape.y1 * (1 - p) + shape.y2 * p];
  12395. }
  12396. });
  12397. module.exports = _default;
  12398. /***/ }),
  12399. /* 71 */
  12400. /***/ (function(module, exports, __webpack_require__) {
  12401. var Path = __webpack_require__(1);
  12402. var vec2 = __webpack_require__(2);
  12403. var _curve = __webpack_require__(4);
  12404. var quadraticSubdivide = _curve.quadraticSubdivide;
  12405. var cubicSubdivide = _curve.cubicSubdivide;
  12406. var quadraticAt = _curve.quadraticAt;
  12407. var cubicAt = _curve.cubicAt;
  12408. var quadraticDerivativeAt = _curve.quadraticDerivativeAt;
  12409. var cubicDerivativeAt = _curve.cubicDerivativeAt;
  12410. /**
  12411. * 贝塞尔曲线
  12412. * @module zrender/shape/BezierCurve
  12413. */
  12414. var out = [];
  12415. function someVectorAt(shape, t, isTangent) {
  12416. var cpx2 = shape.cpx2;
  12417. var cpy2 = shape.cpy2;
  12418. if (cpx2 === null || cpy2 === null) {
  12419. return [(isTangent ? cubicDerivativeAt : cubicAt)(shape.x1, shape.cpx1, shape.cpx2, shape.x2, t), (isTangent ? cubicDerivativeAt : cubicAt)(shape.y1, shape.cpy1, shape.cpy2, shape.y2, t)];
  12420. } else {
  12421. return [(isTangent ? quadraticDerivativeAt : quadraticAt)(shape.x1, shape.cpx1, shape.x2, t), (isTangent ? quadraticDerivativeAt : quadraticAt)(shape.y1, shape.cpy1, shape.y2, t)];
  12422. }
  12423. }
  12424. var _default = Path.extend({
  12425. type: 'bezier-curve',
  12426. shape: {
  12427. x1: 0,
  12428. y1: 0,
  12429. x2: 0,
  12430. y2: 0,
  12431. cpx1: 0,
  12432. cpy1: 0,
  12433. // cpx2: 0,
  12434. // cpy2: 0
  12435. // Curve show percent, for animating
  12436. percent: 1
  12437. },
  12438. style: {
  12439. stroke: '#000',
  12440. fill: null
  12441. },
  12442. buildPath: function (ctx, shape) {
  12443. var x1 = shape.x1;
  12444. var y1 = shape.y1;
  12445. var x2 = shape.x2;
  12446. var y2 = shape.y2;
  12447. var cpx1 = shape.cpx1;
  12448. var cpy1 = shape.cpy1;
  12449. var cpx2 = shape.cpx2;
  12450. var cpy2 = shape.cpy2;
  12451. var percent = shape.percent;
  12452. if (percent === 0) {
  12453. return;
  12454. }
  12455. ctx.moveTo(x1, y1);
  12456. if (cpx2 == null || cpy2 == null) {
  12457. if (percent < 1) {
  12458. quadraticSubdivide(x1, cpx1, x2, percent, out);
  12459. cpx1 = out[1];
  12460. x2 = out[2];
  12461. quadraticSubdivide(y1, cpy1, y2, percent, out);
  12462. cpy1 = out[1];
  12463. y2 = out[2];
  12464. }
  12465. ctx.quadraticCurveTo(cpx1, cpy1, x2, y2);
  12466. } else {
  12467. if (percent < 1) {
  12468. cubicSubdivide(x1, cpx1, cpx2, x2, percent, out);
  12469. cpx1 = out[1];
  12470. cpx2 = out[2];
  12471. x2 = out[3];
  12472. cubicSubdivide(y1, cpy1, cpy2, y2, percent, out);
  12473. cpy1 = out[1];
  12474. cpy2 = out[2];
  12475. y2 = out[3];
  12476. }
  12477. ctx.bezierCurveTo(cpx1, cpy1, cpx2, cpy2, x2, y2);
  12478. }
  12479. },
  12480. /**
  12481. * Get point at percent
  12482. * @param {number} t
  12483. * @return {Array.<number>}
  12484. */
  12485. pointAt: function (t) {
  12486. return someVectorAt(this.shape, t, false);
  12487. },
  12488. /**
  12489. * Get tangent at percent
  12490. * @param {number} t
  12491. * @return {Array.<number>}
  12492. */
  12493. tangentAt: function (t) {
  12494. var p = someVectorAt(this.shape, t, true);
  12495. return vec2.normalize(p, p);
  12496. }
  12497. });
  12498. module.exports = _default;
  12499. /***/ }),
  12500. /* 72 */
  12501. /***/ (function(module, exports, __webpack_require__) {
  12502. var Path = __webpack_require__(1);
  12503. /**
  12504. * 圆弧
  12505. * @module zrender/graphic/shape/Arc
  12506. */
  12507. var _default = Path.extend({
  12508. type: 'arc',
  12509. shape: {
  12510. cx: 0,
  12511. cy: 0,
  12512. r: 0,
  12513. startAngle: 0,
  12514. endAngle: Math.PI * 2,
  12515. clockwise: true
  12516. },
  12517. style: {
  12518. stroke: '#000',
  12519. fill: null
  12520. },
  12521. buildPath: function (ctx, shape) {
  12522. var x = shape.cx;
  12523. var y = shape.cy;
  12524. var r = Math.max(shape.r, 0);
  12525. var startAngle = shape.startAngle;
  12526. var endAngle = shape.endAngle;
  12527. var clockwise = shape.clockwise;
  12528. var unitX = Math.cos(startAngle);
  12529. var unitY = Math.sin(startAngle);
  12530. ctx.moveTo(unitX * r + x, unitY * r + y);
  12531. ctx.arc(x, y, r, startAngle, endAngle, !clockwise);
  12532. }
  12533. });
  12534. module.exports = _default;
  12535. /***/ }),
  12536. /* 73 */
  12537. /***/ (function(module, exports, __webpack_require__) {
  12538. var Path = __webpack_require__(1);
  12539. // CompoundPath to improve performance
  12540. var _default = Path.extend({
  12541. type: 'compound',
  12542. shape: {
  12543. paths: null
  12544. },
  12545. _updatePathDirty: function () {
  12546. var dirtyPath = this.__dirtyPath;
  12547. var paths = this.shape.paths;
  12548. for (var i = 0; i < paths.length; i++) {
  12549. // Mark as dirty if any subpath is dirty
  12550. dirtyPath = dirtyPath || paths[i].__dirtyPath;
  12551. }
  12552. this.__dirtyPath = dirtyPath;
  12553. this.__dirty = this.__dirty || dirtyPath;
  12554. },
  12555. beforeBrush: function () {
  12556. this._updatePathDirty();
  12557. var paths = this.shape.paths || [];
  12558. var scale = this.getGlobalScale(); // Update path scale
  12559. for (var i = 0; i < paths.length; i++) {
  12560. if (!paths[i].path) {
  12561. paths[i].createPathProxy();
  12562. }
  12563. paths[i].path.setScale(scale[0], scale[1]);
  12564. }
  12565. },
  12566. buildPath: function (ctx, shape) {
  12567. var paths = shape.paths || [];
  12568. for (var i = 0; i < paths.length; i++) {
  12569. paths[i].buildPath(ctx, paths[i].shape, true);
  12570. }
  12571. },
  12572. afterBrush: function () {
  12573. var paths = this.shape.paths || [];
  12574. for (var i = 0; i < paths.length; i++) {
  12575. paths[i].__dirtyPath = false;
  12576. }
  12577. },
  12578. getBoundingRect: function () {
  12579. this._updatePathDirty();
  12580. return Path.prototype.getBoundingRect.call(this);
  12581. }
  12582. });
  12583. module.exports = _default;
  12584. /***/ }),
  12585. /* 74 */
  12586. /***/ (function(module, exports, __webpack_require__) {
  12587. var zrUtil = __webpack_require__(0);
  12588. var Gradient = __webpack_require__(24);
  12589. /**
  12590. * x, y, x2, y2 are all percent from 0 to 1
  12591. * @param {number} [x=0]
  12592. * @param {number} [y=0]
  12593. * @param {number} [x2=1]
  12594. * @param {number} [y2=0]
  12595. * @param {Array.<Object>} colorStops
  12596. * @param {boolean} [globalCoord=false]
  12597. */
  12598. var LinearGradient = function (x, y, x2, y2, colorStops, globalCoord) {
  12599. // Should do nothing more in this constructor. Because gradient can be
  12600. // declard by `color: {type: 'linear', colorStops: ...}`, where
  12601. // this constructor will not be called.
  12602. this.x = x == null ? 0 : x;
  12603. this.y = y == null ? 0 : y;
  12604. this.x2 = x2 == null ? 1 : x2;
  12605. this.y2 = y2 == null ? 0 : y2; // Can be cloned
  12606. this.type = 'linear'; // If use global coord
  12607. this.global = globalCoord || false;
  12608. Gradient.call(this, colorStops);
  12609. };
  12610. LinearGradient.prototype = {
  12611. constructor: LinearGradient
  12612. };
  12613. zrUtil.inherits(LinearGradient, Gradient);
  12614. var _default = LinearGradient;
  12615. module.exports = _default;
  12616. /***/ }),
  12617. /* 75 */
  12618. /***/ (function(module, exports, __webpack_require__) {
  12619. var zrUtil = __webpack_require__(0);
  12620. var Gradient = __webpack_require__(24);
  12621. /**
  12622. * x, y, r are all percent from 0 to 1
  12623. * @param {number} [x=0.5]
  12624. * @param {number} [y=0.5]
  12625. * @param {number} [r=0.5]
  12626. * @param {Array.<Object>} [colorStops]
  12627. * @param {boolean} [globalCoord=false]
  12628. */
  12629. var RadialGradient = function (x, y, r, colorStops, globalCoord) {
  12630. // Should do nothing more in this constructor. Because gradient can be
  12631. // declard by `color: {type: 'radial', colorStops: ...}`, where
  12632. // this constructor will not be called.
  12633. this.x = x == null ? 0.5 : x;
  12634. this.y = y == null ? 0.5 : y;
  12635. this.r = r == null ? 0.5 : r; // Can be cloned
  12636. this.type = 'radial'; // If use global coord
  12637. this.global = globalCoord || false;
  12638. Gradient.call(this, colorStops);
  12639. };
  12640. RadialGradient.prototype = {
  12641. constructor: RadialGradient
  12642. };
  12643. zrUtil.inherits(RadialGradient, Gradient);
  12644. var _default = RadialGradient;
  12645. module.exports = _default;
  12646. /***/ }),
  12647. /* 76 */
  12648. /***/ (function(module, exports, __webpack_require__) {
  12649. var makeStyleMapper = __webpack_require__(11);
  12650. var getItemStyle = makeStyleMapper([['fill', 'color'], ['stroke', 'borderColor'], ['lineWidth', 'borderWidth'], ['opacity'], ['shadowBlur'], ['shadowOffsetX'], ['shadowOffsetY'], ['shadowColor'], ['textPosition'], ['textAlign']]);
  12651. var _default = {
  12652. getItemStyle: function (excludes, includes) {
  12653. var style = getItemStyle(this, excludes, includes);
  12654. var lineDash = this.getBorderLineDash();
  12655. lineDash && (style.lineDash = lineDash);
  12656. return style;
  12657. },
  12658. getBorderLineDash: function () {
  12659. var lineType = this.get('borderType');
  12660. return lineType === 'solid' || lineType == null ? null : lineType === 'dashed' ? [5, 5] : [1, 1];
  12661. }
  12662. };
  12663. module.exports = _default;
  12664. /***/ }),
  12665. /* 77 */
  12666. /***/ (function(module, exports, __webpack_require__) {
  12667. var echarts = __webpack_require__(7);
  12668. function getShallow(model, path) {
  12669. return model && model.getShallow(path);
  12670. }
  12671. echarts.extendChartView({
  12672. type: 'wordCloud',
  12673. render: function (seriesModel, ecModel, api) {
  12674. var group = this.group;
  12675. group.removeAll();
  12676. var data = seriesModel.getData();
  12677. var gridSize = seriesModel.get('gridSize');
  12678. seriesModel.layoutInstance.ondraw = function (text, size, dataIdx, drawn) {
  12679. var itemModel = data.getItemModel(dataIdx);
  12680. var textStyleModel = itemModel.getModel('textStyle.normal');
  12681. var emphasisTextStyleModel = itemModel.getModel('textStyle.emphasis');
  12682. var textEl = new echarts.graphic.Text({
  12683. style: echarts.graphic.setTextStyle({}, textStyleModel, {
  12684. x: drawn.info.fillTextOffsetX,
  12685. y: drawn.info.fillTextOffsetY + size * 0.5,
  12686. text: text,
  12687. textBaseline: 'middle',
  12688. textFill: data.getItemVisual(dataIdx, 'color'),
  12689. fontSize: size
  12690. }),
  12691. scale: [1 / drawn.info.mu, 1 / drawn.info.mu],
  12692. position: [
  12693. (drawn.gx + drawn.info.gw / 2) * gridSize,
  12694. (drawn.gy + drawn.info.gh / 2) * gridSize
  12695. ],
  12696. rotation: drawn.rot
  12697. });
  12698. group.add(textEl);
  12699. data.setItemGraphicEl(dataIdx, textEl);
  12700. echarts.graphic.setHoverStyle(
  12701. textEl,
  12702. echarts.graphic.setTextStyle({}, emphasisTextStyleModel, null, {forMerge: true}, true)
  12703. );
  12704. };
  12705. this._model = seriesModel;
  12706. },
  12707. remove: function () {
  12708. this.group.removeAll();
  12709. this._model.layoutInstance.dispose();
  12710. },
  12711. dispose: function () {
  12712. this._model.layoutInstance.dispose();
  12713. }
  12714. });
  12715. /***/ }),
  12716. /* 78 */
  12717. /***/ (function(module, exports, __webpack_require__) {
  12718. "use strict";
  12719. var __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_DEFINE_RESULT__;/*!
  12720. * wordcloud2.js
  12721. * http://timdream.org/wordcloud2.js/
  12722. *
  12723. * Copyright 2011 - 2013 Tim Chien
  12724. * Released under the MIT license
  12725. */
  12726. // setImmediate
  12727. if (!window.setImmediate) {
  12728. window.setImmediate = (function setupSetImmediate() {
  12729. return window.msSetImmediate ||
  12730. window.webkitSetImmediate ||
  12731. window.mozSetImmediate ||
  12732. window.oSetImmediate ||
  12733. (function setupSetZeroTimeout() {
  12734. if (!window.postMessage || !window.addEventListener) {
  12735. return null;
  12736. }
  12737. var callbacks = [undefined];
  12738. var message = 'zero-timeout-message';
  12739. // Like setTimeout, but only takes a function argument. There's
  12740. // no time argument (always zero) and no arguments (you have to
  12741. // use a closure).
  12742. var setZeroTimeout = function setZeroTimeout(callback) {
  12743. var id = callbacks.length;
  12744. callbacks.push(callback);
  12745. window.postMessage(message + id.toString(36), '*');
  12746. return id;
  12747. };
  12748. window.addEventListener('message', function setZeroTimeoutMessage(evt) {
  12749. // Skipping checking event source, retarded IE confused this window
  12750. // object with another in the presence of iframe
  12751. if (typeof evt.data !== 'string' ||
  12752. evt.data.substr(0, message.length) !== message/* ||
  12753. evt.source !== window */) {
  12754. return;
  12755. }
  12756. evt.stopImmediatePropagation();
  12757. var id = parseInt(evt.data.substr(message.length), 36);
  12758. if (!callbacks[id]) {
  12759. return;
  12760. }
  12761. callbacks[id]();
  12762. callbacks[id] = undefined;
  12763. }, true);
  12764. /* specify clearImmediate() here since we need the scope */
  12765. window.clearImmediate = function clearZeroTimeout(id) {
  12766. if (!callbacks[id]) {
  12767. return;
  12768. }
  12769. callbacks[id] = undefined;
  12770. };
  12771. return setZeroTimeout;
  12772. })() ||
  12773. // fallback
  12774. function setImmediateFallback(fn) {
  12775. window.setTimeout(fn, 0);
  12776. };
  12777. })();
  12778. }
  12779. if (!window.clearImmediate) {
  12780. window.clearImmediate = (function setupClearImmediate() {
  12781. return window.msClearImmediate ||
  12782. window.webkitClearImmediate ||
  12783. window.mozClearImmediate ||
  12784. window.oClearImmediate ||
  12785. // "clearZeroTimeout" is implement on the previous block ||
  12786. // fallback
  12787. function clearImmediateFallback(timer) {
  12788. window.clearTimeout(timer);
  12789. };
  12790. })();
  12791. }
  12792. (function(global) {
  12793. // Check if WordCloud can run on this browser
  12794. var isSupported = (function isSupported() {
  12795. var canvas = document.createElement('canvas');
  12796. if (!canvas || !canvas.getContext) {
  12797. return false;
  12798. }
  12799. var ctx = canvas.getContext('2d');
  12800. if (!ctx.getImageData) {
  12801. return false;
  12802. }
  12803. if (!ctx.fillText) {
  12804. return false;
  12805. }
  12806. if (!Array.prototype.some) {
  12807. return false;
  12808. }
  12809. if (!Array.prototype.push) {
  12810. return false;
  12811. }
  12812. return true;
  12813. }());
  12814. // Find out if the browser impose minium font size by
  12815. // drawing small texts on a canvas and measure it's width.
  12816. var minFontSize = (function getMinFontSize() {
  12817. if (!isSupported) {
  12818. return;
  12819. }
  12820. var ctx = document.createElement('canvas').getContext('2d');
  12821. // start from 20
  12822. var size = 20;
  12823. // two sizes to measure
  12824. var hanWidth, mWidth;
  12825. while (size) {
  12826. ctx.font = size.toString(10) + 'px sans-serif';
  12827. if ((ctx.measureText('\uFF37').width === hanWidth) &&
  12828. (ctx.measureText('m').width) === mWidth) {
  12829. return (size + 1);
  12830. }
  12831. hanWidth = ctx.measureText('\uFF37').width;
  12832. mWidth = ctx.measureText('m').width;
  12833. size--;
  12834. }
  12835. return 0;
  12836. })();
  12837. // Based on http://jsfromhell.com/array/shuffle
  12838. var shuffleArray = function shuffleArray(arr) {
  12839. for (var j, x, i = arr.length; i;
  12840. j = Math.floor(Math.random() * i),
  12841. x = arr[--i], arr[i] = arr[j],
  12842. arr[j] = x) {}
  12843. return arr;
  12844. };
  12845. var WordCloud = function WordCloud(elements, options) {
  12846. if (!isSupported) {
  12847. return;
  12848. }
  12849. if (!Array.isArray(elements)) {
  12850. elements = [elements];
  12851. }
  12852. elements.forEach(function(el, i) {
  12853. if (typeof el === 'string') {
  12854. elements[i] = document.getElementById(el);
  12855. if (!elements[i]) {
  12856. throw 'The element id specified is not found.';
  12857. }
  12858. } else if (!el.tagName && !el.appendChild) {
  12859. throw 'You must pass valid HTML elements, or ID of the element.';
  12860. }
  12861. });
  12862. /* Default values to be overwritten by options object */
  12863. var settings = {
  12864. list: [],
  12865. fontFamily: '"Trebuchet MS", "Heiti TC", "微軟正黑體", ' +
  12866. '"Arial Unicode MS", "Droid Fallback Sans", sans-serif',
  12867. fontWeight: 'normal',
  12868. color: 'random-dark',
  12869. minSize: 0, // 0 to disable
  12870. weightFactor: 1,
  12871. clearCanvas: true,
  12872. backgroundColor: '#fff', // opaque white = rgba(255, 255, 255, 1)
  12873. gridSize: 8,
  12874. drawOutOfBound: false,
  12875. origin: null,
  12876. drawMask: false,
  12877. maskColor: 'rgba(255,0,0,0.3)',
  12878. maskGapWidth: 0.3,
  12879. wait: 0,
  12880. abortThreshold: 0, // disabled
  12881. abort: function noop() {},
  12882. minRotation: - Math.PI / 2,
  12883. maxRotation: Math.PI / 2,
  12884. rotationStep: 0.1,
  12885. shuffle: true,
  12886. rotateRatio: 0.1,
  12887. shape: 'circle',
  12888. ellipticity: 0.65,
  12889. classes: null,
  12890. hover: null,
  12891. click: null
  12892. };
  12893. if (options) {
  12894. for (var key in options) {
  12895. if (key in settings) {
  12896. settings[key] = options[key];
  12897. }
  12898. }
  12899. }
  12900. /* Convert weightFactor into a function */
  12901. if (typeof settings.weightFactor !== 'function') {
  12902. var factor = settings.weightFactor;
  12903. settings.weightFactor = function weightFactor(pt) {
  12904. return pt * factor; //in px
  12905. };
  12906. }
  12907. /* Convert shape into a function */
  12908. if (typeof settings.shape !== 'function') {
  12909. switch (settings.shape) {
  12910. case 'circle':
  12911. /* falls through */
  12912. default:
  12913. // 'circle' is the default and a shortcut in the code loop.
  12914. settings.shape = 'circle';
  12915. break;
  12916. case 'cardioid':
  12917. settings.shape = function shapeCardioid(theta) {
  12918. return 1 - Math.sin(theta);
  12919. };
  12920. break;
  12921. /*
  12922. To work out an X-gon, one has to calculate "m",
  12923. where 1/(cos(2*PI/X)+m*sin(2*PI/X)) = 1/(cos(0)+m*sin(0))
  12924. http://www.wolframalpha.com/input/?i=1%2F%28cos%282*PI%2FX%29%2Bm*sin%28
  12925. 2*PI%2FX%29%29+%3D+1%2F%28cos%280%29%2Bm*sin%280%29%29
  12926. Copy the solution into polar equation r = 1/(cos(t') + m*sin(t'))
  12927. where t' equals to mod(t, 2PI/X);
  12928. */
  12929. case 'diamond':
  12930. case 'square':
  12931. // http://www.wolframalpha.com/input/?i=plot+r+%3D+1%2F%28cos%28mod+
  12932. // %28t%2C+PI%2F2%29%29%2Bsin%28mod+%28t%2C+PI%2F2%29%29%29%2C+t+%3D
  12933. // +0+..+2*PI
  12934. settings.shape = function shapeSquare(theta) {
  12935. var thetaPrime = theta % (2 * Math.PI / 4);
  12936. return 1 / (Math.cos(thetaPrime) + Math.sin(thetaPrime));
  12937. };
  12938. break;
  12939. case 'triangle-forward':
  12940. // http://www.wolframalpha.com/input/?i=plot+r+%3D+1%2F%28cos%28mod+
  12941. // %28t%2C+2*PI%2F3%29%29%2Bsqrt%283%29sin%28mod+%28t%2C+2*PI%2F3%29
  12942. // %29%29%2C+t+%3D+0+..+2*PI
  12943. settings.shape = function shapeTriangle(theta) {
  12944. var thetaPrime = theta % (2 * Math.PI / 3);
  12945. return 1 / (Math.cos(thetaPrime) +
  12946. Math.sqrt(3) * Math.sin(thetaPrime));
  12947. };
  12948. break;
  12949. case 'triangle':
  12950. case 'triangle-upright':
  12951. settings.shape = function shapeTriangle(theta) {
  12952. var thetaPrime = (theta + Math.PI * 3 / 2) % (2 * Math.PI / 3);
  12953. return 1 / (Math.cos(thetaPrime) +
  12954. Math.sqrt(3) * Math.sin(thetaPrime));
  12955. };
  12956. break;
  12957. case 'pentagon':
  12958. settings.shape = function shapePentagon(theta) {
  12959. var thetaPrime = (theta + 0.955) % (2 * Math.PI / 5);
  12960. return 1 / (Math.cos(thetaPrime) +
  12961. 0.726543 * Math.sin(thetaPrime));
  12962. };
  12963. break;
  12964. case 'star':
  12965. settings.shape = function shapeStar(theta) {
  12966. var thetaPrime = (theta + 0.955) % (2 * Math.PI / 10);
  12967. if ((theta + 0.955) % (2 * Math.PI / 5) - (2 * Math.PI / 10) >= 0) {
  12968. return 1 / (Math.cos((2 * Math.PI / 10) - thetaPrime) +
  12969. 3.07768 * Math.sin((2 * Math.PI / 10) - thetaPrime));
  12970. } else {
  12971. return 1 / (Math.cos(thetaPrime) +
  12972. 3.07768 * Math.sin(thetaPrime));
  12973. }
  12974. };
  12975. break;
  12976. }
  12977. }
  12978. /* Make sure gridSize is a whole number and is not smaller than 4px */
  12979. settings.gridSize = Math.max(Math.floor(settings.gridSize), 4);
  12980. /* shorthand */
  12981. var g = settings.gridSize;
  12982. var maskRectWidth = g - settings.maskGapWidth;
  12983. /* normalize rotation settings */
  12984. var rotationRange = Math.abs(settings.maxRotation - settings.minRotation);
  12985. var minRotation = Math.min(settings.maxRotation, settings.minRotation);
  12986. var rotationStep = settings.rotationStep;
  12987. /* information/object available to all functions, set when start() */
  12988. var grid, // 2d array containing filling information
  12989. ngx, ngy, // width and height of the grid
  12990. center, // position of the center of the cloud
  12991. maxRadius;
  12992. /* timestamp for measuring each putWord() action */
  12993. var escapeTime;
  12994. /* function for getting the color of the text */
  12995. var getTextColor;
  12996. function random_hsl_color(min, max) {
  12997. return 'hsl(' +
  12998. (Math.random() * 360).toFixed() + ',' +
  12999. (Math.random() * 30 + 70).toFixed() + '%,' +
  13000. (Math.random() * (max - min) + min).toFixed() + '%)';
  13001. }
  13002. switch (settings.color) {
  13003. case 'random-dark':
  13004. getTextColor = function getRandomDarkColor() {
  13005. return random_hsl_color(10, 50);
  13006. };
  13007. break;
  13008. case 'random-light':
  13009. getTextColor = function getRandomLightColor() {
  13010. return random_hsl_color(50, 90);
  13011. };
  13012. break;
  13013. default:
  13014. if (typeof settings.color === 'function') {
  13015. getTextColor = settings.color;
  13016. }
  13017. break;
  13018. }
  13019. /* function for getting the classes of the text */
  13020. var getTextClasses = null;
  13021. if (typeof settings.classes === 'function') {
  13022. getTextClasses = settings.classes;
  13023. }
  13024. /* Interactive */
  13025. var interactive = false;
  13026. var infoGrid = [];
  13027. var hovered;
  13028. var getInfoGridFromMouseTouchEvent =
  13029. function getInfoGridFromMouseTouchEvent(evt) {
  13030. var canvas = evt.currentTarget;
  13031. var rect = canvas.getBoundingClientRect();
  13032. var clientX;
  13033. var clientY;
  13034. /** Detect if touches are available */
  13035. if (evt.touches) {
  13036. clientX = evt.touches[0].clientX;
  13037. clientY = evt.touches[0].clientY;
  13038. } else {
  13039. clientX = evt.clientX;
  13040. clientY = evt.clientY;
  13041. }
  13042. var eventX = clientX - rect.left;
  13043. var eventY = clientY - rect.top;
  13044. var x = Math.floor(eventX * ((canvas.width / rect.width) || 1) / g);
  13045. var y = Math.floor(eventY * ((canvas.height / rect.height) || 1) / g);
  13046. return infoGrid[x][y];
  13047. };
  13048. var wordcloudhover = function wordcloudhover(evt) {
  13049. var info = getInfoGridFromMouseTouchEvent(evt);
  13050. if (hovered === info) {
  13051. return;
  13052. }
  13053. hovered = info;
  13054. if (!info) {
  13055. settings.hover(undefined, undefined, evt);
  13056. return;
  13057. }
  13058. settings.hover(info.item, info.dimension, evt);
  13059. };
  13060. var wordcloudclick = function wordcloudclick(evt) {
  13061. var info = getInfoGridFromMouseTouchEvent(evt);
  13062. if (!info) {
  13063. return;
  13064. }
  13065. settings.click(info.item, info.dimension, evt);
  13066. evt.preventDefault();
  13067. };
  13068. /* Get points on the grid for a given radius away from the center */
  13069. var pointsAtRadius = [];
  13070. var getPointsAtRadius = function getPointsAtRadius(radius) {
  13071. if (pointsAtRadius[radius]) {
  13072. return pointsAtRadius[radius];
  13073. }
  13074. // Look for these number of points on each radius
  13075. var T = radius * 8;
  13076. // Getting all the points at this radius
  13077. var t = T;
  13078. var points = [];
  13079. if (radius === 0) {
  13080. points.push([center[0], center[1], 0]);
  13081. }
  13082. while (t--) {
  13083. // distort the radius to put the cloud in shape
  13084. var rx = 1;
  13085. if (settings.shape !== 'circle') {
  13086. rx = settings.shape(t / T * 2 * Math.PI); // 0 to 1
  13087. }
  13088. // Push [x, y, t]; t is used solely for getTextColor()
  13089. points.push([
  13090. center[0] + radius * rx * Math.cos(-t / T * 2 * Math.PI),
  13091. center[1] + radius * rx * Math.sin(-t / T * 2 * Math.PI) *
  13092. settings.ellipticity,
  13093. t / T * 2 * Math.PI]);
  13094. }
  13095. pointsAtRadius[radius] = points;
  13096. return points;
  13097. };
  13098. /* Return true if we had spent too much time */
  13099. var exceedTime = function exceedTime() {
  13100. return ((settings.abortThreshold > 0) &&
  13101. ((new Date()).getTime() - escapeTime > settings.abortThreshold));
  13102. };
  13103. /* Get the deg of rotation according to settings, and luck. */
  13104. var getRotateDeg = function getRotateDeg() {
  13105. if (settings.rotateRatio === 0) {
  13106. return 0;
  13107. }
  13108. if (Math.random() > settings.rotateRatio) {
  13109. return 0;
  13110. }
  13111. if (rotationRange === 0) {
  13112. return minRotation;
  13113. }
  13114. return minRotation + Math.round(Math.random() * rotationRange / rotationStep) * rotationStep;
  13115. };
  13116. var getTextInfo = function getTextInfo(word, weight, rotateDeg) {
  13117. // calculate the acutal font size
  13118. // fontSize === 0 means weightFactor function wants the text skipped,
  13119. // and size < minSize means we cannot draw the text.
  13120. var debug = false;
  13121. var fontSize = settings.weightFactor(weight);
  13122. if (fontSize <= settings.minSize) {
  13123. return false;
  13124. }
  13125. // Scale factor here is to make sure fillText is not limited by
  13126. // the minium font size set by browser.
  13127. // It will always be 1 or 2n.
  13128. var mu = 1;
  13129. if (fontSize < minFontSize) {
  13130. mu = (function calculateScaleFactor() {
  13131. var mu = 2;
  13132. while (mu * fontSize < minFontSize) {
  13133. mu += 2;
  13134. }
  13135. return mu;
  13136. })();
  13137. }
  13138. var fcanvas = document.createElement('canvas');
  13139. var fctx = fcanvas.getContext('2d', { willReadFrequently: true });
  13140. fctx.font = settings.fontWeight + ' ' +
  13141. (fontSize * mu).toString(10) + 'px ' + settings.fontFamily;
  13142. // Estimate the dimension of the text with measureText().
  13143. var fw = fctx.measureText(word).width / mu;
  13144. var fh = Math.max(fontSize * mu,
  13145. fctx.measureText('m').width,
  13146. fctx.measureText('\uFF37').width) / mu;
  13147. // Create a boundary box that is larger than our estimates,
  13148. // so text don't get cut of (it sill might)
  13149. var boxWidth = fw + fh * 2;
  13150. var boxHeight = fh * 3;
  13151. var fgw = Math.ceil(boxWidth / g);
  13152. var fgh = Math.ceil(boxHeight / g);
  13153. boxWidth = fgw * g;
  13154. boxHeight = fgh * g;
  13155. // Calculate the proper offsets to make the text centered at
  13156. // the preferred position.
  13157. // This is simply half of the width.
  13158. var fillTextOffsetX = - fw / 2;
  13159. // Instead of moving the box to the exact middle of the preferred
  13160. // position, for Y-offset we move 0.4 instead, so Latin alphabets look
  13161. // vertical centered.
  13162. var fillTextOffsetY = - fh * 0.4;
  13163. // Calculate the actual dimension of the canvas, considering the rotation.
  13164. var cgh = Math.ceil((boxWidth * Math.abs(Math.sin(rotateDeg)) +
  13165. boxHeight * Math.abs(Math.cos(rotateDeg))) / g);
  13166. var cgw = Math.ceil((boxWidth * Math.abs(Math.cos(rotateDeg)) +
  13167. boxHeight * Math.abs(Math.sin(rotateDeg))) / g);
  13168. var width = cgw * g;
  13169. var height = cgh * g;
  13170. fcanvas.setAttribute('width', width);
  13171. fcanvas.setAttribute('height', height);
  13172. if (debug) {
  13173. // Attach fcanvas to the DOM
  13174. document.body.appendChild(fcanvas);
  13175. // Save it's state so that we could restore and draw the grid correctly.
  13176. fctx.save();
  13177. }
  13178. // Scale the canvas with |mu|.
  13179. fctx.scale(1 / mu, 1 / mu);
  13180. fctx.translate(width * mu / 2, height * mu / 2);
  13181. fctx.rotate(- rotateDeg);
  13182. // Once the width/height is set, ctx info will be reset.
  13183. // Set it again here.
  13184. fctx.font = settings.fontWeight + ' ' +
  13185. (fontSize * mu).toString(10) + 'px ' + settings.fontFamily;
  13186. // Fill the text into the fcanvas.
  13187. // XXX: We cannot because textBaseline = 'top' here because
  13188. // Firefox and Chrome uses different default line-height for canvas.
  13189. // Please read https://bugzil.la/737852#c6.
  13190. // Here, we use textBaseline = 'middle' and draw the text at exactly
  13191. // 0.5 * fontSize lower.
  13192. fctx.fillStyle = '#000';
  13193. fctx.textBaseline = 'middle';
  13194. fctx.fillText(word, fillTextOffsetX * mu,
  13195. (fillTextOffsetY + fontSize * 0.5) * mu);
  13196. // Get the pixels of the text
  13197. var imageData = fctx.getImageData(0, 0, width, height).data;
  13198. if (exceedTime()) {
  13199. return false;
  13200. }
  13201. if (debug) {
  13202. // Draw the box of the original estimation
  13203. fctx.strokeRect(fillTextOffsetX * mu,
  13204. fillTextOffsetY, fw * mu, fh * mu);
  13205. fctx.restore();
  13206. }
  13207. // Read the pixels and save the information to the occupied array
  13208. var occupied = [];
  13209. var gx = cgw, gy, x, y;
  13210. var bounds = [cgh / 2, cgw / 2, cgh / 2, cgw / 2];
  13211. while (gx--) {
  13212. gy = cgh;
  13213. while (gy--) {
  13214. y = g;
  13215. singleGridLoop: {
  13216. while (y--) {
  13217. x = g;
  13218. while (x--) {
  13219. if (imageData[((gy * g + y) * width +
  13220. (gx * g + x)) * 4 + 3]) {
  13221. occupied.push([gx, gy]);
  13222. if (gx < bounds[3]) {
  13223. bounds[3] = gx;
  13224. }
  13225. if (gx > bounds[1]) {
  13226. bounds[1] = gx;
  13227. }
  13228. if (gy < bounds[0]) {
  13229. bounds[0] = gy;
  13230. }
  13231. if (gy > bounds[2]) {
  13232. bounds[2] = gy;
  13233. }
  13234. if (debug) {
  13235. fctx.fillStyle = 'rgba(255, 0, 0, 0.5)';
  13236. fctx.fillRect(gx * g, gy * g, g - 0.5, g - 0.5);
  13237. }
  13238. break singleGridLoop;
  13239. }
  13240. }
  13241. }
  13242. if (debug) {
  13243. fctx.fillStyle = 'rgba(0, 0, 255, 0.5)';
  13244. fctx.fillRect(gx * g, gy * g, g - 0.5, g - 0.5);
  13245. }
  13246. }
  13247. }
  13248. }
  13249. if (debug) {
  13250. fctx.fillStyle = 'rgba(0, 255, 0, 0.5)';
  13251. fctx.fillRect(bounds[3] * g,
  13252. bounds[0] * g,
  13253. (bounds[1] - bounds[3] + 1) * g,
  13254. (bounds[2] - bounds[0] + 1) * g);
  13255. }
  13256. // Return information needed to create the text on the real canvas
  13257. return {
  13258. mu: mu,
  13259. occupied: occupied,
  13260. bounds: bounds,
  13261. gw: cgw,
  13262. gh: cgh,
  13263. fillTextOffsetX: fillTextOffsetX,
  13264. fillTextOffsetY: fillTextOffsetY,
  13265. fillTextWidth: fw,
  13266. fillTextHeight: fh,
  13267. fontSize: fontSize
  13268. };
  13269. };
  13270. /* Determine if there is room available in the given dimension */
  13271. var canFitText = function canFitText(gx, gy, gw, gh, occupied) {
  13272. // Go through the occupied points,
  13273. // return false if the space is not available.
  13274. var i = occupied.length;
  13275. while (i--) {
  13276. var px = gx + occupied[i][0];
  13277. var py = gy + occupied[i][1];
  13278. if (px >= ngx || py >= ngy || px < 0 || py < 0) {
  13279. if (!settings.drawOutOfBound) {
  13280. return false;
  13281. }
  13282. continue;
  13283. }
  13284. if (!grid[px][py]) {
  13285. return false;
  13286. }
  13287. }
  13288. return true;
  13289. };
  13290. /* Actually draw the text on the grid */
  13291. var drawText = function drawText(gx, gy, info, word, weight,
  13292. distance, theta, rotateDeg, attributes) {
  13293. var fontSize = info.fontSize;
  13294. var color;
  13295. if (getTextColor) {
  13296. color = getTextColor(word, weight, fontSize, distance, theta);
  13297. } else {
  13298. color = settings.color;
  13299. }
  13300. var classes;
  13301. if (getTextClasses) {
  13302. classes = getTextClasses(word, weight, fontSize, distance, theta);
  13303. } else {
  13304. classes = settings.classes;
  13305. }
  13306. var dimension;
  13307. var bounds = info.bounds;
  13308. dimension = {
  13309. x: (gx + bounds[3]) * g,
  13310. y: (gy + bounds[0]) * g,
  13311. w: (bounds[1] - bounds[3] + 1) * g,
  13312. h: (bounds[2] - bounds[0] + 1) * g
  13313. };
  13314. elements.forEach(function(el) {
  13315. if (el.getContext) {
  13316. var ctx = el.getContext('2d');
  13317. var mu = info.mu;
  13318. // Save the current state before messing it
  13319. ctx.save();
  13320. ctx.scale(1 / mu, 1 / mu);
  13321. ctx.font = settings.fontWeight + ' ' +
  13322. (fontSize * mu).toString(10) + 'px ' + settings.fontFamily;
  13323. ctx.fillStyle = color;
  13324. // Translate the canvas position to the origin coordinate of where
  13325. // the text should be put.
  13326. ctx.translate((gx + info.gw / 2) * g * mu,
  13327. (gy + info.gh / 2) * g * mu);
  13328. if (rotateDeg !== 0) {
  13329. ctx.rotate(- rotateDeg);
  13330. }
  13331. // Finally, fill the text.
  13332. // XXX: We cannot because textBaseline = 'top' here because
  13333. // Firefox and Chrome uses different default line-height for canvas.
  13334. // Please read https://bugzil.la/737852#c6.
  13335. // Here, we use textBaseline = 'middle' and draw the text at exactly
  13336. // 0.5 * fontSize lower.
  13337. ctx.textBaseline = 'middle';
  13338. ctx.fillText(word, info.fillTextOffsetX * mu,
  13339. (info.fillTextOffsetY + fontSize * 0.5) * mu);
  13340. // The below box is always matches how <span>s are positioned
  13341. /* ctx.strokeRect(info.fillTextOffsetX, info.fillTextOffsetY,
  13342. info.fillTextWidth, info.fillTextHeight); */
  13343. // Restore the state.
  13344. ctx.restore();
  13345. } else {
  13346. // drawText on DIV element
  13347. var span = document.createElement('span');
  13348. var transformRule = '';
  13349. transformRule = 'rotate(' + (- rotateDeg / Math.PI * 180) + 'deg) ';
  13350. if (info.mu !== 1) {
  13351. transformRule +=
  13352. 'translateX(-' + (info.fillTextWidth / 4) + 'px) ' +
  13353. 'scale(' + (1 / info.mu) + ')';
  13354. }
  13355. var styleRules = {
  13356. 'position': 'absolute',
  13357. 'display': 'block',
  13358. 'font': settings.fontWeight + ' ' +
  13359. (fontSize * info.mu) + 'px ' + settings.fontFamily,
  13360. 'left': ((gx + info.gw / 2) * g + info.fillTextOffsetX) + 'px',
  13361. 'top': ((gy + info.gh / 2) * g + info.fillTextOffsetY) + 'px',
  13362. 'width': info.fillTextWidth + 'px',
  13363. 'height': info.fillTextHeight + 'px',
  13364. 'lineHeight': fontSize + 'px',
  13365. 'whiteSpace': 'nowrap',
  13366. 'transform': transformRule,
  13367. 'webkitTransform': transformRule,
  13368. 'msTransform': transformRule,
  13369. 'transformOrigin': '50% 40%',
  13370. 'webkitTransformOrigin': '50% 40%',
  13371. 'msTransformOrigin': '50% 40%'
  13372. };
  13373. if (color) {
  13374. styleRules.color = color;
  13375. }
  13376. span.textContent = word;
  13377. for (var cssProp in styleRules) {
  13378. span.style[cssProp] = styleRules[cssProp];
  13379. }
  13380. if (attributes) {
  13381. for (var attribute in attributes) {
  13382. span.setAttribute(attribute, attributes[attribute]);
  13383. }
  13384. }
  13385. if (classes) {
  13386. span.className += classes;
  13387. }
  13388. el.appendChild(span);
  13389. }
  13390. });
  13391. };
  13392. /* Help function to updateGrid */
  13393. var fillGridAt = function fillGridAt(x, y, drawMask, dimension, item) {
  13394. if (x >= ngx || y >= ngy || x < 0 || y < 0) {
  13395. return;
  13396. }
  13397. grid[x][y] = false;
  13398. if (drawMask) {
  13399. var ctx = elements[0].getContext('2d');
  13400. ctx.fillRect(x * g, y * g, maskRectWidth, maskRectWidth);
  13401. }
  13402. if (interactive) {
  13403. infoGrid[x][y] = { item: item, dimension: dimension };
  13404. }
  13405. };
  13406. /* Update the filling information of the given space with occupied points.
  13407. Draw the mask on the canvas if necessary. */
  13408. var updateGrid = function updateGrid(gx, gy, gw, gh, info, item) {
  13409. var occupied = info.occupied;
  13410. var drawMask = settings.drawMask;
  13411. var ctx;
  13412. if (drawMask) {
  13413. ctx = elements[0].getContext('2d');
  13414. ctx.save();
  13415. ctx.fillStyle = settings.maskColor;
  13416. }
  13417. var dimension;
  13418. if (interactive) {
  13419. var bounds = info.bounds;
  13420. dimension = {
  13421. x: (gx + bounds[3]) * g,
  13422. y: (gy + bounds[0]) * g,
  13423. w: (bounds[1] - bounds[3] + 1) * g,
  13424. h: (bounds[2] - bounds[0] + 1) * g
  13425. };
  13426. }
  13427. var i = occupied.length;
  13428. while (i--) {
  13429. var px = gx + occupied[i][0];
  13430. var py = gy + occupied[i][1];
  13431. if (px >= ngx || py >= ngy || px < 0 || py < 0) {
  13432. continue;
  13433. }
  13434. fillGridAt(px, py, drawMask, dimension, item);
  13435. }
  13436. if (drawMask) {
  13437. ctx.restore();
  13438. }
  13439. };
  13440. /* putWord() processes each item on the list,
  13441. calculate it's size and determine it's position, and actually
  13442. put it on the canvas. */
  13443. var putWord = function putWord(item) {
  13444. var word, weight, attributes;
  13445. if (Array.isArray(item)) {
  13446. word = item[0];
  13447. weight = item[1];
  13448. } else {
  13449. word = item.word;
  13450. weight = item.weight;
  13451. attributes = item.attributes;
  13452. }
  13453. var rotateDeg = getRotateDeg();
  13454. // get info needed to put the text onto the canvas
  13455. var info = getTextInfo(word, weight, rotateDeg);
  13456. // not getting the info means we shouldn't be drawing this one.
  13457. if (!info) {
  13458. return false;
  13459. }
  13460. if (exceedTime()) {
  13461. return false;
  13462. }
  13463. // If drawOutOfBound is set to false,
  13464. // skip the loop if we have already know the bounding box of
  13465. // word is larger than the canvas.
  13466. if (!settings.drawOutOfBound) {
  13467. var bounds = info.bounds;
  13468. if ((bounds[1] - bounds[3] + 1) > ngx ||
  13469. (bounds[2] - bounds[0] + 1) > ngy) {
  13470. return false;
  13471. }
  13472. }
  13473. // Determine the position to put the text by
  13474. // start looking for the nearest points
  13475. var r = maxRadius + 1;
  13476. var tryToPutWordAtPoint = function(gxy) {
  13477. var gx = Math.floor(gxy[0] - info.gw / 2);
  13478. var gy = Math.floor(gxy[1] - info.gh / 2);
  13479. var gw = info.gw;
  13480. var gh = info.gh;
  13481. // If we cannot fit the text at this position, return false
  13482. // and go to the next position.
  13483. if (!canFitText(gx, gy, gw, gh, info.occupied)) {
  13484. return false;
  13485. }
  13486. // Actually put the text on the canvas
  13487. drawText(gx, gy, info, word, weight,
  13488. (maxRadius - r), gxy[2], rotateDeg, attributes);
  13489. // Mark the spaces on the grid as filled
  13490. updateGrid(gx, gy, gw, gh, info, item);
  13491. return {
  13492. gx: gx,
  13493. gy: gy,
  13494. rot: rotateDeg,
  13495. info: info
  13496. };
  13497. };
  13498. while (r--) {
  13499. var points = getPointsAtRadius(maxRadius - r);
  13500. if (settings.shuffle) {
  13501. points = [].concat(points);
  13502. shuffleArray(points);
  13503. }
  13504. // Try to fit the words by looking at each point.
  13505. // array.some() will stop and return true
  13506. // when putWordAtPoint() returns true.
  13507. for (var i = 0; i < points.length; i++) {
  13508. var res = tryToPutWordAtPoint(points[i]);
  13509. if (res) {
  13510. return res;
  13511. }
  13512. }
  13513. // var drawn = points.some(tryToPutWordAtPoint);
  13514. // if (drawn) {
  13515. // // leave putWord() and return true
  13516. // return true;
  13517. // }
  13518. }
  13519. // we tried all distances but text won't fit, return null
  13520. return null;
  13521. };
  13522. /* Send DOM event to all elements. Will stop sending event and return
  13523. if the previous one is canceled (for cancelable events). */
  13524. var sendEvent = function sendEvent(type, cancelable, detail) {
  13525. if (cancelable) {
  13526. return !elements.some(function(el) {
  13527. var evt = document.createEvent('CustomEvent');
  13528. evt.initCustomEvent(type, true, cancelable, detail || {});
  13529. return !el.dispatchEvent(evt);
  13530. }, this);
  13531. } else {
  13532. elements.forEach(function(el) {
  13533. var evt = document.createEvent('CustomEvent');
  13534. evt.initCustomEvent(type, true, cancelable, detail || {});
  13535. el.dispatchEvent(evt);
  13536. }, this);
  13537. }
  13538. };
  13539. /* Start drawing on a canvas */
  13540. var start = function start() {
  13541. // For dimensions, clearCanvas etc.,
  13542. // we only care about the first element.
  13543. var canvas = elements[0];
  13544. if (canvas.getContext) {
  13545. ngx = Math.ceil(canvas.width / g);
  13546. ngy = Math.ceil(canvas.height / g);
  13547. } else {
  13548. var rect = canvas.getBoundingClientRect();
  13549. ngx = Math.ceil(rect.width / g);
  13550. ngy = Math.ceil(rect.height / g);
  13551. }
  13552. // Sending a wordcloudstart event which cause the previous loop to stop.
  13553. // Do nothing if the event is canceled.
  13554. if (!sendEvent('wordcloudstart', true)) {
  13555. return;
  13556. }
  13557. // Determine the center of the word cloud
  13558. center = (settings.origin) ?
  13559. [settings.origin[0]/g, settings.origin[1]/g] :
  13560. [ngx / 2, ngy / 2];
  13561. // Maxium radius to look for space
  13562. maxRadius = Math.floor(Math.sqrt(ngx * ngx + ngy * ngy));
  13563. /* Clear the canvas only if the clearCanvas is set,
  13564. if not, update the grid to the current canvas state */
  13565. grid = [];
  13566. var gx, gy, i;
  13567. if (!canvas.getContext || settings.clearCanvas) {
  13568. elements.forEach(function(el) {
  13569. if (el.getContext) {
  13570. var ctx = el.getContext('2d');
  13571. ctx.fillStyle = settings.backgroundColor;
  13572. ctx.clearRect(0, 0, ngx * (g + 1), ngy * (g + 1));
  13573. ctx.fillRect(0, 0, ngx * (g + 1), ngy * (g + 1));
  13574. } else {
  13575. el.textContent = '';
  13576. el.style.backgroundColor = settings.backgroundColor;
  13577. el.style.position = 'relative';
  13578. }
  13579. });
  13580. /* fill the grid with empty state */
  13581. gx = ngx;
  13582. while (gx--) {
  13583. grid[gx] = [];
  13584. gy = ngy;
  13585. while (gy--) {
  13586. grid[gx][gy] = true;
  13587. }
  13588. }
  13589. } else {
  13590. /* Determine bgPixel by creating
  13591. another canvas and fill the specified background color. */
  13592. var bctx = document.createElement('canvas').getContext('2d');
  13593. bctx.fillStyle = settings.backgroundColor;
  13594. bctx.fillRect(0, 0, 1, 1);
  13595. var bgPixel = bctx.getImageData(0, 0, 1, 1).data;
  13596. /* Read back the pixels of the canvas we got to tell which part of the
  13597. canvas is empty.
  13598. (no clearCanvas only works with a canvas, not divs) */
  13599. var imageData =
  13600. canvas.getContext('2d').getImageData(0, 0, ngx * g, ngy * g).data;
  13601. gx = ngx;
  13602. var x, y;
  13603. while (gx--) {
  13604. grid[gx] = [];
  13605. gy = ngy;
  13606. while (gy--) {
  13607. y = g;
  13608. singleGridLoop: while (y--) {
  13609. x = g;
  13610. while (x--) {
  13611. i = 4;
  13612. while (i--) {
  13613. if (imageData[((gy * g + y) * ngx * g +
  13614. (gx * g + x)) * 4 + i] !== bgPixel[i]) {
  13615. grid[gx][gy] = false;
  13616. break singleGridLoop;
  13617. }
  13618. }
  13619. }
  13620. }
  13621. if (grid[gx][gy] !== false) {
  13622. grid[gx][gy] = true;
  13623. }
  13624. }
  13625. }
  13626. imageData = bctx = bgPixel = undefined;
  13627. }
  13628. // fill the infoGrid with empty state if we need it
  13629. if (settings.hover || settings.click) {
  13630. interactive = true;
  13631. /* fill the grid with empty state */
  13632. gx = ngx + 1;
  13633. while (gx--) {
  13634. infoGrid[gx] = [];
  13635. }
  13636. if (settings.hover) {
  13637. canvas.addEventListener('mousemove', wordcloudhover);
  13638. }
  13639. if (settings.click) {
  13640. canvas.addEventListener('click', wordcloudclick);
  13641. canvas.addEventListener('touchstart', wordcloudclick);
  13642. canvas.addEventListener('touchend', function (e) {
  13643. e.preventDefault();
  13644. });
  13645. canvas.style.webkitTapHighlightColor = 'rgba(0, 0, 0, 0)';
  13646. }
  13647. canvas.addEventListener('wordcloudstart', function stopInteraction() {
  13648. canvas.removeEventListener('wordcloudstart', stopInteraction);
  13649. canvas.removeEventListener('mousemove', wordcloudhover);
  13650. canvas.removeEventListener('click', wordcloudclick);
  13651. hovered = undefined;
  13652. });
  13653. }
  13654. i = 0;
  13655. var loopingFunction, stoppingFunction;
  13656. if (settings.wait !== 0) {
  13657. loopingFunction = window.setTimeout;
  13658. stoppingFunction = window.clearTimeout;
  13659. } else {
  13660. loopingFunction = window.setImmediate;
  13661. stoppingFunction = window.clearImmediate;
  13662. }
  13663. var addEventListener = function addEventListener(type, listener) {
  13664. elements.forEach(function(el) {
  13665. el.addEventListener(type, listener);
  13666. }, this);
  13667. };
  13668. var removeEventListener = function removeEventListener(type, listener) {
  13669. elements.forEach(function(el) {
  13670. el.removeEventListener(type, listener);
  13671. }, this);
  13672. };
  13673. var anotherWordCloudStart = function anotherWordCloudStart() {
  13674. removeEventListener('wordcloudstart', anotherWordCloudStart);
  13675. stoppingFunction(timer);
  13676. };
  13677. addEventListener('wordcloudstart', anotherWordCloudStart);
  13678. var timer = loopingFunction(function loop() {
  13679. if (i >= settings.list.length) {
  13680. stoppingFunction(timer);
  13681. sendEvent('wordcloudstop', false);
  13682. removeEventListener('wordcloudstart', anotherWordCloudStart);
  13683. return;
  13684. }
  13685. escapeTime = (new Date()).getTime();
  13686. var drawn = putWord(settings.list[i]);
  13687. var canceled = !sendEvent('wordclouddrawn', true, {
  13688. item: settings.list[i], drawn: drawn });
  13689. if (exceedTime() || canceled) {
  13690. stoppingFunction(timer);
  13691. settings.abort();
  13692. sendEvent('wordcloudabort', false);
  13693. sendEvent('wordcloudstop', false);
  13694. removeEventListener('wordcloudstart', anotherWordCloudStart);
  13695. return;
  13696. }
  13697. i++;
  13698. timer = loopingFunction(loop, settings.wait);
  13699. }, settings.wait);
  13700. };
  13701. // All set, start the drawing
  13702. start();
  13703. };
  13704. WordCloud.isSupported = isSupported;
  13705. WordCloud.minFontSize = minFontSize;
  13706. // Expose the library as an AMD module
  13707. if (true) {
  13708. !(__WEBPACK_AMD_DEFINE_ARRAY__ = [], __WEBPACK_AMD_DEFINE_RESULT__ = function() { return WordCloud; }.apply(exports, __WEBPACK_AMD_DEFINE_ARRAY__),
  13709. __WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__));
  13710. } else if (typeof module !== 'undefined' && module.exports) {
  13711. module.exports = WordCloud;
  13712. } else {
  13713. global.WordCloud = WordCloud;
  13714. }
  13715. })(this); //jshint ignore:line
  13716. /***/ })
  13717. /******/ ]);
  13718. });