f2-common.js 339 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559
  1. (function webpackUniversalModuleDefinition(root, factory) {
  2. if(typeof exports === 'object' && typeof module === 'object')
  3. module.exports = factory();
  4. else if(typeof define === 'function' && define.amd)
  5. define([], factory);
  6. else if(typeof exports === 'object')
  7. exports["F2"] = factory();
  8. else
  9. root["F2"] = factory();
  10. })(this, function() {
  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 = 101);
  74. /******/ })
  75. /************************************************************************/
  76. /******/ ([
  77. /* 0 */
  78. /***/ (function(module, exports, __webpack_require__) {
  79. /**
  80. * @fileOverview 基础工具类
  81. * @author dxq613@gmail.com
  82. */
  83. var DomUtil = __webpack_require__(29);
  84. var objectPrototype = Object.prototype;
  85. var toString = objectPrototype.toString;
  86. var MAX_LEVEL = 5;
  87. var Util = void 0;
  88. function _deepMix(dst, src, level) {
  89. level = level || 0;
  90. for (var k in src) {
  91. if (src.hasOwnProperty(k)) {
  92. var value = src[k];
  93. if (value !== null && Util.isPlainObject(value)) {
  94. if (!Util.isPlainObject(dst[k])) {
  95. dst[k] = {};
  96. }
  97. if (level < MAX_LEVEL) {
  98. _deepMix(dst[k], src[k], level + 1);
  99. } else {
  100. dst[k] = src[k];
  101. }
  102. } else if (Util.isArray(value)) {
  103. dst[k] = [];
  104. dst[k] = dst[k].concat(value);
  105. } else if (value !== undefined) {
  106. dst[k] = src[k];
  107. }
  108. }
  109. }
  110. }
  111. function _mix(dist, obj) {
  112. for (var k in obj) {
  113. if (obj.hasOwnProperty(k) && k !== 'constructor' && obj[k] !== undefined) {
  114. dist[k] = obj[k];
  115. }
  116. }
  117. }
  118. /**
  119. * @class Util
  120. * @singleton
  121. * 绘图的工具类
  122. */
  123. Util = {
  124. /**
  125. * 使第一个字母变成大写
  126. * @param {String} s 字符串
  127. * @return {String} 首字母大写后的字符串
  128. */
  129. upperFirst: function upperFirst(s) {
  130. s += '';
  131. return s.charAt(0).toUpperCase() + s.substring(1);
  132. },
  133. lowerFirst: function lowerFirst(s) {
  134. s += '';
  135. return s.charAt(0).toLowerCase() + s.substring(1);
  136. },
  137. /**
  138. * 判断是否是字符串
  139. * @param {*} value 判定的值
  140. * @return {Boolean} 是否是字符串
  141. */
  142. isString: function isString(value) {
  143. return typeof value === 'string';
  144. },
  145. /**
  146. * 判断是否数字
  147. * @param {*} value 判定的值
  148. * @return {Boolean} 是否数字
  149. */
  150. isNumber: function isNumber(value) {
  151. return typeof value === 'number';
  152. },
  153. /**
  154. * 是否是布尔类型
  155. * @param {Object} value 测试的值
  156. * @return {Boolean} 是否布尔类型
  157. */
  158. isBoolean: function isBoolean(value) {
  159. return typeof value === 'boolean';
  160. },
  161. /**
  162. * 是否为函数
  163. * @param {*} fn 对象
  164. * @return {Boolean} 是否函数
  165. */
  166. isFunction: function isFunction(fn) {
  167. return typeof fn === 'function';
  168. },
  169. /**
  170. * 是否数组
  171. * @method
  172. * @param {*} value 是否数组
  173. * @return {Boolean} 是否数组
  174. */
  175. isArray: 'isArray' in Array ? Array.isArray : function (value) {
  176. return toString.call(value) === '[object Array]';
  177. },
  178. /**
  179. * 是否日期
  180. * @param {*} value 对象
  181. * @return {Boolean} 是否日期
  182. */
  183. isDate: function isDate(value) {
  184. return toString.call(value) === '[object Date]';
  185. },
  186. isNil: function isNil(o) {
  187. return o === undefined || o === null;
  188. },
  189. /**
  190. * 是否是javascript对象
  191. * @param {Object} value The value to test
  192. * @return {Boolean} 返回判定结果
  193. */
  194. isObject: toString.call(null) === '[object Object]' ? function (value) {
  195. // check ownerDocument here as well to exclude DOM nodes
  196. return value !== null && value !== undefined && toString.call(value) === '[object Object]' && value.ownerDocument === undefined;
  197. } : function (value) {
  198. return toString.call(value) === '[object Object]';
  199. },
  200. isPlainObject: function isPlainObject(o) {
  201. if (!Util.isObject(o)) return false;
  202. if (Object.getPrototypeOf(o) === null) {
  203. return true;
  204. }
  205. var proto = o;
  206. while (Object.getPrototypeOf(proto) !== null) {
  207. proto = Object.getPrototypeOf(proto);
  208. }
  209. return Object.getPrototypeOf(o) === proto;
  210. },
  211. deepMix: function deepMix() {
  212. var args = new Array(arguments.length);
  213. var length = args.length;
  214. for (var i = 0; i < length; i++) {
  215. args[i] = arguments[i];
  216. }
  217. var rst = args[0];
  218. for (var _i = 1; _i < length; _i++) {
  219. var source = args[_i];
  220. _deepMix(rst, source);
  221. }
  222. return rst;
  223. },
  224. /**
  225. * 合并数据, 简单的合并,仅支持最多3个对象
  226. * @param {Object} dist 源对象
  227. * @param {Object} obj1 待复制对象1
  228. * @param {Object} obj2 待复制对象2
  229. * @param {Object} obj3 待复制对象3
  230. * @return {Object} 将数据合并到第一个
  231. */
  232. mix: function mix(dist, obj1, obj2, obj3) {
  233. if (obj1) {
  234. _mix(dist, obj1);
  235. }
  236. if (obj2) {
  237. _mix(dist, obj2);
  238. }
  239. if (obj3) {
  240. _mix(dist, obj3);
  241. }
  242. return dist;
  243. },
  244. indexOf: function indexOf(arr, element) {
  245. return arr.indexOf(element);
  246. },
  247. /**
  248. * 遍历数组或者对象
  249. * @param {Object|Array} elements 数组中的元素或者对象的值
  250. * @param {Function} func 遍历的函数 function(elememt,index){} 或者 function(value,key){}
  251. */
  252. each: function each(elements, func) {
  253. if (!elements) {
  254. return;
  255. }
  256. if (elements.length) {
  257. for (var i = 0, len = elements.length; i < len; i++) {
  258. var rst = func(elements[i], i);
  259. if (rst === false) {
  260. break;
  261. }
  262. }
  263. } else {
  264. for (var k in elements) {
  265. if (elements.hasOwnProperty(k)) {
  266. var _rst = func(elements[k], k);
  267. if (_rst === false) {
  268. break;
  269. }
  270. }
  271. }
  272. }
  273. },
  274. fixedBase: function fixedBase(v, base) {
  275. var str = base.toString();
  276. var index = str.indexOf('.');
  277. if (index === -1) {
  278. return Math.round(v);
  279. }
  280. var length = str.substr(index + 1).length;
  281. if (length > 20) {
  282. length = 20;
  283. }
  284. return parseFloat(v.toFixed(length));
  285. },
  286. /**
  287. * 封装事件,便于使用上下文this,和便于解除事件时使用
  288. * @protected
  289. * @param {Object} obj 对象
  290. * @param {String} action 事件名称
  291. * @return {Function} 返回事件处理函数
  292. */
  293. wrapBehavior: function wrapBehavior(obj, action) {
  294. if (obj['_wrap_' + action]) {
  295. return obj['_wrap_' + action];
  296. }
  297. var method = function method(e) {
  298. obj[action](e);
  299. };
  300. obj['_wrap_' + action] = method;
  301. return method;
  302. },
  303. /**
  304. * 获取封装的事件
  305. * @protected
  306. * @param {Object} obj 对象
  307. * @param {String} action 事件名称
  308. * @return {Function} 返回事件处理函数
  309. */
  310. getWrapBehavior: function getWrapBehavior(obj, action) {
  311. return obj['_wrap_' + action];
  312. },
  313. parsePadding: function parsePadding(padding) {
  314. var top = void 0;
  315. var right = void 0;
  316. var bottom = void 0;
  317. var left = void 0;
  318. if (Util.isNumber(padding) || Util.isString(padding)) {
  319. top = bottom = left = right = padding;
  320. } else if (Util.isArray(padding)) {
  321. top = padding[0];
  322. right = !Util.isNil(padding[1]) ? padding[1] : padding[0];
  323. bottom = !Util.isNil(padding[2]) ? padding[2] : padding[0];
  324. left = !Util.isNil(padding[3]) ? padding[3] : right;
  325. }
  326. return [top, right, bottom, left];
  327. }
  328. };
  329. Util.Array = {
  330. merge: function merge(dataArray) {
  331. var rst = [];
  332. for (var i = 0, len = dataArray.length; i < len; i++) {
  333. rst = rst.concat(dataArray[i]);
  334. }
  335. return rst;
  336. },
  337. values: function values(data, name) {
  338. var rst = [];
  339. var tmpMap = {};
  340. for (var i = 0, len = data.length; i < len; i++) {
  341. var obj = data[i];
  342. var value = obj[name];
  343. if (!Util.isNil(value)) {
  344. if (!Util.isArray(value)) {
  345. if (!tmpMap[value]) {
  346. rst.push(value);
  347. tmpMap[value] = true;
  348. }
  349. } else {
  350. Util.each(value, function (val) {
  351. if (!tmpMap[val]) {
  352. rst.push(val);
  353. tmpMap[val] = true;
  354. }
  355. });
  356. }
  357. }
  358. }
  359. return rst;
  360. },
  361. firstValue: function firstValue(data, name) {
  362. var rst = null;
  363. for (var i = 0, len = data.length; i < len; i++) {
  364. var obj = data[i];
  365. var value = obj[name];
  366. if (!Util.isNil(value)) {
  367. if (Util.isArray(value)) {
  368. rst = value[0];
  369. } else {
  370. rst = value;
  371. }
  372. break;
  373. }
  374. }
  375. return rst;
  376. },
  377. group: function group(data, condition) {
  378. if (!condition) {
  379. return [data];
  380. }
  381. var groups = Util.Array.groupToMap(data, condition);
  382. var array = [];
  383. for (var i in groups) {
  384. array.push(groups[i]);
  385. }
  386. return array;
  387. },
  388. groupToMap: function groupToMap(data, condition) {
  389. if (!condition) {
  390. return {
  391. 0: data
  392. };
  393. }
  394. if (!Util.isFunction(condition)) {
  395. var paramsCondition = Util.isArray(condition) ? condition : condition.replace(/\s+/g, '').split('*');
  396. condition = function condition(row) {
  397. var unique = '_'; // 避免出现数字作为Key的情况,会进行按照数字的排序
  398. for (var i = 0, l = paramsCondition.length; i < l; i++) {
  399. unique += row[paramsCondition[i]] && row[paramsCondition[i]].toString();
  400. }
  401. return unique;
  402. };
  403. }
  404. var groups = {};
  405. for (var i = 0, len = data.length; i < len; i++) {
  406. var row = data[i];
  407. var key = condition(row);
  408. if (groups[key]) {
  409. groups[key].push(row);
  410. } else {
  411. groups[key] = [row];
  412. }
  413. }
  414. return groups;
  415. },
  416. remove: function remove(arr, obj) {
  417. if (!arr) {
  418. return;
  419. }
  420. var index = arr.indexOf(obj);
  421. if (index !== -1) {
  422. arr.splice(index, 1);
  423. }
  424. }
  425. };
  426. Util.mix(Util, DomUtil);
  427. module.exports = Util;
  428. /***/ }),
  429. /* 1 */
  430. /***/ (function(module, exports, __webpack_require__) {
  431. var Theme = __webpack_require__(28);
  432. var Util = __webpack_require__(0);
  433. /**
  434. * @class 全局配置项
  435. */
  436. var Global = {
  437. version: '3.1.22',
  438. trackable: true,
  439. // 预先定义的度量
  440. scales: {
  441. nice: true
  442. },
  443. // 宽度
  444. widthRatio: { // 宽度所占的分类的比例
  445. column: 1 / 2, // 一般的柱状图占比 1/2
  446. rose: 0.999999,
  447. multiplePie: 3 / 4,
  448. dodgeMargin: 0
  449. },
  450. // 虚线配置
  451. lineDash: [4, 4]
  452. };
  453. Global.setTheme = function (theme) {
  454. Util.deepMix(this, theme);
  455. };
  456. Global.setTheme(Theme);
  457. module.exports = Global;
  458. /***/ }),
  459. /* 2 */
  460. /***/ (function(module, exports, __webpack_require__) {
  461. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  462. function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
  463. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
  464. var Util = __webpack_require__(0);
  465. var Element = __webpack_require__(16);
  466. var Shape = function (_Element) {
  467. _inherits(Shape, _Element);
  468. function Shape() {
  469. _classCallCheck(this, Shape);
  470. return _possibleConstructorReturn(this, _Element.apply(this, arguments));
  471. }
  472. Shape.prototype._initProperties = function _initProperties() {
  473. this._attrs = {
  474. zIndex: 0,
  475. visible: true,
  476. destroyed: false,
  477. isShape: true,
  478. attrs: {}
  479. };
  480. };
  481. Shape.prototype.drawInner = function drawInner(context) {
  482. var self = this;
  483. var attrs = self.get('attrs');
  484. self.createPath(context);
  485. var originOpacity = context.globalAlpha;
  486. if (self.hasFill()) {
  487. var fillOpacity = attrs.fillOpacity;
  488. if (!Util.isNil(fillOpacity) && fillOpacity !== 1) {
  489. context.globalAlpha = fillOpacity;
  490. context.fill();
  491. context.globalAlpha = originOpacity;
  492. } else {
  493. context.fill();
  494. }
  495. }
  496. if (self.hasStroke()) {
  497. var lineWidth = attrs.lineWidth;
  498. if (lineWidth > 0) {
  499. var strokeOpacity = attrs.strokeOpacity;
  500. if (!Util.isNil(strokeOpacity) && strokeOpacity !== 1) {
  501. context.globalAlpha = strokeOpacity;
  502. }
  503. context.stroke();
  504. }
  505. }
  506. };
  507. Shape.prototype.getBBox = function getBBox() {
  508. var bbox = this._attrs.bbox;
  509. // 延迟计算
  510. if (!bbox) {
  511. bbox = this.calculateBox();
  512. if (bbox) {
  513. bbox.x = bbox.minX;
  514. bbox.y = bbox.minY;
  515. bbox.width = bbox.maxX - bbox.minX;
  516. bbox.height = bbox.maxY - bbox.minY;
  517. }
  518. this._attrs.bbox = bbox;
  519. }
  520. return bbox;
  521. };
  522. /**
  523. * @protected
  524. * 计算包围盒
  525. * @return {Object} 包围盒
  526. */
  527. Shape.prototype.calculateBox = function calculateBox() {
  528. return null;
  529. };
  530. Shape.prototype.createPath = function createPath() {};
  531. return Shape;
  532. }(Element);
  533. module.exports = Shape;
  534. /***/ }),
  535. /* 3 */
  536. /***/ (function(module, exports) {
  537. /**
  538. * 2 Dimensional Vector
  539. * @module vector2
  540. */
  541. module.exports = {
  542. /**
  543. * Creates a new, empty vector2
  544. *
  545. * @return {vector2} a new 2D vector
  546. */
  547. create: function create() {
  548. return [0, 0];
  549. },
  550. /**
  551. * Calculates the length of a vector2
  552. *
  553. * @param {vector2} v vector to calculate length of
  554. * @return {Number} length of v
  555. */
  556. length: function length(v) {
  557. var x = v[0];
  558. var y = v[1];
  559. return Math.sqrt(x * x + y * y);
  560. },
  561. /**
  562. * Normalize a vector2
  563. *
  564. * @param {vector2} out the receiving vector
  565. * @param {vector2} v vector to normalize
  566. * @return {vector2} out
  567. */
  568. normalize: function normalize(out, v) {
  569. var len = this.length(v);
  570. if (len === 0) {
  571. out[0] = 0;
  572. out[1] = 0;
  573. } else {
  574. out[0] = v[0] / len;
  575. out[1] = v[1] / len;
  576. }
  577. return out;
  578. },
  579. /**
  580. * Adds two vector2's
  581. *
  582. * @param {vector2} out the receiving vector
  583. * @param {vector2} v1 the first operand
  584. * @param {vector2} v2 the second operand
  585. * @return {vector2} out
  586. */
  587. add: function add(out, v1, v2) {
  588. out[0] = v1[0] + v2[0];
  589. out[1] = v1[1] + v2[1];
  590. return out;
  591. },
  592. /**
  593. * Subtracts vector v2 from vector v1
  594. *
  595. * @param {vector2} out the receiving vector
  596. * @param {vector2} v1 the first operand
  597. * @param {vector2} v2 the second operand
  598. * @return {vector2} out
  599. */
  600. sub: function sub(out, v1, v2) {
  601. out[0] = v1[0] - v2[0];
  602. out[1] = v1[1] - v2[1];
  603. return out;
  604. },
  605. /**
  606. * Scales a vector2 by a scalar number
  607. *
  608. * @param {vector2} out the receiving vector
  609. * @param {vector2} v the vector to scale
  610. * @param {Number} s amount to scale the vector by
  611. * @return {vector2} out
  612. */
  613. scale: function scale(out, v, s) {
  614. out[0] = v[0] * s;
  615. out[1] = v[1] * s;
  616. return out;
  617. },
  618. /**
  619. * Calculates the dot product of two vector2's
  620. *
  621. * @param {vector2} v1 the first operand
  622. * @param {vector2} v2 the second operand
  623. * @return {Number} dot product of v1 and v2
  624. */
  625. dot: function dot(v1, v2) {
  626. return v1[0] * v2[0] + v1[1] * v2[1];
  627. },
  628. /**
  629. * Calculates the direction of two vector2's
  630. *
  631. * @param {vector2} v1 the first operand
  632. * @param {vector2} v2 the second operand
  633. * @return {Boolean} the direction of v1 and v2
  634. */
  635. direction: function direction(v1, v2) {
  636. return v1[0] * v2[1] - v2[0] * v1[1];
  637. },
  638. /**
  639. * Calculates the angle of two vector2's
  640. *
  641. * @param {vector2} v1 the first operand
  642. * @param {vector2} v2 the second operand
  643. * @return {Number} angle of v1 and v2
  644. */
  645. angle: function angle(v1, v2) {
  646. var theta = this.dot(v1, v2) / (this.length(v1) * this.length(v2));
  647. return Math.acos(theta);
  648. },
  649. /**
  650. * Calculates the angle of two vector2's with direction
  651. *
  652. * @param {vector2} v1 the first operand
  653. * @param {vector2} v2 the second operand
  654. * @param {Boolean} direction the direction of two vector2's
  655. * @return {Number} angle of v1 and v2
  656. */
  657. angleTo: function angleTo(v1, v2, direction) {
  658. var angle = this.angle(v1, v2);
  659. var angleLargeThanPI = this.direction(v1, v2) >= 0;
  660. if (direction) {
  661. if (angleLargeThanPI) {
  662. return Math.PI * 2 - angle;
  663. }
  664. return angle;
  665. }
  666. if (angleLargeThanPI) {
  667. return angle;
  668. }
  669. return Math.PI * 2 - angle;
  670. },
  671. /**
  672. * whether a vector2 is zero vector
  673. *
  674. * @param {vector2} v vector to calculate
  675. * @return {Boolean} is or not a zero vector
  676. */
  677. zero: function zero(v) {
  678. return v[0] === 0 && v[1] === 0;
  679. },
  680. /**
  681. * Calculates the euclidian distance between two vector2's
  682. *
  683. * @param {vector2} v1 the first operand
  684. * @param {vector2} v2 the second operand
  685. * @return {Number} distance between a and b
  686. */
  687. distance: function distance(v1, v2) {
  688. var x = v2[0] - v1[0];
  689. var y = v2[1] - v1[1];
  690. return Math.sqrt(x * x + y * y);
  691. },
  692. /**
  693. * Creates a new vector2 initialized with values from an existing vector
  694. *
  695. * @param {vector2} v vector to clone
  696. * @return {Array} a new 2D vector
  697. */
  698. clone: function clone(v) {
  699. return [v[0], v[1]];
  700. },
  701. /**
  702. * Return the minimum of two vector2's
  703. *
  704. * @param {vector2} out the receiving vector
  705. * @param {vector2} v1 the first operand
  706. * @param {vector2} v2 the second operand
  707. * @return {vector2} out
  708. */
  709. min: function min(out, v1, v2) {
  710. out[0] = Math.min(v1[0], v2[0]);
  711. out[1] = Math.min(v1[1], v2[1]);
  712. return out;
  713. },
  714. /**
  715. * Return the maximum of two vector2's
  716. *
  717. * @param {vector2} out the receiving vector
  718. * @param {vector2} v1 the first operand
  719. * @param {vector2} v2 the second operand
  720. * @return {vector2} out
  721. */
  722. max: function max(out, v1, v2) {
  723. out[0] = Math.max(v1[0], v2[0]);
  724. out[1] = Math.max(v1[1], v2[1]);
  725. return out;
  726. },
  727. /**
  728. * Transforms the vector2 with a mat2d
  729. *
  730. * @param {vector2} out the receiving vector
  731. * @param {vector2} v the vector to transform
  732. * @param {mat2d} m matrix to transform with
  733. * @return {vector2} out
  734. */
  735. transformMat2d: function transformMat2d(out, v, m) {
  736. var x = v[0];
  737. var y = v[1];
  738. out[0] = m[0] * x + m[2] * y + m[4];
  739. out[1] = m[1] * x + m[3] * y + m[5];
  740. return out;
  741. }
  742. };
  743. /***/ }),
  744. /* 4 */
  745. /***/ (function(module, exports, __webpack_require__) {
  746. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  747. function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
  748. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
  749. var Util = __webpack_require__(0);
  750. var Base = __webpack_require__(17);
  751. var GROUP_ATTRS = ['color', 'size', 'shape'];
  752. var FIELD_ORIGIN = '_origin';
  753. var FIELD_ORIGIN_Y = '_originY';
  754. var Global = __webpack_require__(1);
  755. var Attr = __webpack_require__(33);
  756. var Shape = __webpack_require__(5);
  757. var Adjust = __webpack_require__(11);
  758. function parseFields(field) {
  759. if (Util.isArray(field)) {
  760. return field;
  761. }
  762. if (Util.isString(field)) {
  763. return field.split('*');
  764. }
  765. return [field];
  766. }
  767. /**
  768. * 图形的基类
  769. * @class Geom
  770. */
  771. var Geom = function (_Base) {
  772. _inherits(Geom, _Base);
  773. function Geom() {
  774. _classCallCheck(this, Geom);
  775. return _possibleConstructorReturn(this, _Base.apply(this, arguments));
  776. }
  777. Geom.prototype.getDefaultCfg = function getDefaultCfg() {
  778. return {
  779. /**
  780. * core的类型
  781. * @type {String}
  782. */
  783. type: null,
  784. /**
  785. * 图形的数据集合
  786. * @type {Array}
  787. */
  788. data: null,
  789. /**
  790. * 属性的键值对
  791. * @type {Object}
  792. */
  793. attrs: {},
  794. scales: {},
  795. /**
  796. * 画布
  797. * @type {Canvas}
  798. */
  799. container: null,
  800. /**
  801. * 图形样式
  802. * @type {Object}
  803. */
  804. styleOptions: null,
  805. chart: null,
  806. shapeType: '',
  807. /**
  808. * 是否生成多个点来绘制图形
  809. * @protected
  810. * @type {Boolean}
  811. */
  812. generatePoints: false,
  813. attrOptions: {},
  814. sortable: false,
  815. /**
  816. * 图形的底边是否从 0 开始,默认为 0,即从 0 开始,
  817. * 否则从最小值开始
  818. * @type {Boolean}
  819. */
  820. startOnZero: true,
  821. /**
  822. * 是否连接空数据,对 area、line、path 生效
  823. */
  824. connectNulls: false
  825. };
  826. };
  827. Geom.prototype.init = function init() {
  828. var self = this;
  829. self._initAttrs();
  830. var dataArray = self._processData();
  831. if (self.get('adjust')) {
  832. self._adjustData(dataArray);
  833. }
  834. self.set('dataArray', dataArray);
  835. };
  836. // 获取分组的度量
  837. Geom.prototype._getGroupScales = function _getGroupScales() {
  838. var self = this;
  839. var scales = [];
  840. Util.each(GROUP_ATTRS, function (attrName) {
  841. var attr = self.getAttr(attrName);
  842. if (attr) {
  843. var attrScales = attr.scales;
  844. Util.each(attrScales, function (scale) {
  845. if (scale && scale.isCategory && scales.indexOf(scale) === -1) {
  846. scales.push(scale);
  847. }
  848. });
  849. }
  850. });
  851. return scales;
  852. };
  853. // 分组数据
  854. Geom.prototype._groupData = function _groupData(data) {
  855. var self = this;
  856. var groupScales = self._getGroupScales();
  857. if (groupScales.length) {
  858. var names = [];
  859. Util.each(groupScales, function (scale) {
  860. names.push(scale.field);
  861. });
  862. return Util.Array.group(data, names);
  863. }
  864. return [data];
  865. };
  866. // 设置属性配置信息
  867. Geom.prototype._setAttrOptions = function _setAttrOptions(attrName, attrCfg) {
  868. var options = this.get('attrOptions');
  869. options[attrName] = attrCfg;
  870. };
  871. Geom.prototype._createAttrOption = function _createAttrOption(attrName, field, cfg, defaultValues) {
  872. var attrCfg = {};
  873. attrCfg.field = field;
  874. if (cfg) {
  875. if (Util.isFunction(cfg)) {
  876. attrCfg.callback = cfg;
  877. } else {
  878. attrCfg.values = cfg;
  879. }
  880. } else {
  881. attrCfg.values = defaultValues;
  882. }
  883. this._setAttrOptions(attrName, attrCfg);
  884. };
  885. // step 1: init attrs
  886. Geom.prototype._initAttrs = function _initAttrs() {
  887. var self = this;
  888. var attrs = self.get('attrs');
  889. var attrOptions = self.get('attrOptions');
  890. var coord = self.get('coord');
  891. for (var type in attrOptions) {
  892. if (attrOptions.hasOwnProperty(type)) {
  893. var option = attrOptions[type];
  894. var className = Util.upperFirst(type);
  895. var fields = parseFields(option.field);
  896. if (type === 'position') {
  897. option.coord = coord;
  898. }
  899. var scales = [];
  900. for (var i = 0, len = fields.length; i < len; i++) {
  901. var field = fields[i];
  902. var scale = self._createScale(field);
  903. scales.push(scale);
  904. }
  905. if (type === 'position') {
  906. var yScale = scales[1];
  907. // 饼图需要填充满整个空间
  908. if (coord.type === 'polar' && coord.transposed && self.hasAdjust('stack')) {
  909. if (yScale.values.length) {
  910. yScale.change({
  911. nice: false,
  912. min: 0,
  913. max: Math.max.apply(null, yScale.values)
  914. });
  915. }
  916. }
  917. }
  918. option.scales = scales;
  919. var attr = new Attr[className](option);
  920. attrs[type] = attr;
  921. }
  922. }
  923. };
  924. Geom.prototype._createScale = function _createScale(field) {
  925. var scales = this.get('scales');
  926. var scale = scales[field];
  927. if (!scale) {
  928. scale = this.get('chart').createScale(field);
  929. scales[field] = scale;
  930. }
  931. return scale;
  932. };
  933. // 处理数据
  934. Geom.prototype._processData = function _processData() {
  935. var self = this;
  936. var data = this.get('data');
  937. var dataArray = [];
  938. var groupedArray = this._groupData(data);
  939. for (var i = 0, len = groupedArray.length; i < len; i++) {
  940. var subData = groupedArray[i];
  941. var tempData = self._saveOrigin(subData);
  942. if (this.hasAdjust('dodge')) {
  943. self._numberic(tempData);
  944. }
  945. dataArray.push(tempData);
  946. }
  947. return dataArray;
  948. };
  949. Geom.prototype._saveOrigin = function _saveOrigin(data) {
  950. var rst = [];
  951. for (var i = 0, len = data.length; i < len; i++) {
  952. var origin = data[i];
  953. var obj = {};
  954. for (var k in origin) {
  955. obj[k] = origin[k];
  956. }
  957. obj[FIELD_ORIGIN] = origin;
  958. rst.push(obj);
  959. }
  960. return rst;
  961. };
  962. // step 2.3 将分类数据翻译成数据, 仅对位置相关的度量进行数字化处理
  963. Geom.prototype._numberic = function _numberic(data) {
  964. var positionAttr = this.getAttr('position');
  965. var scales = positionAttr.scales;
  966. for (var j = 0, len = data.length; j < len; j++) {
  967. var obj = data[j];
  968. var count = Math.min(2, scales.length);
  969. for (var i = 0; i < count; i++) {
  970. var scale = scales[i];
  971. if (scale.isCategory) {
  972. var field = scale.field;
  973. obj[field] = scale.translate(obj[field]);
  974. }
  975. }
  976. }
  977. };
  978. // 进行数据调整
  979. Geom.prototype._adjustData = function _adjustData(dataArray) {
  980. var self = this;
  981. var adjust = self.get('adjust');
  982. if (adjust) {
  983. var adjustType = Util.upperFirst(adjust.type);
  984. if (!Adjust[adjustType]) {
  985. throw new Error('not support such adjust : ' + adjust);
  986. }
  987. var xScale = self.getXScale();
  988. var yScale = self.getYScale();
  989. var cfg = Util.mix({
  990. xField: xScale.field,
  991. yField: yScale.field
  992. }, adjust);
  993. var adjustObject = new Adjust[adjustType](cfg);
  994. adjustObject.processAdjust(dataArray);
  995. if (adjustType === 'Stack') {
  996. self._updateStackRange(yScale.field, yScale, dataArray);
  997. }
  998. }
  999. };
  1000. Geom.prototype._updateStackRange = function _updateStackRange(field, scale, dataArray) {
  1001. var mergeArray = Util.Array.merge(dataArray);
  1002. var min = scale.min;
  1003. var max = scale.max;
  1004. for (var i = 0, len = mergeArray.length; i < len; i++) {
  1005. var obj = mergeArray[i];
  1006. var tmpMin = Math.min.apply(null, obj[field]);
  1007. var tmpMax = Math.max.apply(null, obj[field]);
  1008. if (tmpMin < min) {
  1009. min = tmpMin;
  1010. }
  1011. if (tmpMax > max) {
  1012. max = tmpMax;
  1013. }
  1014. }
  1015. if (min < scale.min || max > scale.max) {
  1016. scale.change({
  1017. min: min,
  1018. max: max
  1019. });
  1020. }
  1021. };
  1022. Geom.prototype._sort = function _sort(mappedArray) {
  1023. var self = this;
  1024. var xScale = self.getXScale();
  1025. var xField = xScale.field;
  1026. if (xScale.type !== 'identity' && xScale.values.length > 1) {
  1027. Util.each(mappedArray, function (itemArr) {
  1028. itemArr.sort(function (obj1, obj2) {
  1029. return xScale.translate(obj1[FIELD_ORIGIN][xField]) - xScale.translate(obj2[FIELD_ORIGIN][xField]);
  1030. });
  1031. });
  1032. }
  1033. self.set('hasSorted', true);
  1034. self.set('dataArray', mappedArray);
  1035. };
  1036. Geom.prototype.paint = function paint() {
  1037. var self = this;
  1038. var dataArray = self.get('dataArray');
  1039. var mappedArray = [];
  1040. var shapeFactory = self.getShapeFactory();
  1041. shapeFactory.setCoord(self.get('coord'));
  1042. self._beforeMapping(dataArray);
  1043. for (var i = 0, len = dataArray.length; i < len; i++) {
  1044. var data = dataArray[i];
  1045. if (data.length) {
  1046. data = self._mapping(data);
  1047. mappedArray.push(data);
  1048. self.draw(data, shapeFactory);
  1049. }
  1050. }
  1051. self.set('dataArray', mappedArray);
  1052. };
  1053. /**
  1054. * @protected
  1055. * 获取图形的工厂类
  1056. * @return {Object} 工厂类对象
  1057. */
  1058. Geom.prototype.getShapeFactory = function getShapeFactory() {
  1059. var shapeFactory = this.get('shapeFactory');
  1060. if (!shapeFactory) {
  1061. var shapeType = this.get('shapeType');
  1062. shapeFactory = Shape.getShapeFactory(shapeType);
  1063. this.set('shapeFactory', shapeFactory);
  1064. }
  1065. return shapeFactory;
  1066. };
  1067. // step 3.2 mapping
  1068. Geom.prototype._mapping = function _mapping(data) {
  1069. var self = this;
  1070. var attrs = self.get('attrs');
  1071. var yField = self.getYScale().field;
  1072. var mappedData = [];
  1073. for (var i = 0, len = data.length; i < len; i++) {
  1074. var record = data[i];
  1075. var newRecord = {};
  1076. newRecord[FIELD_ORIGIN] = record[FIELD_ORIGIN];
  1077. newRecord.points = record.points;
  1078. // 避免
  1079. newRecord[FIELD_ORIGIN_Y] = record[yField];
  1080. for (var k in attrs) {
  1081. if (attrs.hasOwnProperty(k)) {
  1082. var attr = attrs[k];
  1083. var names = attr.names;
  1084. var values = self._getAttrValues(attr, record);
  1085. if (names.length > 1) {
  1086. // position 之类的生成多个字段的属性
  1087. for (var j = 0, _len = values.length; j < _len; j++) {
  1088. var val = values[j];
  1089. var name = names[j];
  1090. newRecord[name] = Util.isArray(val) && val.length === 1 ? val[0] : val; // 只有一个值时返回第一个属性值
  1091. }
  1092. } else {
  1093. newRecord[names[0]] = values.length === 1 ? values[0] : values;
  1094. }
  1095. }
  1096. }
  1097. mappedData.push(newRecord);
  1098. }
  1099. return mappedData;
  1100. };
  1101. // 获取属性映射的值
  1102. Geom.prototype._getAttrValues = function _getAttrValues(attr, record) {
  1103. var scales = attr.scales;
  1104. var params = [];
  1105. for (var i = 0, len = scales.length; i < len; i++) {
  1106. var scale = scales[i];
  1107. var field = scale.field;
  1108. if (scale.type === 'identity') {
  1109. params.push(scale.value);
  1110. } else {
  1111. params.push(record[field]);
  1112. }
  1113. }
  1114. var values = attr.mapping.apply(attr, params);
  1115. return values;
  1116. };
  1117. Geom.prototype.getAttrValue = function getAttrValue(attrName, record) {
  1118. var attr = this.getAttr(attrName);
  1119. var rst = null;
  1120. if (attr) {
  1121. var values = this._getAttrValues(attr, record);
  1122. rst = values[0];
  1123. }
  1124. return rst;
  1125. };
  1126. Geom.prototype._beforeMapping = function _beforeMapping(dataArray) {
  1127. var self = this;
  1128. if (self.get('sortable')) {
  1129. // 需要排序
  1130. self._sort(dataArray);
  1131. }
  1132. if (self.get('generatePoints')) {
  1133. Util.each(dataArray, function (data) {
  1134. self._generatePoints(data);
  1135. });
  1136. }
  1137. };
  1138. Geom.prototype.isInCircle = function isInCircle() {
  1139. var coord = this.get('coord');
  1140. return coord && coord.isPolar;
  1141. };
  1142. Geom.prototype.getCallbackCfg = function getCallbackCfg(fields, cfg, origin) {
  1143. if (!fields) {
  1144. return cfg;
  1145. }
  1146. var tmpCfg = {};
  1147. var params = fields.map(function (field) {
  1148. return origin[field];
  1149. });
  1150. Util.each(cfg, function (v, k) {
  1151. if (Util.isFunction(v)) {
  1152. tmpCfg[k] = v.apply(null, params);
  1153. } else {
  1154. tmpCfg[k] = v;
  1155. }
  1156. });
  1157. return tmpCfg;
  1158. };
  1159. Geom.prototype.getDrawCfg = function getDrawCfg(obj) {
  1160. var self = this;
  1161. var isInCircle = self.isInCircle();
  1162. var cfg = {
  1163. origin: obj,
  1164. x: obj.x,
  1165. y: obj.y,
  1166. color: obj.color,
  1167. size: obj.size,
  1168. shape: obj.shape,
  1169. isInCircle: isInCircle,
  1170. opacity: obj.opacity
  1171. };
  1172. var styleOptions = self.get('styleOptions');
  1173. if (styleOptions && styleOptions.style) {
  1174. cfg.style = self.getCallbackCfg(styleOptions.fields, styleOptions.style, obj[FIELD_ORIGIN]);
  1175. }
  1176. if (self.get('generatePoints')) {
  1177. cfg.points = obj.points;
  1178. }
  1179. if (isInCircle) {
  1180. cfg.center = self.get('coord').center;
  1181. }
  1182. return cfg;
  1183. };
  1184. Geom.prototype.draw = function draw(data, shapeFactory) {
  1185. var self = this;
  1186. var container = self.get('container');
  1187. var yScale = self.getYScale();
  1188. Util.each(data, function (obj, index) {
  1189. if (yScale && Util.isNil(obj._origin[yScale.field])) {
  1190. return;
  1191. }
  1192. obj.index = index;
  1193. var cfg = self.getDrawCfg(obj);
  1194. var shape = obj.shape;
  1195. self.drawShape(shape, obj, cfg, container, shapeFactory);
  1196. });
  1197. };
  1198. Geom.prototype.drawShape = function drawShape(shape, shapeData, cfg, container, shapeFactory) {
  1199. var gShape = shapeFactory.drawShape(shape, cfg, container);
  1200. if (gShape) {
  1201. Util.each([].concat(gShape), function (s) {
  1202. s.set('origin', shapeData); // todo
  1203. });
  1204. }
  1205. };
  1206. Geom.prototype._generatePoints = function _generatePoints(data) {
  1207. var self = this;
  1208. var shapeFactory = self.getShapeFactory();
  1209. var shapeAttr = self.getAttr('shape');
  1210. for (var i = 0, len = data.length; i < len; i++) {
  1211. var obj = data[i];
  1212. var cfg = self.createShapePointsCfg(obj);
  1213. var shape = shapeAttr ? self._getAttrValues(shapeAttr, obj) : null;
  1214. var points = shapeFactory.getShapePoints(shape, cfg);
  1215. obj.points = points;
  1216. }
  1217. };
  1218. /**
  1219. * 获取图形对应点的配置项
  1220. * @protected
  1221. * @param {Object} obj 数据对象
  1222. * @return {Object} cfg 获取图形对应点的配置项
  1223. */
  1224. Geom.prototype.createShapePointsCfg = function createShapePointsCfg(obj) {
  1225. var xScale = this.getXScale();
  1226. var yScale = this.getYScale();
  1227. var x = this._normalizeValues(obj[xScale.field], xScale);
  1228. var y = void 0; // 存在没有 y 的情况
  1229. if (yScale) {
  1230. y = this._normalizeValues(obj[yScale.field], yScale);
  1231. } else {
  1232. y = obj.y ? obj.y : 0.1;
  1233. }
  1234. return {
  1235. x: x,
  1236. y: y,
  1237. y0: yScale ? yScale.scale(this.getYMinValue()) : undefined
  1238. };
  1239. };
  1240. /**
  1241. * @protected
  1242. * @return {Number} y 轴上的最小值
  1243. */
  1244. Geom.prototype.getYMinValue = function getYMinValue() {
  1245. var yScale = this.getYScale();
  1246. var min = yScale.min,
  1247. max = yScale.max;
  1248. var value = void 0;
  1249. if (this.get('startOnZero')) {
  1250. if (max <= 0 && min <= 0) {
  1251. // 当值全部为负时,需要在现有范围内绘制
  1252. value = max;
  1253. } else {
  1254. value = min >= 0 ? min : 0;
  1255. }
  1256. } else {
  1257. value = min;
  1258. }
  1259. return value;
  1260. };
  1261. // 将数据归一化
  1262. Geom.prototype._normalizeValues = function _normalizeValues(values, scale) {
  1263. var rst = [];
  1264. if (Util.isArray(values)) {
  1265. for (var i = 0, len = values.length; i < len; i++) {
  1266. var v = values[i];
  1267. rst.push(scale.scale(v));
  1268. }
  1269. } else {
  1270. rst = scale.scale(values);
  1271. }
  1272. return rst;
  1273. };
  1274. /**
  1275. * 获取属性
  1276. * @protected
  1277. * @param {String} name 属性名
  1278. * @return {Scale} 度量
  1279. */
  1280. Geom.prototype.getAttr = function getAttr(name) {
  1281. return this.get('attrs')[name];
  1282. };
  1283. /**
  1284. * 获取 x 对应的度量
  1285. * @return {Scale} x 对应的度量
  1286. */
  1287. Geom.prototype.getXScale = function getXScale() {
  1288. return this.getAttr('position').scales[0];
  1289. };
  1290. /**
  1291. * 获取 y 对应的度量
  1292. * @return {Scale} y 对应的度量
  1293. */
  1294. Geom.prototype.getYScale = function getYScale() {
  1295. return this.getAttr('position').scales[1];
  1296. };
  1297. Geom.prototype.hasAdjust = function hasAdjust(adjust) {
  1298. return this.get('adjust') && this.get('adjust').type === adjust;
  1299. };
  1300. Geom.prototype._getSnap = function _getSnap(scale, item, arr) {
  1301. var i = 0;
  1302. var values = void 0;
  1303. var yField = this.getYScale().field; // 叠加的维度
  1304. if (this.hasAdjust('stack') && scale.field === yField) {
  1305. values = [];
  1306. arr.forEach(function (obj) {
  1307. values.push(obj[FIELD_ORIGIN_Y]);
  1308. });
  1309. for (var len = values.length; i < len; i++) {
  1310. if (values[0][0] > item) {
  1311. break;
  1312. }
  1313. if (values[values.length - 1][1] <= item) {
  1314. i = values.length - 1;
  1315. break;
  1316. }
  1317. if (values[i][0] <= item && values[i][1] > item) {
  1318. break;
  1319. }
  1320. }
  1321. } else {
  1322. values = scale.values;
  1323. values.sort(function (a, b) {
  1324. return a - b;
  1325. });
  1326. for (var _len2 = values.length; i < _len2; i++) {
  1327. if ((values[0] + values[1]) / 2 > item) {
  1328. break;
  1329. }
  1330. if ((values[i - 1] + values[i]) / 2 <= item && (values[i + 1] + values[i]) / 2 > item) {
  1331. break;
  1332. }
  1333. if ((values[values.length - 2] + values[values.length - 1]) / 2 <= item) {
  1334. i = values.length - 1;
  1335. break;
  1336. }
  1337. }
  1338. }
  1339. var result = values[i];
  1340. return result;
  1341. };
  1342. /**
  1343. * 根据画布坐标获取切割线对应数据集
  1344. * @param {Object} point 画布坐标的x,y的值
  1345. * @return {Array} 切割交点对应数据集
  1346. **/
  1347. Geom.prototype.getSnapRecords = function getSnapRecords(point) {
  1348. var self = this;
  1349. var coord = self.get('coord');
  1350. var xScale = self.getXScale();
  1351. var yScale = self.getYScale();
  1352. var xfield = xScale.field;
  1353. var dataArray = self.get('dataArray');
  1354. if (!this.get('hasSorted')) {
  1355. this._sort(dataArray);
  1356. }
  1357. var rst = [];
  1358. var invertPoint = coord.invertPoint(point);
  1359. var invertPointX = invertPoint.x;
  1360. if (self.isInCircle() && !coord.transposed && invertPointX > (1 + xScale.rangeMax()) / 2) {
  1361. invertPointX = xScale.rangeMin(); // 极坐标下,scale 的 range 被做过特殊处理 see chart.js#L183
  1362. }
  1363. var xValue = xScale.invert(invertPointX);
  1364. if (!xScale.isCategory) {
  1365. xValue = self._getSnap(xScale, xValue);
  1366. }
  1367. var tmp = [];
  1368. dataArray.forEach(function (data) {
  1369. data.forEach(function (obj) {
  1370. var originValue = Util.isNil(obj[FIELD_ORIGIN]) ? obj[xfield] : obj[FIELD_ORIGIN][xfield];
  1371. if (self._isEqual(originValue, xValue, xScale)) {
  1372. tmp.push(obj);
  1373. }
  1374. });
  1375. });
  1376. // 特别针对饼图做处理
  1377. if (this.hasAdjust('stack') && coord.isPolar && coord.transposed && xScale.values.length === 1) {
  1378. if (invertPointX >= 0 && invertPointX <= 1) {
  1379. // 精确拾取
  1380. var yValue = yScale.invert(invertPoint.y);
  1381. yValue = self._getSnap(yScale, yValue, tmp);
  1382. tmp.forEach(function (obj) {
  1383. if (Util.isArray(yValue) ? obj[FIELD_ORIGIN_Y].toString() === yValue.toString() : obj[FIELD_ORIGIN_Y] === yValue) {
  1384. rst.push(obj);
  1385. }
  1386. });
  1387. }
  1388. } else {
  1389. rst = tmp;
  1390. }
  1391. return rst;
  1392. };
  1393. Geom.prototype._isEqual = function _isEqual(originValue, value, scale) {
  1394. if (scale.type === 'timeCat') {
  1395. return scale._toTimeStamp(originValue) === value;
  1396. }
  1397. return value === originValue;
  1398. };
  1399. /**
  1400. * 位置属性映射
  1401. * @chainable
  1402. * @param {String} field 字段名
  1403. * @return {Geom} geom 当前几何标记
  1404. */
  1405. Geom.prototype.position = function position(field) {
  1406. this._setAttrOptions('position', {
  1407. field: field
  1408. });
  1409. return this;
  1410. };
  1411. /**
  1412. * 颜色属性映射
  1413. * @chainable
  1414. * @param {String} field 字段名
  1415. * @param {Array|Function} values 颜色的数组或者回调函数
  1416. * @return {Geom} geom 当前几何标记
  1417. */
  1418. Geom.prototype.color = function color(field, values) {
  1419. this._createAttrOption('color', field, values, Global.colors);
  1420. return this;
  1421. };
  1422. /**
  1423. * 大小属性映射
  1424. * @chainable
  1425. * @param {String} field 字段名
  1426. * @param {Array|Function} values 大小的数组或者回调函数
  1427. * @return {Geom} geom 当前几何标记
  1428. */
  1429. Geom.prototype.size = function size(field, values) {
  1430. this._createAttrOption('size', field, values, Global.sizes);
  1431. return this;
  1432. };
  1433. /**
  1434. * 形状属性映射
  1435. * @chainable
  1436. * @param {String} field 字段名
  1437. * @param {Array|Function} values 大小的数组或者回调函数
  1438. * @return {Geom} geom 当前几何标记
  1439. */
  1440. Geom.prototype.shape = function shape(field, values) {
  1441. var type = this.get('type');
  1442. var shapes = Global.shapes[type] || [];
  1443. this._createAttrOption('shape', field, values, shapes);
  1444. return this;
  1445. };
  1446. Geom.prototype.style = function style(field, cfg) {
  1447. var styleOptions = this.get('styleOptions');
  1448. if (!styleOptions) {
  1449. styleOptions = {};
  1450. this.set('styleOptions', styleOptions);
  1451. }
  1452. if (Util.isObject(field)) {
  1453. cfg = field;
  1454. field = null;
  1455. }
  1456. var fields = void 0;
  1457. if (field) {
  1458. fields = parseFields(field);
  1459. }
  1460. styleOptions.fields = fields;
  1461. styleOptions.style = cfg;
  1462. return this;
  1463. };
  1464. Geom.prototype.adjust = function adjust(type) {
  1465. if (Util.isString(type)) {
  1466. type = { type: type };
  1467. }
  1468. this.set('adjust', type);
  1469. return this;
  1470. };
  1471. Geom.prototype.animate = function animate(cfg) {
  1472. this.set('animateCfg', cfg);
  1473. return this;
  1474. };
  1475. Geom.prototype.reset = function reset() {
  1476. this.set('attrOptions', {});
  1477. this.set('adjust', null);
  1478. this.clearInner();
  1479. };
  1480. Geom.prototype.clearInner = function clearInner() {
  1481. var container = this.get('container');
  1482. if (container) {
  1483. container.clear();
  1484. container.setMatrix([1, 0, 0, 1, 0, 0]);
  1485. }
  1486. container && container.clear();
  1487. this.set('attrs', {});
  1488. this.set('groupScales', null);
  1489. this.set('xDistance', null);
  1490. };
  1491. Geom.prototype.clear = function clear() {
  1492. this.clearInner();
  1493. this.set('scales', {});
  1494. };
  1495. Geom.prototype.destroy = function destroy() {
  1496. this.clear();
  1497. // const container = this.get('container');
  1498. // container && container.remove();
  1499. _Base.prototype.destroy.call(this);
  1500. };
  1501. return Geom;
  1502. }(Base);
  1503. module.exports = Geom;
  1504. /***/ }),
  1505. /* 5 */
  1506. /***/ (function(module, exports, __webpack_require__) {
  1507. var Util = __webpack_require__(0);
  1508. var Global = __webpack_require__(1);
  1509. var Shape = {};
  1510. var ShapeBase = {
  1511. _coord: null,
  1512. /**
  1513. * 绘制图形
  1514. * @param {Object} cfg 配置项
  1515. * @param {Object} container 容器
  1516. */
  1517. draw: function draw(cfg, container) {
  1518. if (this.drawShape) {
  1519. this.drawShape(cfg, container);
  1520. }
  1521. },
  1522. /**
  1523. * 设置坐标系
  1524. * @param {Coord} coord 坐标系
  1525. */
  1526. setCoord: function setCoord(coord) {
  1527. this._coord = coord;
  1528. },
  1529. /**
  1530. * 0~1 point 转 画布 point
  1531. * @param {point} point 转换的点
  1532. * @return {point} point 转换结果
  1533. */
  1534. parsePoint: function parsePoint(point) {
  1535. var coord = this._coord;
  1536. if (coord.isPolar) {
  1537. if (point.x === 1) point.x = 0.9999999;
  1538. if (point.y === 1) point.y = 0.9999999;
  1539. }
  1540. return coord.convertPoint(point);
  1541. },
  1542. /**
  1543. * 0~1 points 转 画布 points
  1544. * @param {points} points 转换的多个点
  1545. * @return {points} points 转换结果
  1546. */
  1547. parsePoints: function parsePoints(points) {
  1548. if (!points) return false;
  1549. var self = this;
  1550. var rst = [];
  1551. points.forEach(function (point) {
  1552. rst.push(self.parsePoint(point));
  1553. });
  1554. return rst;
  1555. }
  1556. };
  1557. var ShapeFactoryBase = {
  1558. defaultShapeType: null,
  1559. setCoord: function setCoord(coord) {
  1560. this._coord = coord;
  1561. },
  1562. getShape: function getShape(type) {
  1563. var self = this;
  1564. if (Util.isArray(type)) {
  1565. type = type[0];
  1566. }
  1567. var shape = self[type] || self[self.defaultShapeType];
  1568. shape._coord = self._coord;
  1569. return shape;
  1570. },
  1571. getShapePoints: function getShapePoints(type, cfg) {
  1572. var shape = this.getShape(type);
  1573. var fn = shape.getPoints || shape.getShapePoints || this.getDefaultPoints;
  1574. var points = fn(cfg);
  1575. return points;
  1576. },
  1577. getDefaultPoints: function getDefaultPoints() /* cfg */{
  1578. return [];
  1579. },
  1580. drawShape: function drawShape(type, cfg, container) {
  1581. var shape = this.getShape(type);
  1582. if (!cfg.color) {
  1583. cfg.color = Global.colors[0];
  1584. }
  1585. return shape.draw(cfg, container);
  1586. }
  1587. };
  1588. // 注册 Geometry 获取图形的入口
  1589. Shape.registerFactory = function (factoryName, cfg) {
  1590. var className = Util.upperFirst(factoryName);
  1591. var geomObj = Util.mix({}, ShapeFactoryBase, cfg);
  1592. Shape[className] = geomObj;
  1593. geomObj.name = factoryName;
  1594. return geomObj;
  1595. };
  1596. // 注册图形
  1597. Shape.registerShape = function (factoryName, shapeType, cfg) {
  1598. var className = Util.upperFirst(factoryName);
  1599. var factory = Shape[className];
  1600. var shapeObj = Util.mix({}, ShapeBase, cfg);
  1601. factory[shapeType] = shapeObj;
  1602. return shapeObj;
  1603. };
  1604. Shape.registShape = Shape.registerShape;
  1605. // 获得Geom 对应的 shapeFactory
  1606. Shape.getShapeFactory = function (factoryName) {
  1607. var self = this;
  1608. factoryName = factoryName || 'point';
  1609. var className = Util.upperFirst(factoryName);
  1610. return self[className];
  1611. };
  1612. module.exports = Shape;
  1613. /***/ }),
  1614. /* 6 */
  1615. /***/ (function(module, exports, __webpack_require__) {
  1616. var G = {
  1617. Canvas: __webpack_require__(48),
  1618. Group: __webpack_require__(19),
  1619. Shape: __webpack_require__(2),
  1620. Matrix: __webpack_require__(14),
  1621. Vector2: __webpack_require__(3)
  1622. };
  1623. __webpack_require__(49);
  1624. __webpack_require__(50);
  1625. __webpack_require__(51);
  1626. __webpack_require__(52);
  1627. __webpack_require__(53);
  1628. __webpack_require__(54);
  1629. __webpack_require__(55);
  1630. __webpack_require__(56);
  1631. __webpack_require__(57);
  1632. module.exports = G;
  1633. /***/ }),
  1634. /* 7 */
  1635. /***/ (function(module, exports, __webpack_require__) {
  1636. var Vector2 = __webpack_require__(3);
  1637. var start = Vector2.create();
  1638. var end = Vector2.create();
  1639. var extremity = Vector2.create();
  1640. function getCubicBezierXYatT(startPt, controlPt1, controlPt2, endPt, T) {
  1641. var x = CubicN(T, startPt.x, controlPt1.x, controlPt2.x, endPt.x);
  1642. var y = CubicN(T, startPt.y, controlPt1.y, controlPt2.y, endPt.y);
  1643. return {
  1644. x: x,
  1645. y: y
  1646. };
  1647. }
  1648. // cubic helper formula at T distance
  1649. function CubicN(T, a, b, c, d) {
  1650. var t2 = T * T;
  1651. var t3 = t2 * T;
  1652. return a + (-a * 3 + T * (3 * a - a * T)) * T + (3 * b + T * (-6 * b + b * 3 * T)) * T + (c * 3 - c * 3 * T) * t2 + d * t3;
  1653. }
  1654. function cubicBezierBounds(c) {
  1655. var minX = Infinity;
  1656. var maxX = -Infinity;
  1657. var minY = Infinity;
  1658. var maxY = -Infinity;
  1659. var s = {
  1660. x: c[0],
  1661. y: c[1]
  1662. };
  1663. var c1 = {
  1664. x: c[2],
  1665. y: c[3]
  1666. };
  1667. var c2 = {
  1668. x: c[4],
  1669. y: c[5]
  1670. };
  1671. var e = {
  1672. x: c[6],
  1673. y: c[7]
  1674. };
  1675. for (var t = 0; t < 100; t++) {
  1676. var pt = getCubicBezierXYatT(s, c1, c2, e, t / 100);
  1677. if (pt.x < minX) {
  1678. minX = pt.x;
  1679. }
  1680. if (pt.x > maxX) {
  1681. maxX = pt.x;
  1682. }
  1683. if (pt.y < minY) {
  1684. minY = pt.y;
  1685. }
  1686. if (pt.y > maxY) {
  1687. maxY = pt.y;
  1688. }
  1689. }
  1690. return {
  1691. minX: minX,
  1692. minY: minY,
  1693. maxX: maxX,
  1694. maxY: maxY
  1695. };
  1696. }
  1697. module.exports = {
  1698. /**
  1699. * 从顶点数组中计算最小包围盒
  1700. * @param {Array} points 顶点数组
  1701. * @param {Number} lineWidth 线宽
  1702. * @return {Object} 最小包围盒的范围
  1703. */
  1704. getBBoxFromPoints: function getBBoxFromPoints(points) {
  1705. if (points.length === 0) {
  1706. return;
  1707. }
  1708. var p = points[0];
  1709. var left = p.x;
  1710. var right = p.x;
  1711. var top = p.y;
  1712. var bottom = p.y;
  1713. var len = points.length;
  1714. for (var i = 1; i < len; i++) {
  1715. p = points[i];
  1716. left = Math.min(left, p.x);
  1717. right = Math.max(right, p.x);
  1718. top = Math.min(top, p.y);
  1719. bottom = Math.max(bottom, p.y);
  1720. }
  1721. return {
  1722. minX: left,
  1723. minY: top,
  1724. maxX: right,
  1725. maxY: bottom
  1726. };
  1727. },
  1728. /**
  1729. * 计算线的最小包围盒
  1730. * @param {Number} x0 线段的起点 x
  1731. * @param {Number} y0 线段的起点 y
  1732. * @param {Number} x1 线段的终点 x
  1733. * @param {Number} y1 线段的终点 y
  1734. * @param {Number} lineWidth 线宽
  1735. * @return {Object} 线段的最小包围盒
  1736. */
  1737. getBBoxFromLine: function getBBoxFromLine(x0, y0, x1, y1) {
  1738. return {
  1739. minX: Math.min(x0, x1),
  1740. minY: Math.min(y0, y1),
  1741. maxX: Math.max(x0, x1),
  1742. maxY: Math.max(y0, y1)
  1743. };
  1744. },
  1745. getBBoxFromArc: function getBBoxFromArc(x, y, r, startAngle, endAngle, anticlockwise) {
  1746. var diff = Math.abs(startAngle - endAngle);
  1747. if (diff % Math.PI * 2 < 1e-4 && diff > 1e-4) {
  1748. // Is a circle
  1749. return {
  1750. minX: x - r,
  1751. minY: y - r,
  1752. maxX: x + r,
  1753. maxY: y + r
  1754. };
  1755. }
  1756. start[0] = Math.cos(startAngle) * r + x;
  1757. start[1] = Math.sin(startAngle) * r + y;
  1758. end[0] = Math.cos(endAngle) * r + x;
  1759. end[1] = Math.sin(endAngle) * r + y;
  1760. var min = [0, 0];
  1761. var max = [0, 0];
  1762. Vector2.min(min, start, end);
  1763. Vector2.max(max, start, end);
  1764. // Thresh to [0, Math.PI * 2]
  1765. startAngle = startAngle % (Math.PI * 2);
  1766. if (startAngle < 0) {
  1767. startAngle = startAngle + Math.PI * 2;
  1768. }
  1769. endAngle = endAngle % (Math.PI * 2);
  1770. if (endAngle < 0) {
  1771. endAngle = endAngle + Math.PI * 2;
  1772. }
  1773. if (startAngle > endAngle && !anticlockwise) {
  1774. endAngle += Math.PI * 2;
  1775. } else if (startAngle < endAngle && anticlockwise) {
  1776. startAngle += Math.PI * 2;
  1777. }
  1778. if (anticlockwise) {
  1779. var tmp = endAngle;
  1780. endAngle = startAngle;
  1781. startAngle = tmp;
  1782. }
  1783. for (var angle = 0; angle < endAngle; angle += Math.PI / 2) {
  1784. if (angle > startAngle) {
  1785. extremity[0] = Math.cos(angle) * r + x;
  1786. extremity[1] = Math.sin(angle) * r + y;
  1787. Vector2.min(min, extremity, min);
  1788. Vector2.max(max, extremity, max);
  1789. }
  1790. }
  1791. return {
  1792. minX: min[0],
  1793. minY: min[1],
  1794. maxX: max[0],
  1795. maxY: max[1]
  1796. };
  1797. },
  1798. getBBoxFromBezierGroup: function getBBoxFromBezierGroup(points) {
  1799. var minX = Infinity;
  1800. var maxX = -Infinity;
  1801. var minY = Infinity;
  1802. var maxY = -Infinity;
  1803. for (var i = 0, len = points.length; i < len; i++) {
  1804. var bbox = cubicBezierBounds(points[i]);
  1805. if (bbox.minX < minX) {
  1806. minX = bbox.minX;
  1807. }
  1808. if (bbox.maxX > maxX) {
  1809. maxX = bbox.maxX;
  1810. }
  1811. if (bbox.minY < minY) {
  1812. minY = bbox.minY;
  1813. }
  1814. if (bbox.maxY > maxY) {
  1815. maxY = bbox.maxY;
  1816. }
  1817. }
  1818. return {
  1819. minX: minX,
  1820. minY: minY,
  1821. maxX: maxX,
  1822. maxY: maxY
  1823. };
  1824. }
  1825. };
  1826. /***/ }),
  1827. /* 8 */
  1828. /***/ (function(module, exports, __webpack_require__) {
  1829. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  1830. /**
  1831. * @fileOverview the base class of scale
  1832. * @author dxq613@gmail.com
  1833. */
  1834. var Util = __webpack_require__(0);
  1835. /**
  1836. * 度量的构造函数
  1837. * @class Scale
  1838. */
  1839. var Scale = function () {
  1840. Scale.prototype._initDefaultCfg = function _initDefaultCfg() {
  1841. this.type = 'base';
  1842. /**
  1843. * 格式化函数,输出文本或者tick时的格式化函数
  1844. * @type {Function}
  1845. */
  1846. this.formatter = null;
  1847. /**
  1848. * 输出的值域
  1849. * @type {Array}
  1850. */
  1851. this.range = [0, 1];
  1852. /**
  1853. * 度量的标记
  1854. * @type {Array}
  1855. */
  1856. this.ticks = null;
  1857. /**
  1858. * 参与度量计算的值,可选项
  1859. * @type {Array}
  1860. */
  1861. this.values = [];
  1862. };
  1863. function Scale(cfg) {
  1864. _classCallCheck(this, Scale);
  1865. this._initDefaultCfg();
  1866. Util.mix(this, cfg);
  1867. this.init();
  1868. }
  1869. /**
  1870. * 度量初始化
  1871. * @protected
  1872. */
  1873. Scale.prototype.init = function init() {};
  1874. /**
  1875. * 获取该度量的ticks,返回的是多个对象,
  1876. * - text: tick 的文本
  1877. * - value: 对应的度量转换后的值
  1878. * <code>
  1879. * [
  1880. * {text: 0,value:0}
  1881. * {text: 1,value:0.2}
  1882. * {text: 2,value:0.4}
  1883. * {text: 3,value:0.6}
  1884. * {text: 4,value:0.8}
  1885. * {text: 5,value:1}
  1886. * ]
  1887. * </code>
  1888. * @param {Number} count 输出tick的个数的近似值,默认是 10
  1889. * @return {Array} 返回 ticks 数组
  1890. */
  1891. Scale.prototype.getTicks = function getTicks() {
  1892. var self = this;
  1893. var ticks = self.ticks;
  1894. var rst = [];
  1895. Util.each(ticks, function (tick) {
  1896. var obj = void 0;
  1897. if (Util.isObject(tick)) {
  1898. obj = tick;
  1899. } else {
  1900. obj = {
  1901. text: self.getText(tick),
  1902. tickValue: tick,
  1903. value: self.scale(tick)
  1904. };
  1905. }
  1906. rst.push(obj);
  1907. });
  1908. return rst;
  1909. };
  1910. /**
  1911. * 获取格式化后的文本
  1912. * @param {*} value 输入的数据
  1913. * @return {String} 格式化的文本
  1914. */
  1915. Scale.prototype.getText = function getText(value) {
  1916. var formatter = this.formatter;
  1917. value = formatter ? formatter(value) : value;
  1918. if (Util.isNil(value) || !value.toString) {
  1919. value = '';
  1920. }
  1921. return value.toString();
  1922. };
  1923. /**
  1924. * 输出的值域最小值
  1925. * @protected
  1926. * @return {Number} 返回最小的值
  1927. */
  1928. Scale.prototype.rangeMin = function rangeMin() {
  1929. return this.range[0];
  1930. };
  1931. /**
  1932. * 输出的值域最大值
  1933. * @protected
  1934. * @return {Number} 返回最大的值
  1935. */
  1936. Scale.prototype.rangeMax = function rangeMax() {
  1937. var range = this.range;
  1938. return range[range.length - 1];
  1939. };
  1940. /**
  1941. * 度量转换后的结果,翻转回输入域
  1942. * @param {Number} value 需要翻转的数值
  1943. * @return {*} 度量的输入值
  1944. */
  1945. Scale.prototype.invert = function invert(value) {
  1946. return value;
  1947. };
  1948. /**
  1949. * 将传入的值从非数值转换成数值格式,如分类字符串、时间字符串等
  1950. * @param {*} value 传入的值
  1951. * @return {Number} 转换的值
  1952. */
  1953. Scale.prototype.translate = function translate(value) {
  1954. return value;
  1955. };
  1956. /**
  1957. * 进行度量转换
  1958. * @param {*} value 输入值
  1959. * @return {Number} 输出值,在设定的输出值域之间,默认[0,1]
  1960. */
  1961. Scale.prototype.scale = function scale(value) {
  1962. return value;
  1963. };
  1964. /**
  1965. * 克隆一个新的scale,拥有跟当前scale相同的输入域、输出域等
  1966. * @return {Scale} 克隆的度量
  1967. */
  1968. Scale.prototype.clone = function clone() {
  1969. var self = this;
  1970. var constr = self.constructor;
  1971. var cfg = {};
  1972. Util.each(self, function (v, k) {
  1973. cfg[k] = self[k];
  1974. });
  1975. return new constr(cfg);
  1976. };
  1977. /**
  1978. * 更改度量的属性信息
  1979. * @param {Object} info 属性信息
  1980. * @chainable
  1981. * @return {Scale} 返回自身的引用
  1982. */
  1983. Scale.prototype.change = function change(info) {
  1984. this.ticks = null;
  1985. Util.mix(this, info);
  1986. this.init();
  1987. return this;
  1988. };
  1989. return Scale;
  1990. }();
  1991. module.exports = Scale;
  1992. /***/ }),
  1993. /* 9 */
  1994. /***/ (function(module, exports, __webpack_require__) {
  1995. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  1996. var Util = __webpack_require__(0);
  1997. var KEYWORDS_PERCENT = {
  1998. min: 0,
  1999. median: 0.5,
  2000. max: 1
  2001. };
  2002. var GuideBase = function () {
  2003. GuideBase.prototype._initDefaultCfg = function _initDefaultCfg() {};
  2004. function GuideBase(cfg) {
  2005. _classCallCheck(this, GuideBase);
  2006. this._initDefaultCfg();
  2007. Util.deepMix(this, cfg);
  2008. }
  2009. GuideBase.prototype._getNormalizedValue = function _getNormalizedValue(val, scale) {
  2010. var rst = void 0;
  2011. if (Util.isNil(KEYWORDS_PERCENT[val])) {
  2012. rst = scale.scale(val);
  2013. } else {
  2014. rst = KEYWORDS_PERCENT[val];
  2015. }
  2016. return rst;
  2017. };
  2018. GuideBase.prototype.parsePercentPoint = function parsePercentPoint(coord, position) {
  2019. var xPercent = parseFloat(position[0]) / 100;
  2020. var yPercent = parseFloat(position[1]) / 100;
  2021. var start = coord.start;
  2022. var end = coord.end;
  2023. var width = Math.abs(start.x - end.x);
  2024. var height = Math.abs(start.y - end.y);
  2025. var x = width * xPercent + Math.min(start.x, end.x);
  2026. var y = height * yPercent + Math.min(start.y, end.y);
  2027. return {
  2028. x: x,
  2029. y: y
  2030. };
  2031. };
  2032. GuideBase.prototype.parsePoint = function parsePoint(coord, position) {
  2033. var self = this;
  2034. var xScale = self.xScale;
  2035. var yScales = self.yScales;
  2036. if (Util.isFunction(position)) {
  2037. position = position(xScale, yScales); // position 必须是对象
  2038. }
  2039. // 如果数据格式是 ['50%', '50%'] 的格式
  2040. if (Util.isString(position[0]) && position[0].indexOf('%') !== -1) {
  2041. return this.parsePercentPoint(coord, position);
  2042. }
  2043. var x = self._getNormalizedValue(position[0], xScale);
  2044. var y = self._getNormalizedValue(position[1], yScales[0]);
  2045. return coord.convertPoint({
  2046. x: x,
  2047. y: y
  2048. });
  2049. };
  2050. /**
  2051. * 绘制辅助元素
  2052. * @param {Coord} coord 坐标系
  2053. * @param {Canvas.Group} group 绘制到的容器
  2054. */
  2055. GuideBase.prototype.render = function render() /* coord,group */{};
  2056. GuideBase.prototype.remove = function remove() {
  2057. var element = this.element;
  2058. element && element.remove(true);
  2059. };
  2060. return GuideBase;
  2061. }();
  2062. module.exports = GuideBase;
  2063. /***/ }),
  2064. /* 10 */
  2065. /***/ (function(module, exports, __webpack_require__) {
  2066. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  2067. var Util = __webpack_require__(0);
  2068. function toScaleString(scale, value) {
  2069. if (Util.isString(value)) {
  2070. return value;
  2071. }
  2072. return scale.invert(scale.scale(value));
  2073. }
  2074. var AttributeBase = function () {
  2075. function AttributeBase(cfg) {
  2076. _classCallCheck(this, AttributeBase);
  2077. /**
  2078. * 属性的类型
  2079. * @type {String}
  2080. */
  2081. this.type = 'base';
  2082. /**
  2083. * 属性的名称
  2084. * @type {String}
  2085. */
  2086. this.name = null;
  2087. /**
  2088. * 回调函数
  2089. * @type {Function}
  2090. */
  2091. this.method = null;
  2092. /**
  2093. * 备选的值数组
  2094. * @type {Array}
  2095. */
  2096. this.values = [];
  2097. /**
  2098. * 属性内部的度量
  2099. * @type {Array}
  2100. */
  2101. this.scales = [];
  2102. /**
  2103. * 是否通过线性取值, 如果未指定,则根据数值的类型判定
  2104. * @type {Boolean}
  2105. */
  2106. this.linear = null;
  2107. Util.mix(this, cfg);
  2108. }
  2109. // 获取属性值,将值映射到视觉通道
  2110. AttributeBase.prototype._getAttrValue = function _getAttrValue(scale, value) {
  2111. var values = this.values;
  2112. if (scale.isCategory && !this.linear) {
  2113. var index = scale.translate(value);
  2114. return values[index % values.length];
  2115. }
  2116. var percent = scale.scale(value);
  2117. return this.getLinearValue(percent);
  2118. };
  2119. /**
  2120. * 如果进行线性映射,返回对应的映射值
  2121. * @protected
  2122. * @param {Number} percent 百分比
  2123. * @return {*} 颜色值、形状、大小等
  2124. */
  2125. AttributeBase.prototype.getLinearValue = function getLinearValue(percent) {
  2126. var values = this.values;
  2127. var steps = values.length - 1;
  2128. var step = Math.floor(steps * percent);
  2129. var leftPercent = steps * percent - step;
  2130. var start = values[step];
  2131. var end = step === steps ? start : values[step + 1];
  2132. var rstValue = start + (end - start) * leftPercent;
  2133. return rstValue;
  2134. };
  2135. /**
  2136. * 默认的回调函数
  2137. * @param {*} value 回调函数的值
  2138. * @type {Function}
  2139. * @return {Array} 返回映射后的值
  2140. */
  2141. AttributeBase.prototype.callback = function callback(value) {
  2142. var self = this;
  2143. var scale = self.scales[0];
  2144. var rstValue = null;
  2145. if (scale.type === 'identity') {
  2146. rstValue = scale.value;
  2147. } else {
  2148. rstValue = self._getAttrValue(scale, value);
  2149. }
  2150. return rstValue;
  2151. };
  2152. /**
  2153. * 根据度量获取属性名
  2154. * @return {Array} dims of this Attribute
  2155. */
  2156. AttributeBase.prototype.getNames = function getNames() {
  2157. var scales = this.scales;
  2158. var names = this.names;
  2159. var length = Math.min(scales.length, names.length);
  2160. var rst = [];
  2161. for (var i = 0; i < length; i++) {
  2162. rst.push(names[i]);
  2163. }
  2164. return rst;
  2165. };
  2166. /**
  2167. * 根据度量获取维度名
  2168. * @return {Array} dims of this Attribute
  2169. */
  2170. AttributeBase.prototype.getFields = function getFields() {
  2171. var scales = this.scales;
  2172. var rst = [];
  2173. Util.each(scales, function (scale) {
  2174. rst.push(scale.field);
  2175. });
  2176. return rst;
  2177. };
  2178. /**
  2179. * 根据名称获取度量
  2180. * @param {String} name the name of scale
  2181. * @return {Scale} scale
  2182. */
  2183. AttributeBase.prototype.getScale = function getScale(name) {
  2184. var scales = this.scales;
  2185. var names = this.names;
  2186. var index = names.indexOf(name);
  2187. return scales[index];
  2188. };
  2189. /**
  2190. * 映射数据
  2191. * @param {*} param1...paramn 多个数值
  2192. * @return {Array} 映射的值组成的数组
  2193. */
  2194. AttributeBase.prototype.mapping = function mapping() {
  2195. var scales = this.scales;
  2196. var callback = this.callback;
  2197. for (var _len = arguments.length, params = Array(_len), _key = 0; _key < _len; _key++) {
  2198. params[_key] = arguments[_key];
  2199. }
  2200. var values = params;
  2201. if (callback) {
  2202. for (var i = 0, len = params.length; i < len; i++) {
  2203. params[i] = this._toOriginParam(params[i], scales[i]);
  2204. }
  2205. values = callback.apply(this, params);
  2206. }
  2207. if (!Util.isArray(values)) {
  2208. values = [values];
  2209. }
  2210. return values;
  2211. };
  2212. // 原始的参数
  2213. AttributeBase.prototype._toOriginParam = function _toOriginParam(param, scale) {
  2214. var rst = param;
  2215. if (!scale.isLinear) {
  2216. if (Util.isArray(param)) {
  2217. rst = [];
  2218. for (var i = 0, len = param.length; i < len; i++) {
  2219. rst.push(toScaleString(scale, param[i]));
  2220. }
  2221. } else {
  2222. rst = toScaleString(scale, param);
  2223. }
  2224. }
  2225. return rst;
  2226. };
  2227. return AttributeBase;
  2228. }();
  2229. module.exports = AttributeBase;
  2230. /***/ }),
  2231. /* 11 */
  2232. /***/ (function(module, exports, __webpack_require__) {
  2233. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  2234. /**
  2235. * @fileOverview 数据调整的基类
  2236. * @author dxq613@gmail.com
  2237. */
  2238. var Util = __webpack_require__(0);
  2239. var Base = function () {
  2240. Base.prototype._initDefaultCfg = function _initDefaultCfg() {};
  2241. function Base(cfg) {
  2242. _classCallCheck(this, Base);
  2243. this._initDefaultCfg();
  2244. Util.mix(this, cfg);
  2245. }
  2246. Base.prototype.processAdjust = function processAdjust() /* dataArray */{};
  2247. return Base;
  2248. }();
  2249. module.exports = Base;
  2250. /***/ }),
  2251. /* 12 */
  2252. /***/ (function(module, exports, __webpack_require__) {
  2253. /**
  2254. * @fileOverview shape util
  2255. * @author dxq613@gmail.com
  2256. */
  2257. var Util = __webpack_require__(0);
  2258. var ShapeUtil = {
  2259. splitPoints: function splitPoints(obj) {
  2260. var points = [];
  2261. var x = obj.x;
  2262. var y = obj.y;
  2263. y = Util.isArray(y) ? y : [y];
  2264. y.forEach(function (yItem, index) {
  2265. var point = {
  2266. x: Util.isArray(x) ? x[index] : x,
  2267. y: yItem
  2268. };
  2269. points.push(point);
  2270. });
  2271. return points;
  2272. },
  2273. splitArray: function splitArray(data, yField, connectNulls) {
  2274. if (!data.length) return [];
  2275. var arr = [];
  2276. var tmp = [];
  2277. var yValue = void 0;
  2278. Util.each(data, function (obj) {
  2279. yValue = obj._origin ? obj._origin[yField] : obj[yField];
  2280. if (connectNulls) {
  2281. if (!Util.isNil(yValue)) {
  2282. tmp.push(obj);
  2283. }
  2284. } else {
  2285. if (Util.isArray(yValue) && Util.isNil(yValue[0]) || Util.isNil(yValue)) {
  2286. if (tmp.length) {
  2287. arr.push(tmp);
  2288. tmp = [];
  2289. }
  2290. } else {
  2291. tmp.push(obj);
  2292. }
  2293. }
  2294. });
  2295. if (tmp.length) {
  2296. arr.push(tmp);
  2297. }
  2298. return arr;
  2299. }
  2300. };
  2301. module.exports = ShapeUtil;
  2302. /***/ }),
  2303. /* 13 */
  2304. /***/ (function(module, exports, __webpack_require__) {
  2305. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  2306. var Util = __webpack_require__(0);
  2307. var Base = function () {
  2308. Base.prototype._initDefaultCfg = function _initDefaultCfg() {};
  2309. function Base(cfg) {
  2310. _classCallCheck(this, Base);
  2311. this._initDefaultCfg();
  2312. Util.mix(this, cfg);
  2313. var start = void 0;
  2314. var end = void 0;
  2315. if (this.plot) {
  2316. start = this.plot.bl;
  2317. end = this.plot.tr;
  2318. this.start = start;
  2319. this.end = end;
  2320. } else {
  2321. start = this.start;
  2322. end = this.end;
  2323. }
  2324. this.init(start, end);
  2325. }
  2326. Base.prototype.init = function init() {};
  2327. Base.prototype.convertPoint = function convertPoint(point) {
  2328. return point;
  2329. };
  2330. Base.prototype.invertPoint = function invertPoint(point) {
  2331. return point;
  2332. };
  2333. Base.prototype.reset = function reset(plot) {
  2334. this.plot = plot;
  2335. var bl = plot.bl,
  2336. tr = plot.tr;
  2337. this.start = bl;
  2338. this.end = tr;
  2339. this.init(bl, tr);
  2340. };
  2341. return Base;
  2342. }();
  2343. module.exports = Base;
  2344. /***/ }),
  2345. /* 14 */
  2346. /***/ (function(module, exports) {
  2347. var Matrix = {
  2348. /**
  2349. * 两个矩阵相乘
  2350. * @param {Array} m1 左矩阵
  2351. * @param {Array} m2 右矩阵
  2352. * @return {Array} 返回结果
  2353. */
  2354. multiply: function multiply(m1, m2) {
  2355. var m11 = m1[0] * m2[0] + m1[2] * m2[1];
  2356. var m12 = m1[1] * m2[0] + m1[3] * m2[1];
  2357. var m21 = m1[0] * m2[2] + m1[2] * m2[3];
  2358. var m22 = m1[1] * m2[2] + m1[3] * m2[3];
  2359. var dx = m1[0] * m2[4] + m1[2] * m2[5] + m1[4];
  2360. var dy = m1[1] * m2[4] + m1[3] * m2[5] + m1[5];
  2361. return [m11, m12, m21, m22, dx, dy];
  2362. },
  2363. /**
  2364. * 矩阵反转
  2365. * @param {Array} m 参数
  2366. * @return {Array} 返回结果
  2367. */
  2368. // invert(m) {
  2369. // const d = 1 / (m[0] * m[3] - m[1] * m[2]);
  2370. // const m0 = m[3] * d;
  2371. // const m1 = -m[1] * d;
  2372. // const m2 = -m[2] * d;
  2373. // const m3 = m[0] * d;
  2374. // const m4 = d * (m[2] * m[5] - m[3] * m[4]);
  2375. // const m5 = d * (m[1] * m[4] - m[0] * m[5]);
  2376. // return [ m0, m1, m2, m3, m4, m5 ];
  2377. // },
  2378. scale: function scale(out, m, v) {
  2379. out[0] = m[0] * v[0];
  2380. out[1] = m[1] * v[0];
  2381. out[2] = m[2] * v[1];
  2382. out[3] = m[3] * v[1];
  2383. out[4] = m[4];
  2384. out[5] = m[5];
  2385. return out;
  2386. },
  2387. rotate: function rotate(out, m, radian) {
  2388. var c = Math.cos(radian);
  2389. var s = Math.sin(radian);
  2390. var m11 = m[0] * c + m[2] * s;
  2391. var m12 = m[1] * c + m[3] * s;
  2392. var m21 = m[0] * -s + m[2] * c;
  2393. var m22 = m[1] * -s + m[3] * c;
  2394. out[0] = m11;
  2395. out[1] = m12;
  2396. out[2] = m21;
  2397. out[3] = m22;
  2398. out[4] = m[4];
  2399. out[5] = m[5];
  2400. return out;
  2401. },
  2402. translate: function translate(out, m, v) {
  2403. out[0] = m[0];
  2404. out[1] = m[1];
  2405. out[2] = m[2];
  2406. out[3] = m[3];
  2407. out[4] = m[4] + m[0] * v[0] + m[2] * v[1];
  2408. out[5] = m[5] + m[1] * v[0] + m[3] * v[1];
  2409. return out;
  2410. },
  2411. transform: function transform(m, actions) {
  2412. var out = [].concat(m);
  2413. for (var i = 0, len = actions.length; i < len; i++) {
  2414. var action = actions[i];
  2415. switch (action[0]) {
  2416. case 't':
  2417. Matrix.translate(out, out, [action[1], action[2]]);
  2418. break;
  2419. case 's':
  2420. Matrix.scale(out, out, [action[1], action[2]]);
  2421. break;
  2422. case 'r':
  2423. Matrix.rotate(out, out, action[1]);
  2424. break;
  2425. default:
  2426. break;
  2427. }
  2428. }
  2429. return out;
  2430. }
  2431. };
  2432. module.exports = Matrix;
  2433. /***/ }),
  2434. /* 15 */
  2435. /***/ (function(module, exports, __webpack_require__) {
  2436. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  2437. var Util = __webpack_require__(0);
  2438. var Global = __webpack_require__(1);
  2439. var Vector2 = __webpack_require__(3);
  2440. var Abastract = function () {
  2441. Abastract.prototype._initDefaultCfg = function _initDefaultCfg() {
  2442. /**
  2443. * 坐标点
  2444. * @type {Array}
  2445. */
  2446. this.ticks = [];
  2447. /**
  2448. * tick 的配置信息
  2449. * @type {Object}
  2450. */
  2451. this.tickLine = {};
  2452. /**
  2453. * 文本、tick跟坐标轴线的方向,默认是顺时针方向
  2454. * @type {Number}
  2455. */
  2456. this.offsetFactor = 1;
  2457. /**
  2458. * 上层图层
  2459. * @type {container}
  2460. */
  2461. this.frontContainer = null;
  2462. /**
  2463. * 下层图层
  2464. * @type {[type]}
  2465. */
  2466. this.backContainer = null;
  2467. /**
  2468. * 绘制栅格的点
  2469. * @type {Array}
  2470. */
  2471. this.gridPoints = [];
  2472. };
  2473. function Abastract(cfg) {
  2474. _classCallCheck(this, Abastract);
  2475. this._initDefaultCfg();
  2476. Util.mix(this, cfg);
  2477. this.draw();
  2478. }
  2479. Abastract.prototype.draw = function draw() {
  2480. var line = this.line,
  2481. tickLine = this.tickLine,
  2482. label = this.label,
  2483. grid = this.grid;
  2484. grid && this.drawGrid(grid); // 渲染网格
  2485. tickLine && this.drawTicks(tickLine); // 渲染刻度线
  2486. line && this.drawLine(line); // 渲染轴线
  2487. label && this.drawLabels(); // 渲染坐标轴文本
  2488. };
  2489. Abastract.prototype.drawTicks = function drawTicks(tickCfg) {
  2490. var self = this;
  2491. var ticks = self.ticks;
  2492. var length = tickCfg.length; // Change: value 改为 length, 同 G2 统一
  2493. var container = self.getContainer(tickCfg.top);
  2494. Util.each(ticks, function (tick) {
  2495. var start = self.getOffsetPoint(tick.value);
  2496. var end = self.getSidePoint(start, length);
  2497. var shape = container.addShape('line', {
  2498. className: 'axis-tick',
  2499. attrs: Util.mix({
  2500. x1: start.x,
  2501. y1: start.y,
  2502. x2: end.x,
  2503. y2: end.y
  2504. }, tickCfg)
  2505. });
  2506. shape._id = self._id + '-ticks';
  2507. });
  2508. };
  2509. Abastract.prototype.drawLabels = function drawLabels() {
  2510. var self = this;
  2511. var labelOffset = self.labelOffset;
  2512. var labels = self.labels;
  2513. Util.each(labels, function (labelShape) {
  2514. var container = self.getContainer(labelShape.get('top'));
  2515. var start = self.getOffsetPoint(labelShape.get('value'));
  2516. var _self$getSidePoint = self.getSidePoint(start, labelOffset),
  2517. x = _self$getSidePoint.x,
  2518. y = _self$getSidePoint.y;
  2519. labelShape.attr(Util.mix({
  2520. x: x,
  2521. y: y
  2522. }, self.getTextAlignInfo(start, labelOffset), labelShape.get('textStyle')));
  2523. labelShape._id = self._id + '-' + labelShape.attr('text');
  2524. container.add(labelShape);
  2525. });
  2526. };
  2527. Abastract.prototype.drawLine = function drawLine() {};
  2528. Abastract.prototype.drawGrid = function drawGrid(grid) {
  2529. var self = this;
  2530. var gridPoints = self.gridPoints,
  2531. ticks = self.ticks;
  2532. var gridCfg = grid;
  2533. var count = gridPoints.length;
  2534. Util.each(gridPoints, function (subPoints, index) {
  2535. if (Util.isFunction(grid)) {
  2536. var tick = ticks[index] || {};
  2537. gridCfg = Util.mix({}, Global._defaultAxis.grid, grid(tick.text, index, count));
  2538. }
  2539. if (gridCfg) {
  2540. var type = gridCfg.type; // grid 的类型,包含 'line' 以及 'arc'
  2541. var points = subPoints.points;
  2542. var container = self.getContainer(gridCfg.top);
  2543. var shape = void 0;
  2544. if (type === 'arc') {
  2545. var center = self.center,
  2546. startAngle = self.startAngle,
  2547. endAngle = self.endAngle;
  2548. var radius = Vector2.length([points[0].x - center.x, points[0].y - center.y]);
  2549. shape = container.addShape('Arc', {
  2550. className: 'axis-grid',
  2551. attrs: Util.mix({
  2552. x: center.x,
  2553. y: center.y,
  2554. startAngle: startAngle,
  2555. endAngle: endAngle,
  2556. r: radius
  2557. }, gridCfg)
  2558. });
  2559. } else {
  2560. shape = container.addShape('Polyline', {
  2561. className: 'axis-grid',
  2562. attrs: Util.mix({
  2563. points: points
  2564. }, gridCfg)
  2565. });
  2566. }
  2567. shape._id = subPoints._id;
  2568. }
  2569. });
  2570. };
  2571. // 获取坐标轴上的点
  2572. Abastract.prototype.getOffsetPoint = function getOffsetPoint() {};
  2573. // 获取坐标轴上点的向量,极坐标下覆盖此方法
  2574. Abastract.prototype.getAxisVector = function getAxisVector() {};
  2575. // 获取偏移位置的向量
  2576. Abastract.prototype.getOffsetVector = function getOffsetVector(point, offset) {
  2577. var self = this;
  2578. var axisVector = self.getAxisVector(point);
  2579. var normal = Vector2.normalize([], axisVector);
  2580. var factor = self.offsetFactor;
  2581. var verticalVector = [normal[1] * -1 * factor, normal[0] * factor];
  2582. return Vector2.scale([], verticalVector, offset);
  2583. };
  2584. // 获取坐标轴边上的点
  2585. Abastract.prototype.getSidePoint = function getSidePoint(point, offset) {
  2586. var self = this;
  2587. var offsetVector = self.getOffsetVector(point, offset);
  2588. return {
  2589. x: point.x + offsetVector[0],
  2590. y: point.y + offsetVector[1]
  2591. };
  2592. };
  2593. // 获取文本,水平和垂直方向的对齐方式
  2594. Abastract.prototype.getTextAlignInfo = function getTextAlignInfo(point, offset) {
  2595. var self = this;
  2596. var offsetVector = self.getOffsetVector(point, offset);
  2597. var align = void 0;
  2598. var baseLine = void 0;
  2599. if (offsetVector[0] > 0) {
  2600. align = 'left';
  2601. } else if (offsetVector[0] < 0) {
  2602. align = 'right';
  2603. } else {
  2604. align = 'center';
  2605. }
  2606. if (offsetVector[1] > 0) {
  2607. baseLine = 'top';
  2608. } else if (offsetVector[1] < 0) {
  2609. baseLine = 'bottom';
  2610. } else {
  2611. baseLine = 'middle';
  2612. }
  2613. return {
  2614. textAlign: align,
  2615. textBaseline: baseLine
  2616. };
  2617. };
  2618. Abastract.prototype.getContainer = function getContainer(isTop) {
  2619. var frontContainer = this.frontContainer,
  2620. backContainer = this.backContainer;
  2621. return isTop ? frontContainer : backContainer;
  2622. };
  2623. return Abastract;
  2624. }();
  2625. module.exports = Abastract;
  2626. /***/ }),
  2627. /* 16 */
  2628. /***/ (function(module, exports, __webpack_require__) {
  2629. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  2630. var Util = __webpack_require__(0);
  2631. var MatrixUtil = __webpack_require__(14);
  2632. var Vector2 = __webpack_require__(3);
  2633. // 是否未改变
  2634. function isUnchanged(m) {
  2635. return m[0] === 1 && m[1] === 0 && m[2] === 0 && m[3] === 1 && m[4] === 0 && m[5] === 0;
  2636. }
  2637. var ALIAS_ATTRS_MAP = {
  2638. stroke: 'strokeStyle',
  2639. fill: 'fillStyle',
  2640. opacity: 'globalAlpha'
  2641. };
  2642. var SHAPE_ATTRS = ['fillStyle', 'font', 'globalAlpha', 'lineCap', 'lineWidth', 'lineJoin', 'miterLimit', 'shadowBlur', 'shadowColor', 'shadowOffsetX', 'shadowOffsetY', 'strokeStyle', 'textAlign', 'textBaseline', 'lineDash'];
  2643. var CLIP_SHAPES = ['circle', 'sector', 'polygon', 'rect', 'polyline'];
  2644. var Element = function () {
  2645. Element.prototype._initProperties = function _initProperties() {
  2646. this._attrs = {
  2647. zIndex: 0,
  2648. visible: true,
  2649. destroyed: false
  2650. };
  2651. };
  2652. function Element(cfg) {
  2653. _classCallCheck(this, Element);
  2654. this._initProperties();
  2655. Util.mix(this._attrs, cfg);
  2656. var attrs = this._attrs.attrs;
  2657. if (attrs) {
  2658. // 初始化图形属性
  2659. this.initAttrs(attrs);
  2660. }
  2661. this.initTransform(); // 初始化变换
  2662. }
  2663. Element.prototype.get = function get(name) {
  2664. return this._attrs[name];
  2665. };
  2666. Element.prototype.set = function set(name, value) {
  2667. this._attrs[name] = value;
  2668. };
  2669. Element.prototype.initAttrs = function initAttrs(attrs) {
  2670. this.attr(Util.mix(this.getDefaultAttrs(), attrs));
  2671. };
  2672. Element.prototype.getDefaultAttrs = function getDefaultAttrs() {
  2673. return {};
  2674. };
  2675. Element.prototype._setAttr = function _setAttr(name, value) {
  2676. var attrs = this._attrs.attrs;
  2677. if (name === 'clip') {
  2678. value = this._setAttrClip(value);
  2679. } else {
  2680. var alias = ALIAS_ATTRS_MAP[name];
  2681. if (alias) {
  2682. attrs[alias] = value;
  2683. }
  2684. }
  2685. attrs[name] = value;
  2686. };
  2687. Element.prototype._getAttr = function _getAttr(name) {
  2688. return this._attrs.attrs[name];
  2689. };
  2690. // _afterAttrsSet() {}
  2691. Element.prototype._setAttrClip = function _setAttrClip(clip) {
  2692. if (clip && CLIP_SHAPES.indexOf(clip._attrs.type) > -1) {
  2693. if (clip.get('canvas') === null) {
  2694. clip = Object.assign({}, clip);
  2695. }
  2696. clip.set('parent', this.get('parent'));
  2697. clip.set('context', this.get('context'));
  2698. return clip;
  2699. }
  2700. return null;
  2701. };
  2702. Element.prototype.attr = function attr(name, value) {
  2703. var self = this;
  2704. if (self.get('destroyed')) return null;
  2705. var argumentsLen = arguments.length;
  2706. if (argumentsLen === 0) {
  2707. return self._attrs.attrs;
  2708. }
  2709. if (Util.isObject(name)) {
  2710. this._attrs.bbox = null; // attr 改变了有可能会导致 bbox 改变,故在此清除
  2711. for (var k in name) {
  2712. self._setAttr(k, name[k]);
  2713. }
  2714. if (self._afterAttrsSet) {
  2715. self._afterAttrsSet();
  2716. }
  2717. return self;
  2718. }
  2719. if (argumentsLen === 2) {
  2720. this._attrs.bbox = null;
  2721. self._setAttr(name, value);
  2722. if (self._afterAttrsSet) {
  2723. self._afterAttrsSet();
  2724. }
  2725. return self;
  2726. }
  2727. return self._getAttr(name);
  2728. };
  2729. Element.prototype.getParent = function getParent() {
  2730. return this.get('parent');
  2731. };
  2732. Element.prototype.draw = function draw(context) {
  2733. if (this.get('destroyed')) {
  2734. return;
  2735. }
  2736. if (this.get('visible')) {
  2737. this.setContext(context);
  2738. this.drawInner(context);
  2739. this.restoreContext(context);
  2740. }
  2741. };
  2742. Element.prototype.setContext = function setContext(context) {
  2743. var clip = this._attrs.attrs.clip;
  2744. context.save();
  2745. if (clip) {
  2746. clip.resetTransform(context);
  2747. clip.createPath(context);
  2748. context.clip();
  2749. }
  2750. this.resetContext(context);
  2751. this.resetTransform(context);
  2752. };
  2753. Element.prototype.restoreContext = function restoreContext(context) {
  2754. context.restore();
  2755. };
  2756. Element.prototype.resetContext = function resetContext(context) {
  2757. var elAttrs = this._attrs.attrs;
  2758. if (!this.get('isGroup')) {
  2759. for (var k in elAttrs) {
  2760. if (SHAPE_ATTRS.indexOf(k) > -1) {
  2761. // 非canvas属性不附加
  2762. var v = elAttrs[k];
  2763. if (k === 'lineDash' && context.setLineDash && v) {
  2764. context.setLineDash(v);
  2765. } else {
  2766. context[k] = v;
  2767. }
  2768. }
  2769. }
  2770. }
  2771. };
  2772. Element.prototype.hasFill = function hasFill() {
  2773. return this.get('canFill') && this._attrs.attrs.fillStyle;
  2774. };
  2775. Element.prototype.hasStroke = function hasStroke() {
  2776. return this.get('canStroke') && this._attrs.attrs.strokeStyle;
  2777. };
  2778. Element.prototype.drawInner = function drawInner() /* context */{};
  2779. Element.prototype.show = function show() {
  2780. this.set('visible', true);
  2781. return this;
  2782. };
  2783. Element.prototype.hide = function hide() {
  2784. this.set('visible', false);
  2785. return this;
  2786. };
  2787. Element.prototype._removeFromParent = function _removeFromParent() {
  2788. var parent = this.get('parent');
  2789. if (parent) {
  2790. var children = parent.get('children');
  2791. Util.Array.remove(children, this);
  2792. }
  2793. return this;
  2794. };
  2795. /**
  2796. * 移除
  2797. * @param {Boolean} destroy true 表示将自己移除的同时销毁自己,false 表示仅移除自己
  2798. */
  2799. Element.prototype.remove = function remove(destroy) {
  2800. if (destroy) {
  2801. this.destroy();
  2802. } else {
  2803. this._removeFromParent();
  2804. }
  2805. };
  2806. Element.prototype.destroy = function destroy() {
  2807. // 销毁并将自己从父元素中移除(如果有父元素的话)
  2808. var destroyed = this.get('destroyed');
  2809. if (destroyed) {
  2810. return null;
  2811. }
  2812. this._removeFromParent();
  2813. this._attrs = {};
  2814. this.set('destroyed', true);
  2815. };
  2816. Element.prototype.getBBox = function getBBox() {
  2817. return {
  2818. minX: 0,
  2819. maxX: 0,
  2820. minY: 0,
  2821. maxY: 0
  2822. };
  2823. };
  2824. Element.prototype.initTransform = function initTransform() {
  2825. var attrs = this._attrs.attrs || {};
  2826. if (!attrs.matrix) {
  2827. attrs.matrix = [1, 0, 0, 1, 0, 0];
  2828. }
  2829. this._attrs.attrs = attrs;
  2830. };
  2831. Element.prototype.getMatrix = function getMatrix() {
  2832. return this._attrs.attrs.matrix;
  2833. };
  2834. Element.prototype.setMatrix = function setMatrix(m) {
  2835. this._attrs.attrs.matrix = [m[0], m[1], m[2], m[3], m[4], m[5]];
  2836. };
  2837. /**
  2838. * 平移、旋转、缩放
  2839. * @param {Array} actions 操作集合
  2840. * @return {Element} 返回自身
  2841. */
  2842. Element.prototype.transform = function transform(actions) {
  2843. var matrix = this._attrs.attrs.matrix;
  2844. this._attrs.attrs.matrix = MatrixUtil.transform(matrix, actions);
  2845. return this;
  2846. };
  2847. Element.prototype.setTransform = function setTransform(actions) {
  2848. this._attrs.attrs.matrix = [1, 0, 0, 1, 0, 0];
  2849. return this.transform(actions);
  2850. };
  2851. Element.prototype.translate = function translate(x, y) {
  2852. var matrix = this._attrs.attrs.matrix;
  2853. MatrixUtil.translate(matrix, matrix, [x, y]);
  2854. };
  2855. Element.prototype.rotate = function rotate(rad) {
  2856. var matrix = this._attrs.attrs.matrix;
  2857. MatrixUtil.rotate(matrix, matrix, rad);
  2858. };
  2859. Element.prototype.scale = function scale(sx, sy) {
  2860. var matrix = this._attrs.attrs.matrix;
  2861. MatrixUtil.scale(matrix, matrix, [sx, sy]);
  2862. };
  2863. /**
  2864. * 移动的到位置
  2865. * @param {Number} x 移动到x
  2866. * @param {Number} y 移动到y
  2867. */
  2868. Element.prototype.moveTo = function moveTo(x, y) {
  2869. var cx = this._attrs.x || 0; // 当前的x
  2870. var cy = this._attrs.y || 0; // 当前的y
  2871. this.translate(x - cx, y - cy);
  2872. this.set('x', x);
  2873. this.set('y', y);
  2874. };
  2875. Element.prototype.apply = function apply(v) {
  2876. var m = this._attrs.attrs.matrix;
  2877. Vector2.transformMat2d(v, v, m);
  2878. return this;
  2879. };
  2880. Element.prototype.resetTransform = function resetTransform(context) {
  2881. var mo = this._attrs.attrs.matrix;
  2882. // 不改变时
  2883. if (!isUnchanged(mo)) {
  2884. context.transform(mo[0], mo[1], mo[2], mo[3], mo[4], mo[5]);
  2885. }
  2886. };
  2887. return Element;
  2888. }();
  2889. module.exports = Element;
  2890. /***/ }),
  2891. /* 17 */
  2892. /***/ (function(module, exports, __webpack_require__) {
  2893. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  2894. /**
  2895. * @fileOverview Base class of chart and geometry
  2896. * @author dxq613@gmail.com
  2897. */
  2898. var Util = __webpack_require__(0);
  2899. var Base = function () {
  2900. Base.prototype.getDefaultCfg = function getDefaultCfg() {
  2901. return {};
  2902. };
  2903. function Base(cfg) {
  2904. _classCallCheck(this, Base);
  2905. var attrs = {};
  2906. var defaultCfg = this.getDefaultCfg();
  2907. this._attrs = attrs;
  2908. Util.mix(attrs, defaultCfg, cfg);
  2909. }
  2910. Base.prototype.get = function get(name) {
  2911. return this._attrs[name];
  2912. };
  2913. Base.prototype.set = function set(name, value) {
  2914. this._attrs[name] = value;
  2915. };
  2916. Base.prototype.destroy = function destroy() {
  2917. this._attrs = {};
  2918. this.destroyed = true;
  2919. };
  2920. return Base;
  2921. }();
  2922. module.exports = Base;
  2923. /***/ }),
  2924. /* 18 */
  2925. /***/ (function(module, exports, __webpack_require__) {
  2926. var Util = __webpack_require__(0);
  2927. var Shape = __webpack_require__(2);
  2928. var SHAPE_MAP = {}; // 缓存图形类型
  2929. var INDEX = '_INDEX';
  2930. function getComparer(compare) {
  2931. return function (left, right) {
  2932. var result = compare(left, right);
  2933. return result === 0 ? left[INDEX] - right[INDEX] : result;
  2934. };
  2935. }
  2936. module.exports = {
  2937. getGroupClass: function getGroupClass() {},
  2938. /**
  2939. * 创建并添加 Shape
  2940. * @param {String} type 添加的 shape 类型
  2941. * @param {Object} cfg shape 的配置项
  2942. * @return {Shape} 返回创建的 shape 实例
  2943. */
  2944. addShape: function addShape(type) {
  2945. var cfg = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  2946. var canvas = this.get('canvas');
  2947. var shapeType = SHAPE_MAP[type];
  2948. if (!shapeType) {
  2949. shapeType = Util.upperFirst(type);
  2950. SHAPE_MAP[type] = shapeType;
  2951. }
  2952. cfg.canvas = canvas;
  2953. // cfg.type = type;
  2954. // 设置字体
  2955. if (shapeType === 'Text' && canvas && canvas.get('fontFamily')) {
  2956. cfg.attrs.fontFamily = cfg.attrs.fontFamily || canvas.get('fontFamily');
  2957. }
  2958. var shape = new Shape[shapeType](cfg);
  2959. this.add(shape);
  2960. return shape;
  2961. },
  2962. /**
  2963. * 创建并添加 Group 组
  2964. * @param {Object|null} cfg 配置信息
  2965. * @return {Group} 返回创建的 Group 实例
  2966. */
  2967. addGroup: function addGroup(cfg) {
  2968. var canvas = this.get('canvas');
  2969. var groupClass = this.getGroupClass();
  2970. cfg = Util.mix({}, cfg);
  2971. cfg.canvas = canvas;
  2972. cfg.parent = this;
  2973. var rst = new groupClass(cfg);
  2974. this.add(rst);
  2975. return rst;
  2976. },
  2977. /**
  2978. * 判断是否包含 item
  2979. * @param {Shape|Group} item shape 或者 group 实例
  2980. * @return {Boolean} true 表示包含,false 表示不包含
  2981. */
  2982. contain: function contain(item) {
  2983. var children = this.get('children');
  2984. return children.indexOf(item) > -1;
  2985. },
  2986. /**
  2987. * 按照各个元素的 zIndex 进行从大到小的排序
  2988. * @return {Canvas|Group} 返回自己
  2989. */
  2990. sort: function sort() {
  2991. var children = this.get('children');
  2992. // 必须保证稳定排序
  2993. for (var i = 0, len = children.length; i < len; i++) {
  2994. var child = children[i];
  2995. child[INDEX] = i;
  2996. }
  2997. children.sort(getComparer(function (obj1, obj2) {
  2998. return obj1.get('zIndex') - obj2.get('zIndex');
  2999. }));
  3000. return this;
  3001. },
  3002. /**
  3003. * 清除所有的元素
  3004. * @return {Canvas|Group} 返回自己
  3005. */
  3006. clear: function clear() {
  3007. var children = this.get('children');
  3008. while (children.length !== 0) {
  3009. children[children.length - 1].remove(true);
  3010. }
  3011. return this;
  3012. },
  3013. /**
  3014. * 添加元素
  3015. * @param {Array|Group|Shape} items group 实例或者 shape 实例或者他们的数组集合
  3016. * @return {Group} 返回自身
  3017. */
  3018. add: function add(items) {
  3019. var self = this;
  3020. var children = self.get('children');
  3021. if (!Util.isArray(items)) {
  3022. items = [items];
  3023. }
  3024. for (var i = 0, len = items.length; i < len; i++) {
  3025. var item = items[i];
  3026. var parent = item.get('parent');
  3027. if (parent) {
  3028. var descendants = parent.get('children');
  3029. Util.Array.remove(descendants, item);
  3030. }
  3031. self._setEvn(item);
  3032. children.push(item);
  3033. }
  3034. return self;
  3035. },
  3036. _setEvn: function _setEvn(item) {
  3037. var self = this;
  3038. item._attrs.parent = self;
  3039. item._attrs.context = self._attrs.context;
  3040. item._attrs.canvas = self._attrs.canvas;
  3041. var clip = item._attrs.attrs.clip;
  3042. if (clip) {
  3043. clip.set('parent', self);
  3044. clip.set('context', self.get('context'));
  3045. }
  3046. if (item._attrs.isGroup) {
  3047. var children = item._attrs.children;
  3048. for (var i = 0, len = children.length; i < len; i++) {
  3049. item._setEvn(children[i]);
  3050. }
  3051. }
  3052. }
  3053. };
  3054. /***/ }),
  3055. /* 19 */
  3056. /***/ (function(module, exports, __webpack_require__) {
  3057. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  3058. function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
  3059. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
  3060. var Util = __webpack_require__(0);
  3061. var Element = __webpack_require__(16);
  3062. var Container = __webpack_require__(18);
  3063. var Vector2 = __webpack_require__(3);
  3064. var Group = function (_Element) {
  3065. _inherits(Group, _Element);
  3066. function Group() {
  3067. _classCallCheck(this, Group);
  3068. return _possibleConstructorReturn(this, _Element.apply(this, arguments));
  3069. }
  3070. Group.prototype._initProperties = function _initProperties() {
  3071. this._attrs = {
  3072. zIndex: 0,
  3073. visible: true,
  3074. destroyed: false,
  3075. isGroup: true,
  3076. children: []
  3077. };
  3078. };
  3079. Group.prototype.drawInner = function drawInner(context) {
  3080. // context = context || this.get('context');
  3081. var children = this.get('children');
  3082. for (var i = 0, len = children.length; i < len; i++) {
  3083. var child = children[i];
  3084. child.draw(context);
  3085. }
  3086. return this;
  3087. };
  3088. /**
  3089. * 获取最小包围盒
  3090. * @return {Object} 返回包围盒
  3091. */
  3092. Group.prototype.getBBox = function getBBox() {
  3093. var self = this;
  3094. var minX = Infinity;
  3095. var maxX = -Infinity;
  3096. var minY = Infinity;
  3097. var maxY = -Infinity;
  3098. var children = self.get('children');
  3099. for (var i = 0, length = children.length; i < length; i++) {
  3100. var child = children[i];
  3101. if (child.get('visible')) {
  3102. var box = child.getBBox();
  3103. if (!box) {
  3104. continue;
  3105. }
  3106. var leftTop = [box.minX, box.minY];
  3107. var leftBottom = [box.minX, box.maxY];
  3108. var rightTop = [box.maxX, box.minY];
  3109. var rightBottom = [box.maxX, box.maxY];
  3110. var matrix = child.attr('matrix');
  3111. Vector2.transformMat2d(leftTop, leftTop, matrix);
  3112. Vector2.transformMat2d(leftBottom, leftBottom, matrix);
  3113. Vector2.transformMat2d(rightTop, rightTop, matrix);
  3114. Vector2.transformMat2d(rightBottom, rightBottom, matrix);
  3115. minX = Math.min(leftTop[0], leftBottom[0], rightTop[0], rightBottom[0], minX);
  3116. maxX = Math.max(leftTop[0], leftBottom[0], rightTop[0], rightBottom[0], maxX);
  3117. minY = Math.min(leftTop[1], leftBottom[1], rightTop[1], rightBottom[1], minY);
  3118. maxY = Math.max(leftTop[1], leftBottom[1], rightTop[1], rightBottom[1], maxY);
  3119. }
  3120. }
  3121. return {
  3122. minX: minX,
  3123. minY: minY,
  3124. maxX: maxX,
  3125. maxY: maxY,
  3126. x: minX,
  3127. y: minY,
  3128. width: maxX - minX,
  3129. height: maxY - minY
  3130. };
  3131. };
  3132. Group.prototype.destroy = function destroy() {
  3133. if (this.get('destroyed')) {
  3134. return;
  3135. }
  3136. this.clear();
  3137. _Element.prototype.destroy.call(this);
  3138. };
  3139. return Group;
  3140. }(Element);
  3141. Util.mix(Group.prototype, Container, {
  3142. getGroupClass: function getGroupClass() {
  3143. return Group;
  3144. }
  3145. });
  3146. module.exports = Group;
  3147. /***/ }),
  3148. /* 20 */
  3149. /***/ (function(module, exports, __webpack_require__) {
  3150. var Util = __webpack_require__(0);
  3151. var Shape = __webpack_require__(5);
  3152. var ShapeUtil = __webpack_require__(12);
  3153. var Global = __webpack_require__(1);
  3154. // register line geom
  3155. var Line = Shape.registerFactory('line', {
  3156. defaultShapeType: 'line'
  3157. });
  3158. function getStyle(cfg) {
  3159. var style = {
  3160. strokeStyle: cfg.color
  3161. };
  3162. if (cfg.size >= 0) {
  3163. style.lineWidth = cfg.size;
  3164. }
  3165. Util.mix(style, cfg.style);
  3166. return Util.mix({}, Global.shape.line, style);
  3167. }
  3168. function drawLines(cfg, container, style, smooth) {
  3169. var points = cfg.points;
  3170. if (points.length && Util.isArray(points[0].y)) {
  3171. var topPoints = [];
  3172. var bottomPoints = [];
  3173. for (var i = 0, len = points.length; i < len; i++) {
  3174. var point = points[i];
  3175. var tmp = ShapeUtil.splitPoints(point);
  3176. bottomPoints.push(tmp[0]);
  3177. topPoints.push(tmp[1]);
  3178. }
  3179. if (cfg.isInCircle) {
  3180. topPoints.push(topPoints[0]);
  3181. bottomPoints.push(bottomPoints[0]);
  3182. }
  3183. if (cfg.isStack) {
  3184. return container.addShape('Polyline', {
  3185. className: 'line',
  3186. attrs: Util.mix({
  3187. points: topPoints,
  3188. smooth: smooth
  3189. }, style)
  3190. });
  3191. }
  3192. var topShape = container.addShape('Polyline', {
  3193. className: 'line',
  3194. attrs: Util.mix({
  3195. points: topPoints,
  3196. smooth: smooth
  3197. }, style)
  3198. });
  3199. var bottomShape = container.addShape('Polyline', {
  3200. className: 'line',
  3201. attrs: Util.mix({
  3202. points: bottomPoints,
  3203. smooth: smooth
  3204. }, style)
  3205. });
  3206. return [topShape, bottomShape];
  3207. }
  3208. if (cfg.isInCircle) {
  3209. points.push(points[0]);
  3210. }
  3211. return container.addShape('Polyline', {
  3212. className: 'line',
  3213. attrs: Util.mix({
  3214. points: points,
  3215. smooth: smooth
  3216. }, style)
  3217. });
  3218. }
  3219. var SHAPES = ['line', 'smooth', 'dash'];
  3220. Util.each(SHAPES, function (shapeType) {
  3221. Shape.registerShape('line', shapeType, {
  3222. draw: function draw(cfg, container) {
  3223. var smooth = shapeType === 'smooth';
  3224. var style = getStyle(cfg);
  3225. if (shapeType === 'dash') {
  3226. style.lineDash = Global.lineDash;
  3227. }
  3228. return drawLines(cfg, container, style, smooth);
  3229. }
  3230. });
  3231. });
  3232. module.exports = Line;
  3233. /***/ }),
  3234. /* 21 */
  3235. /***/ (function(module, exports, __webpack_require__) {
  3236. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  3237. function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
  3238. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
  3239. /**
  3240. * @fileOverview the scale function to process the categories
  3241. * @author dxq613@gmail.com
  3242. */
  3243. var Base = __webpack_require__(8);
  3244. var Util = __webpack_require__(0);
  3245. var catAuto = __webpack_require__(22);
  3246. /**
  3247. * 度量的构造函数
  3248. * @class Scale.Category
  3249. */
  3250. var Category = function (_Base) {
  3251. _inherits(Category, _Base);
  3252. function Category() {
  3253. _classCallCheck(this, Category);
  3254. return _possibleConstructorReturn(this, _Base.apply(this, arguments));
  3255. }
  3256. Category.prototype._initDefaultCfg = function _initDefaultCfg() {
  3257. this.type = 'cat';
  3258. /**
  3259. * 自动生成标记时的个数
  3260. * @type {Number}
  3261. * @default null
  3262. */
  3263. this.tickCount = null;
  3264. /**
  3265. * 是否分类度量
  3266. * @type {Boolean}
  3267. */
  3268. this.isCategory = true;
  3269. /**
  3270. * 输出的值域
  3271. * @type {Array}
  3272. */
  3273. this.range = [0, 1];
  3274. /**
  3275. * 度量的标记
  3276. * @type {Array}
  3277. */
  3278. this.ticks = null;
  3279. /**
  3280. * 参与度量计算的值,可选项
  3281. * @type {Array}
  3282. */
  3283. this.values = [];
  3284. };
  3285. /**
  3286. * @override
  3287. */
  3288. Category.prototype.init = function init() {
  3289. var self = this;
  3290. var values = self.values;
  3291. var tickCount = self.tickCount;
  3292. Util.each(values, function (v, i) {
  3293. values[i] = v.toString();
  3294. });
  3295. if (!self.ticks) {
  3296. var ticks = values;
  3297. if (tickCount) {
  3298. var temp = catAuto({
  3299. maxCount: tickCount,
  3300. data: values
  3301. });
  3302. ticks = temp.ticks;
  3303. }
  3304. this.ticks = ticks;
  3305. }
  3306. };
  3307. /**
  3308. * @override
  3309. */
  3310. Category.prototype.getText = function getText(value) {
  3311. if (this.values.indexOf(value) === -1 && Util.isNumber(value)) {
  3312. value = this.values[Math.round(value)];
  3313. }
  3314. return _Base.prototype.getText.call(this, value);
  3315. };
  3316. /**
  3317. * @override
  3318. */
  3319. Category.prototype.translate = function translate(value) {
  3320. var index = this.values.indexOf(value);
  3321. if (index === -1 && Util.isNumber(value)) {
  3322. index = value;
  3323. } else if (index === -1) {
  3324. index = NaN;
  3325. }
  3326. return index;
  3327. };
  3328. /**
  3329. * @override
  3330. */
  3331. Category.prototype.scale = function scale(value) {
  3332. var rangeMin = this.rangeMin();
  3333. var rangeMax = this.rangeMax();
  3334. var percent = void 0;
  3335. if (Util.isString(value) || this.values.indexOf(value) !== -1) {
  3336. value = this.translate(value);
  3337. }
  3338. if (this.values.length > 1) {
  3339. percent = value / (this.values.length - 1);
  3340. } else {
  3341. percent = value;
  3342. }
  3343. return rangeMin + percent * (rangeMax - rangeMin);
  3344. };
  3345. /**
  3346. * @override
  3347. */
  3348. Category.prototype.invert = function invert(value) {
  3349. if (Util.isString(value)) {
  3350. // 如果已经是字符串
  3351. return value;
  3352. }
  3353. var min = this.rangeMin();
  3354. var max = this.rangeMax();
  3355. // 归一到 范围内
  3356. if (value < min) {
  3357. value = min;
  3358. }
  3359. if (value > max) {
  3360. value = max;
  3361. }
  3362. var percent = (value - min) / (max - min);
  3363. var index = Math.round(percent * (this.values.length - 1)) % this.values.length;
  3364. index = index || 0;
  3365. return this.values[index];
  3366. };
  3367. return Category;
  3368. }(Base);
  3369. Base.Cat = Category;
  3370. module.exports = Category;
  3371. /***/ }),
  3372. /* 22 */
  3373. /***/ (function(module, exports, __webpack_require__) {
  3374. /**
  3375. * @fileOverview 计算分类的的坐标点
  3376. * @author dxq613@gmail.com
  3377. */
  3378. var Util = __webpack_require__(0);
  3379. var MAX_COUNT = 8;
  3380. function getSimpleArray(data) {
  3381. var arr = [];
  3382. Util.each(data, function (sub) {
  3383. if (Util.isArray(sub)) {
  3384. arr = arr.concat(sub);
  3385. } else {
  3386. arr.push(sub);
  3387. }
  3388. });
  3389. return arr;
  3390. }
  3391. module.exports = function (info) {
  3392. var rst = {};
  3393. var ticks = [];
  3394. var tickCount = info.maxCount || MAX_COUNT;
  3395. var categories = getSimpleArray(info.data);
  3396. if (categories.length <= tickCount + tickCount / 2) {
  3397. ticks = [].concat(categories);
  3398. } else {
  3399. var length = categories.length;
  3400. var step = parseInt(length / (tickCount - 1), 10);
  3401. var groups = categories.map(function (e, i) {
  3402. return i % step === 0 ? categories.slice(i, i + step) : null;
  3403. }).filter(function (e) {
  3404. return e;
  3405. });
  3406. ticks.push(categories[0]);
  3407. for (var i = 1, groupLen = groups.length; i < groupLen && i < tickCount - 1; i++) {
  3408. ticks.push(groups[i][0]);
  3409. }
  3410. ticks.push(categories[length - 1]);
  3411. }
  3412. rst.categories = categories;
  3413. rst.ticks = ticks;
  3414. return rst;
  3415. };
  3416. /***/ }),
  3417. /* 23 */
  3418. /***/ (function(module, exports, __webpack_require__) {
  3419. /**
  3420. * @fileOverview 将折线转换成平滑曲线
  3421. * @author dxq613@gmail.com
  3422. */
  3423. var Vector2 = __webpack_require__(3);
  3424. function getPoint(v) {
  3425. return [v.x, v.y];
  3426. }
  3427. function smoothBezier(points, smooth, isLoop, constraint) {
  3428. var cps = [];
  3429. var prevPoint = void 0;
  3430. var nextPoint = void 0;
  3431. var hasConstraint = !!constraint;
  3432. var min = void 0;
  3433. var max = void 0;
  3434. var point = void 0;
  3435. var len = void 0;
  3436. var l = void 0;
  3437. var i = void 0;
  3438. if (hasConstraint) {
  3439. min = [Infinity, Infinity];
  3440. max = [-Infinity, -Infinity];
  3441. for (i = 0, l = points.length; i < l; i++) {
  3442. point = getPoint(points[i]);
  3443. Vector2.min(min, min, point);
  3444. Vector2.max(max, max, point);
  3445. }
  3446. Vector2.min(min, min, constraint[0]);
  3447. Vector2.max(max, max, constraint[1]);
  3448. }
  3449. for (i = 0, len = points.length; i < len; i++) {
  3450. point = getPoint(points[i]);
  3451. if (isLoop) {
  3452. prevPoint = getPoint(points[i ? i - 1 : len - 1]);
  3453. nextPoint = getPoint(points[(i + 1) % len]);
  3454. } else {
  3455. if (i === 0 || i === len - 1) {
  3456. cps.push([point[0], point[1]]);
  3457. continue;
  3458. } else {
  3459. prevPoint = getPoint(points[i - 1]);
  3460. nextPoint = getPoint(points[i + 1]);
  3461. }
  3462. }
  3463. var v = Vector2.sub([], nextPoint, prevPoint);
  3464. Vector2.scale(v, v, smooth);
  3465. var d0 = Vector2.distance(point, prevPoint);
  3466. var d1 = Vector2.distance(point, nextPoint);
  3467. var sum = d0 + d1;
  3468. if (sum !== 0) {
  3469. d0 /= sum;
  3470. d1 /= sum;
  3471. }
  3472. var v1 = Vector2.scale([], v, -d0);
  3473. var v2 = Vector2.scale([], v, d1);
  3474. var cp0 = Vector2.add([], point, v1);
  3475. var cp1 = Vector2.add([], point, v2);
  3476. if (hasConstraint) {
  3477. Vector2.max(cp0, cp0, min);
  3478. Vector2.min(cp0, cp0, max);
  3479. Vector2.max(cp1, cp1, min);
  3480. Vector2.min(cp1, cp1, max);
  3481. }
  3482. cps.push([cp0[0], cp0[1]]);
  3483. cps.push([cp1[0], cp1[1]]);
  3484. }
  3485. if (isLoop) {
  3486. cps.push(cps.shift());
  3487. }
  3488. return cps;
  3489. }
  3490. function catmullRom2bezier(pointList, z, constraint) {
  3491. var isLoop = !!z;
  3492. var controlPointList = smoothBezier(pointList, 0.4, isLoop, constraint);
  3493. var len = pointList.length;
  3494. var d1 = [];
  3495. var cp1 = void 0;
  3496. var cp2 = void 0;
  3497. var p = void 0;
  3498. for (var i = 0; i < len - 1; i++) {
  3499. cp1 = controlPointList[i * 2];
  3500. cp2 = controlPointList[i * 2 + 1];
  3501. p = pointList[i + 1];
  3502. d1.push(['C', cp1[0], cp1[1], cp2[0], cp2[1], p.x, p.y]);
  3503. }
  3504. if (isLoop) {
  3505. cp1 = controlPointList[len];
  3506. cp2 = controlPointList[len + 1];
  3507. p = pointList[0];
  3508. d1.push(['C', cp1[0], cp1[1], cp2[0], cp2[1], p.x, p.y]);
  3509. }
  3510. return d1;
  3511. }
  3512. module.exports = {
  3513. smooth: catmullRom2bezier
  3514. };
  3515. /***/ }),
  3516. /* 24 */
  3517. /***/ (function(module, exports, __webpack_require__) {
  3518. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  3519. function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
  3520. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
  3521. var Base = __webpack_require__(17);
  3522. var Plot = __webpack_require__(30);
  3523. var Util = __webpack_require__(0);
  3524. var Coord = __webpack_require__(31);
  3525. var Geom = __webpack_require__(4);
  3526. var ScaleController = __webpack_require__(39);
  3527. var AxisController = __webpack_require__(45);
  3528. var Global = __webpack_require__(1);
  3529. var _require = __webpack_require__(6),
  3530. Canvas = _require.Canvas;
  3531. function isFullCircle(coord) {
  3532. var startAngle = coord.startAngle;
  3533. var endAngle = coord.endAngle;
  3534. if (!Util.isNil(startAngle) && !Util.isNil(endAngle) && endAngle - startAngle < Math.PI * 2) {
  3535. return false;
  3536. }
  3537. return true;
  3538. }
  3539. function compare(a, b) {
  3540. return a - b;
  3541. }
  3542. function _isScaleExist(scales, compareScale) {
  3543. var flag = false;
  3544. Util.each(scales, function (scale) {
  3545. var scaleValues = [].concat(scale.values);
  3546. var compareScaleValues = [].concat(compareScale.values);
  3547. if (scale.type === compareScale.type && scale.field === compareScale.field && scaleValues.sort(compare).toString() === compareScaleValues.sort(compare).toString()) {
  3548. flag = true;
  3549. return;
  3550. }
  3551. });
  3552. return flag;
  3553. }
  3554. var Chart = function (_Base) {
  3555. _inherits(Chart, _Base);
  3556. Chart.initPlugins = function initPlugins() {
  3557. return {
  3558. _plugins: [],
  3559. _cacheId: 0,
  3560. register: function register(plugins) {
  3561. var p = this._plugins;
  3562. [].concat(plugins).forEach(function (plugin) {
  3563. if (p.indexOf(plugin) === -1) {
  3564. p.push(plugin);
  3565. }
  3566. });
  3567. this._cacheId++;
  3568. },
  3569. unregister: function unregister(plugins) {
  3570. var p = this._plugins;
  3571. [].concat(plugins).forEach(function (plugin) {
  3572. var idx = p.indexOf(plugin);
  3573. if (idx !== -1) {
  3574. p.splice(idx, 1);
  3575. }
  3576. });
  3577. this._cacheId++;
  3578. },
  3579. clear: function clear() {
  3580. this._plugins = [];
  3581. this._cacheId++;
  3582. },
  3583. count: function count() {
  3584. return this._plugins.length;
  3585. },
  3586. getAll: function getAll() {
  3587. return this._plugins;
  3588. },
  3589. notify: function notify(chart, hook, args) {
  3590. var descriptors = this.descriptors(chart);
  3591. var ilen = descriptors.length;
  3592. var i = void 0;
  3593. var descriptor = void 0;
  3594. var plugin = void 0;
  3595. var params = void 0;
  3596. var method = void 0;
  3597. for (i = 0; i < ilen; ++i) {
  3598. descriptor = descriptors[i];
  3599. plugin = descriptor.plugin;
  3600. method = plugin[hook];
  3601. if (typeof method === 'function') {
  3602. params = [chart].concat(args || []);
  3603. if (method.apply(plugin, params) === false) {
  3604. return false;
  3605. }
  3606. }
  3607. }
  3608. return true;
  3609. },
  3610. descriptors: function descriptors(chart) {
  3611. var cache = chart._plugins || (chart._plugins = {});
  3612. if (cache.id === this._cacheId) {
  3613. return cache.descriptors;
  3614. }
  3615. var plugins = [];
  3616. var descriptors = [];
  3617. this._plugins.concat(chart && chart.get('plugins') || []).forEach(function (plugin) {
  3618. var idx = plugins.indexOf(plugin);
  3619. if (idx !== -1) {
  3620. return;
  3621. }
  3622. plugins.push(plugin);
  3623. descriptors.push({
  3624. plugin: plugin
  3625. });
  3626. });
  3627. cache.descriptors = descriptors;
  3628. cache.id = this._cacheId;
  3629. return descriptors;
  3630. }
  3631. };
  3632. };
  3633. Chart.prototype.getDefaultCfg = function getDefaultCfg() {
  3634. return {
  3635. /**
  3636. * 画布的Id
  3637. * @type {String}
  3638. */
  3639. id: null,
  3640. /**
  3641. * 画布中绘制图形的边距
  3642. * @type {Array|Number}
  3643. */
  3644. padding: Global.padding,
  3645. /**
  3646. * 数据
  3647. * @type {Array}
  3648. */
  3649. data: null,
  3650. /**
  3651. * chart 保有的度量
  3652. * @type {Object}
  3653. */
  3654. scales: {},
  3655. /**
  3656. * 坐标系的配置信息
  3657. * @private
  3658. * @type {Object}
  3659. */
  3660. coordCfg: {
  3661. type: 'cartesian'
  3662. },
  3663. /**
  3664. * @private
  3665. * 图层对应的图形
  3666. * @type {Array}
  3667. */
  3668. geoms: null,
  3669. /**
  3670. * 列定义
  3671. * @type {Object}
  3672. */
  3673. colDefs: null,
  3674. pixelRatio: Global.pixelRatio,
  3675. /**
  3676. * 过滤设置
  3677. * @type {Object}
  3678. */
  3679. filters: null,
  3680. appendPadding: Global.appendPadding
  3681. };
  3682. };
  3683. Chart.prototype._getFieldsForLegend = function _getFieldsForLegend() {
  3684. var fields = [];
  3685. var geoms = this.get('geoms');
  3686. Util.each(geoms, function (geom) {
  3687. var attrOptions = geom.get('attrOptions');
  3688. var attrCfg = attrOptions.color;
  3689. if (attrCfg && attrCfg.field && Util.isString(attrCfg.field)) {
  3690. var arr = attrCfg.field.split('*');
  3691. Util.each(arr, function (item) {
  3692. if (fields.indexOf(item) === -1) {
  3693. fields.push(item);
  3694. }
  3695. });
  3696. }
  3697. });
  3698. return fields;
  3699. };
  3700. Chart.prototype._createScale = function _createScale(field, data) {
  3701. var scaleController = this.get('scaleController');
  3702. return scaleController.createScale(field, data);
  3703. };
  3704. Chart.prototype._adjustScale = function _adjustScale() {
  3705. var self = this;
  3706. var coord = self.get('coord');
  3707. var xScale = self.getXScale();
  3708. var yScales = self.getYScales();
  3709. var scales = [];
  3710. xScale && scales.push(xScale);
  3711. scales = scales.concat(yScales);
  3712. var inFullCircle = coord.isPolar && isFullCircle(coord);
  3713. var scaleController = self.get('scaleController');
  3714. var colDefs = scaleController.defs;
  3715. Util.each(scales, function (scale) {
  3716. if ((scale.isCategory || scale.isIdentity) && scale.values && !(colDefs[scale.field] && colDefs[scale.field].range)) {
  3717. var count = scale.values.length;
  3718. var range = void 0;
  3719. if (count === 1) {
  3720. range = [0.5, 1]; // 只有一个分类时,防止计算出现 [0.5,0.5]的状态
  3721. } else {
  3722. var widthRatio = 1;
  3723. var offset = 0;
  3724. if (inFullCircle) {
  3725. if (!coord.transposed) {
  3726. range = [0, 1 - 1 / count];
  3727. } else {
  3728. widthRatio = Global.widthRatio.multiplePie;
  3729. offset = 1 / count * widthRatio;
  3730. range = [offset / 2, 1 - offset / 2];
  3731. }
  3732. } else {
  3733. offset = 1 / count * 1 / 2; // 两边留下分类空间的一半
  3734. range = [offset, 1 - offset]; // 坐标轴最前面和最后面留下空白防止绘制柱状图时
  3735. }
  3736. }
  3737. scale.range = range;
  3738. }
  3739. });
  3740. var geoms = this.get('geoms');
  3741. for (var i = 0; i < geoms.length; i++) {
  3742. var geom = geoms[i];
  3743. if (geom.get('type') === 'interval') {
  3744. var yScale = geom.getYScale();
  3745. var field = yScale.field,
  3746. min = yScale.min,
  3747. max = yScale.max,
  3748. type = yScale.type;
  3749. if (!(colDefs[field] && colDefs[field].min) && type !== 'time') {
  3750. if (min > 0) {
  3751. yScale.change({
  3752. min: 0
  3753. });
  3754. } else if (max <= 0) {
  3755. // 当柱状图全为负值时也需要从 0 开始生长
  3756. yScale.change({
  3757. max: 0
  3758. });
  3759. }
  3760. }
  3761. }
  3762. }
  3763. };
  3764. Chart.prototype._removeGeoms = function _removeGeoms() {
  3765. var geoms = this.get('geoms');
  3766. while (geoms.length > 0) {
  3767. var geom = geoms.shift();
  3768. geom.destroy();
  3769. }
  3770. };
  3771. Chart.prototype._clearGeoms = function _clearGeoms() {
  3772. var geoms = this.get('geoms');
  3773. for (var i = 0, length = geoms.length; i < length; i++) {
  3774. var geom = geoms[i];
  3775. geom.clear();
  3776. }
  3777. };
  3778. Chart.prototype._clearInner = function _clearInner() {
  3779. this.set('scales', {});
  3780. this.set('legendItems', null);
  3781. this._clearGeoms();
  3782. Chart.plugins.notify(this, 'clearInner'); // TODO
  3783. this.get('axisController') && this.get('axisController').clear();
  3784. };
  3785. Chart.prototype._execFilter = function _execFilter(data) {
  3786. var filters = this.get('filters');
  3787. if (filters) {
  3788. data = data.filter(function (obj) {
  3789. var rst = true;
  3790. Util.each(filters, function (fn, k) {
  3791. if (fn) {
  3792. rst = fn(obj[k], obj);
  3793. if (!rst) {
  3794. return false;
  3795. }
  3796. }
  3797. });
  3798. return rst;
  3799. });
  3800. }
  3801. return data;
  3802. };
  3803. Chart.prototype._initGeoms = function _initGeoms(geoms) {
  3804. var coord = this.get('coord');
  3805. var data = this.get('filteredData');
  3806. for (var i = 0, length = geoms.length; i < length; i++) {
  3807. var geom = geoms[i];
  3808. geom.set('data', data);
  3809. geom.set('coord', coord);
  3810. geom.init();
  3811. }
  3812. };
  3813. Chart.prototype._initCoord = function _initCoord() {
  3814. var plot = this.get('plotRange');
  3815. var coordCfg = Util.mix({}, this.get('coordCfg'), {
  3816. plot: plot
  3817. });
  3818. var type = coordCfg.type;
  3819. var C = Coord[Util.upperFirst(type)] || Coord.Cartesian;
  3820. var coord = new C(coordCfg);
  3821. this.set('coord', coord);
  3822. };
  3823. Chart.prototype._initLayout = function _initLayout() {
  3824. var padding = this.get('_padding');
  3825. if (!padding) {
  3826. padding = this.get('margin') || this.get('padding'); // 兼容margin 的写法
  3827. padding = Util.parsePadding(padding);
  3828. }
  3829. var top = padding[0] === 'auto' ? 0 : padding[0];
  3830. var right = padding[1] === 'auto' ? 0 : padding[1];
  3831. var bottom = padding[2] === 'auto' ? 0 : padding[2];
  3832. var left = padding[3] === 'auto' ? 0 : padding[3];
  3833. var width = this.get('width');
  3834. var height = this.get('height');
  3835. var plot = new Plot({
  3836. start: {
  3837. x: left,
  3838. y: top
  3839. },
  3840. end: {
  3841. x: width - right,
  3842. y: height - bottom
  3843. }
  3844. });
  3845. this.set('plotRange', plot);
  3846. this.set('plot', plot);
  3847. };
  3848. Chart.prototype._initCanvas = function _initCanvas() {
  3849. var self = this;
  3850. try {
  3851. var canvas = new Canvas({
  3852. el: self.get('el') || self.get('id'),
  3853. context: self.get('context'),
  3854. pixelRatio: self.get('pixelRatio'),
  3855. width: self.get('width'),
  3856. height: self.get('height'),
  3857. fontFamily: Global.fontFamily
  3858. });
  3859. self.set('canvas', canvas);
  3860. self.set('width', canvas.get('width'));
  3861. self.set('height', canvas.get('height'));
  3862. } catch (error) {
  3863. // canvas 创建发生异常
  3864. throw error;
  3865. }
  3866. Chart.plugins.notify(self, 'afterCanvasInit');
  3867. self._initLayout();
  3868. };
  3869. Chart.prototype._initLayers = function _initLayers() {
  3870. var canvas = this.get('canvas');
  3871. this.set('backPlot', canvas.addGroup()); // 默认 zIndex 为 0
  3872. this.set('middlePlot', canvas.addGroup({
  3873. zIndex: 10
  3874. }));
  3875. this.set('frontPlot', canvas.addGroup({
  3876. zIndex: 20
  3877. }));
  3878. };
  3879. Chart.prototype.initColDefs = function initColDefs() {
  3880. var colDefs = this.get('colDefs');
  3881. if (colDefs) {
  3882. var scaleController = this.get('scaleController');
  3883. Util.mix(scaleController.defs, colDefs);
  3884. }
  3885. };
  3886. Chart.prototype._init = function _init() {
  3887. var self = this;
  3888. self._initCanvas();
  3889. self._initLayers();
  3890. self.set('geoms', []);
  3891. self.set('scaleController', new ScaleController());
  3892. self.set('axisController', new AxisController({
  3893. frontPlot: self.get('frontPlot').addGroup({
  3894. className: 'axisContainer'
  3895. }),
  3896. backPlot: self.get('backPlot').addGroup({
  3897. className: 'axisContainer'
  3898. }),
  3899. chart: self
  3900. }));
  3901. Chart.plugins.notify(self, 'init'); // TODO: beforeInit afterInit
  3902. };
  3903. function Chart(cfg) {
  3904. _classCallCheck(this, Chart);
  3905. // 附加各种 geometry 对应的方法
  3906. var _this = _possibleConstructorReturn(this, _Base.call(this, cfg));
  3907. var self = _this;
  3908. Util.each(Geom, function (geomConstructor, className) {
  3909. var methodName = Util.lowerFirst(className);
  3910. self[methodName] = function (cfg) {
  3911. var geom = new geomConstructor(cfg);
  3912. self.addGeom(geom);
  3913. return geom;
  3914. };
  3915. });
  3916. self._init();
  3917. return _this;
  3918. }
  3919. /**
  3920. * 设置数据源和数据字段定义
  3921. * @chainable
  3922. * @param {Array} data 数据集合
  3923. * @param {Object} colDefs 数据字段定义
  3924. * @return {Chart} 返回当前 chart 的引用
  3925. */
  3926. Chart.prototype.source = function source(data, colDefs) {
  3927. this.set('data', data);
  3928. if (colDefs) {
  3929. this.scale(colDefs);
  3930. }
  3931. return this;
  3932. };
  3933. Chart.prototype.scale = function scale(field, cfg) {
  3934. var colDefs = this.get('colDefs') || {};
  3935. if (Util.isObject(field)) {
  3936. Util.mix(colDefs, field);
  3937. } else {
  3938. colDefs[field] = cfg;
  3939. }
  3940. this.set('colDefs', colDefs);
  3941. this.initColDefs();
  3942. return this;
  3943. };
  3944. /**
  3945. * 设置坐标轴配置项
  3946. * @chainable
  3947. * @param {String|Boolean} field 坐标轴对应的字段
  3948. * @param {Object} cfg 坐标轴的配置信息
  3949. * @return {Chart} 返回当前 chart 的引用
  3950. */
  3951. Chart.prototype.axis = function axis(field, cfg) {
  3952. var axisController = this.get('axisController');
  3953. if (!field) {
  3954. axisController.axisCfg = null;
  3955. } else {
  3956. axisController.axisCfg = axisController.axisCfg || {};
  3957. axisController.axisCfg[field] = cfg;
  3958. }
  3959. return this;
  3960. };
  3961. /**
  3962. * 设置坐标系配置项
  3963. * @chainable
  3964. * @param {String} type 坐标系类型
  3965. * @param {Object} cfg 配置项
  3966. * @return {Chart} 返回当前 chart 的引用
  3967. */
  3968. Chart.prototype.coord = function coord(type, cfg) {
  3969. if (!type) {
  3970. return;
  3971. }
  3972. var coordCfg = void 0;
  3973. if (Util.isObject(type)) {
  3974. coordCfg = type;
  3975. } else {
  3976. coordCfg = cfg || {};
  3977. coordCfg.type = type;
  3978. }
  3979. this.set('coordCfg', coordCfg);
  3980. return this;
  3981. };
  3982. Chart.prototype.filter = function filter(field, condition) {
  3983. var filters = this.get('filters') || {};
  3984. filters[field] = condition;
  3985. this.set('filters', filters);
  3986. };
  3987. /**
  3988. * 图表绘制
  3989. * @chainable
  3990. * @return {Chart} 返回当前 chart 的引用
  3991. */
  3992. Chart.prototype.render = function render() {
  3993. var self = this;
  3994. var canvas = self.get('canvas');
  3995. var geoms = self.get('geoms');
  3996. // 处理数据
  3997. var data = this.get('data') || [];
  3998. var filteredData = this._execFilter(data);
  3999. this.set('filteredData', filteredData);
  4000. // 初始化坐标系
  4001. self._initCoord();
  4002. // 初始化 geoms
  4003. self._initGeoms(geoms);
  4004. // 调整度量
  4005. self._adjustScale();
  4006. // 绘制坐标轴
  4007. Chart.plugins.notify(self, 'beforeGeomDraw');
  4008. self._renderAxis();
  4009. // 绘制 geom
  4010. for (var i = 0, length = geoms.length; i < length; i++) {
  4011. var geom = geoms[i];
  4012. geom.paint();
  4013. }
  4014. Chart.plugins.notify(self, 'afterGeomDraw');
  4015. canvas.sort();
  4016. this.get('frontPlot').sort();
  4017. Chart.plugins.notify(self, 'beforeCanvasDraw');
  4018. canvas.draw();
  4019. return self;
  4020. };
  4021. /**
  4022. * 清空图表上面的图层
  4023. * @chainable
  4024. * @return {Chart} 返回当前 chart 的引用
  4025. */
  4026. Chart.prototype.clear = function clear() {
  4027. Chart.plugins.notify(this, 'clear'); // TODO: beforeClear afterClear
  4028. this._removeGeoms();
  4029. this._clearInner();
  4030. this.set('filters', null);
  4031. this.set('isUpdate', false);
  4032. this.set('_padding', null);
  4033. var canvas = this.get('canvas');
  4034. canvas.draw();
  4035. return this;
  4036. };
  4037. Chart.prototype.repaint = function repaint() {
  4038. this.set('isUpdate', true);
  4039. Chart.plugins.notify(this, 'repaint');
  4040. this._clearInner();
  4041. this.render();
  4042. };
  4043. Chart.prototype.changeData = function changeData(data) {
  4044. this.set('data', data);
  4045. this.set('_padding', null);
  4046. this.repaint();
  4047. };
  4048. Chart.prototype.changeSize = function changeSize(width, height) {
  4049. if (width) {
  4050. this.set('width', width);
  4051. } else {
  4052. width = this.get('width');
  4053. }
  4054. if (height) {
  4055. this.set('height', height);
  4056. } else {
  4057. height = this.get('height');
  4058. }
  4059. var canvas = this.get('canvas');
  4060. canvas.changeSize(width, height);
  4061. this._initLayout();
  4062. this.repaint();
  4063. return this;
  4064. };
  4065. Chart.prototype.destroy = function destroy() {
  4066. this.clear();
  4067. var canvas = this.get('canvas');
  4068. canvas.destroy();
  4069. Chart.plugins.notify(this, 'afterCanvasDestroyed');
  4070. _Base.prototype.destroy.call(this);
  4071. };
  4072. /**
  4073. * 获取数据对应在画布空间的坐标
  4074. * @param {Object} record 原始数据
  4075. * @return {Object} 返回对应的画布上的坐标点
  4076. */
  4077. Chart.prototype.getPosition = function getPosition(record) {
  4078. var self = this;
  4079. var coord = self.get('coord');
  4080. var xScale = self.getXScale();
  4081. var yScale = self.getYScales()[0]; // 暂时只取第一个y轴,忽视多轴的情况
  4082. var xField = xScale.field;
  4083. var x = xScale.scale(record[xField]);
  4084. var yField = yScale.field;
  4085. var y = yScale.scale(record[yField]);
  4086. return coord.convertPoint({
  4087. x: x,
  4088. y: y
  4089. });
  4090. };
  4091. /**
  4092. * 获取画布上坐标对应的数据值
  4093. * @param {Object} point 画布坐标的x,y的值
  4094. * @return {Object} 当前坐标系的数据值
  4095. */
  4096. Chart.prototype.getRecord = function getRecord(point) {
  4097. var self = this;
  4098. var coord = self.get('coord');
  4099. var xScale = self.getXScale();
  4100. var yScale = self.getYScales()[0];
  4101. var invertPoint = coord.invertPoint(point);
  4102. var record = {};
  4103. record[xScale.field] = xScale.invert(invertPoint.x);
  4104. record[yScale.field] = yScale.invert(invertPoint.y);
  4105. return record;
  4106. };
  4107. /**
  4108. * 根据画布坐标获取对应数据集
  4109. * @param {Object} point 画布坐标的x,y的值
  4110. * @return {Array} 纵向切割交点对应数据集
  4111. **/
  4112. Chart.prototype.getSnapRecords = function getSnapRecords(point) {
  4113. var geom = this.get('geoms')[0];
  4114. var data = [];
  4115. if (geom) {
  4116. // need to judge
  4117. data = geom.getSnapRecords(point);
  4118. }
  4119. return data;
  4120. };
  4121. /**
  4122. * 创建度量
  4123. * @param {String} field 度量对应的名称
  4124. * @return {Scale} 度量
  4125. */
  4126. Chart.prototype.createScale = function createScale(field) {
  4127. var data = this.get('data');
  4128. var filteredData = this.get('filteredData');
  4129. // 过滤导致数据为空时,需要使用全局数据
  4130. // 参与过滤的字段的度量也根据全局数据来生成
  4131. if (filteredData.length) {
  4132. var legendFields = this._getFieldsForLegend();
  4133. if (legendFields.indexOf(field) === -1) {
  4134. data = filteredData;
  4135. }
  4136. }
  4137. var scales = this.get('scales');
  4138. if (!scales[field]) {
  4139. scales[field] = this._createScale(field, data);
  4140. }
  4141. return scales[field];
  4142. };
  4143. /**
  4144. * @protected
  4145. * 添加几何标记
  4146. * @param {Geom} geom 几何标记
  4147. */
  4148. Chart.prototype.addGeom = function addGeom(geom) {
  4149. var geoms = this.get('geoms');
  4150. var middlePlot = this.get('middlePlot');
  4151. geoms.push(geom);
  4152. geom.set('chart', this);
  4153. geom.set('container', middlePlot.addGroup());
  4154. };
  4155. /**
  4156. * 获取 x 对应的度量
  4157. * @return {Scale} x 对应的度量
  4158. */
  4159. Chart.prototype.getXScale = function getXScale() {
  4160. var self = this;
  4161. var geoms = self.get('geoms');
  4162. var xScale = geoms[0].getXScale();
  4163. return xScale;
  4164. };
  4165. /**
  4166. * 获取 y 对应的度量
  4167. * @return {Array} 返回所有 y 的度量
  4168. */
  4169. Chart.prototype.getYScales = function getYScales() {
  4170. var geoms = this.get('geoms');
  4171. var rst = [];
  4172. Util.each(geoms, function (geom) {
  4173. var yScale = geom.getYScale();
  4174. if (Util.indexOf(rst, yScale) === -1) {
  4175. rst.push(yScale);
  4176. }
  4177. });
  4178. return rst;
  4179. };
  4180. Chart.prototype.getLegendItems = function getLegendItems() {
  4181. if (this.get('legendItems')) {
  4182. return this.get('legendItems');
  4183. }
  4184. var legendItems = {};
  4185. var scales = [];
  4186. var geoms = this.get('geoms');
  4187. Util.each(geoms, function (geom) {
  4188. var colorAttr = geom.getAttr('color');
  4189. if (colorAttr) {
  4190. var scale = colorAttr.getScale('color');
  4191. if (scale.type !== 'identity' && !_isScaleExist(scales, scale)) {
  4192. scales.push(scale);
  4193. var field = scale.field;
  4194. var ticks = scale.getTicks();
  4195. var items = [];
  4196. Util.each(ticks, function (tick) {
  4197. var text = tick.text;
  4198. var name = text;
  4199. var scaleValue = tick.value;
  4200. var value = scale.invert(scaleValue);
  4201. var color = colorAttr.mapping(value).join('') || Global.defaultColor;
  4202. var marker = {
  4203. fill: color,
  4204. radius: 3,
  4205. symbol: 'circle',
  4206. stroke: '#fff'
  4207. };
  4208. items.push({
  4209. name: name, // 图例项显示文本的内容
  4210. dataValue: value, // 图例项对应原始数据中的数值
  4211. checked: true,
  4212. marker: marker
  4213. });
  4214. });
  4215. legendItems[field] = items;
  4216. }
  4217. }
  4218. });
  4219. this.set('legendItems', legendItems);
  4220. return legendItems;
  4221. };
  4222. // 注册插件
  4223. Chart.prototype.registerPlugins = function registerPlugins(plugins) {
  4224. var self = this;
  4225. var chartPlugins = self.get('plugins') || [];
  4226. if (!Util.isArray(chartPlugins)) {
  4227. chartPlugins = [chartPlugins];
  4228. }
  4229. [].concat(plugins).forEach(function (plugin) {
  4230. if (chartPlugins.indexOf(plugin) === -1) {
  4231. plugin.init && plugin.init(self); // 进行初始化
  4232. chartPlugins.push(plugin);
  4233. }
  4234. });
  4235. Chart.plugins._cacheId++;
  4236. self.set('plugins', chartPlugins);
  4237. };
  4238. Chart.prototype._renderAxis = function _renderAxis() {
  4239. var axisController = this.get('axisController');
  4240. var xScale = this.getXScale();
  4241. var yScales = this.getYScales();
  4242. var coord = this.get('coord');
  4243. Chart.plugins.notify(this, 'beforeRenderAxis');
  4244. axisController.createAxis(coord, xScale, yScales);
  4245. };
  4246. Chart.prototype._isAutoPadding = function _isAutoPadding() {
  4247. if (this.get('_padding')) {
  4248. return false;
  4249. }
  4250. var padding = this.get('padding');
  4251. if (Util.isArray(padding)) {
  4252. return padding.indexOf('auto') !== -1;
  4253. }
  4254. return padding === 'auto';
  4255. };
  4256. Chart.prototype._updateLayout = function _updateLayout(padding) {
  4257. var width = this.get('width');
  4258. var height = this.get('height');
  4259. var start = {
  4260. x: padding[3],
  4261. y: padding[0]
  4262. };
  4263. var end = {
  4264. x: width - padding[1],
  4265. y: height - padding[2]
  4266. };
  4267. var plot = this.get('plot');
  4268. var coord = this.get('coord');
  4269. plot.reset(start, end);
  4270. coord.reset(plot);
  4271. };
  4272. return Chart;
  4273. }(Base);
  4274. Chart.plugins = Chart.initPlugins();
  4275. module.exports = Chart;
  4276. /***/ }),
  4277. /* 25 */
  4278. /***/ (function(module, exports, __webpack_require__) {
  4279. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  4280. function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
  4281. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
  4282. var Geom = __webpack_require__(4);
  4283. var ShapeUtil = __webpack_require__(12);
  4284. var Util = __webpack_require__(0);
  4285. __webpack_require__(20);
  4286. var Path = function (_Geom) {
  4287. _inherits(Path, _Geom);
  4288. function Path() {
  4289. _classCallCheck(this, Path);
  4290. return _possibleConstructorReturn(this, _Geom.apply(this, arguments));
  4291. }
  4292. /**
  4293. * 获取默认的配置属性
  4294. * @protected
  4295. * @return {Object} 默认属性
  4296. */
  4297. Path.prototype.getDefaultCfg = function getDefaultCfg() {
  4298. var cfg = _Geom.prototype.getDefaultCfg.call(this);
  4299. cfg.type = 'path';
  4300. cfg.shapeType = 'line';
  4301. return cfg;
  4302. };
  4303. Path.prototype.getDrawCfg = function getDrawCfg(obj) {
  4304. var cfg = _Geom.prototype.getDrawCfg.call(this, obj);
  4305. cfg.isStack = this.hasAdjust('stack');
  4306. return cfg;
  4307. };
  4308. Path.prototype.draw = function draw(data, shapeFactory) {
  4309. var self = this;
  4310. var container = self.get('container');
  4311. var yScale = self.getYScale();
  4312. var connectNulls = self.get('connectNulls');
  4313. var splitArray = ShapeUtil.splitArray(data, yScale.field, connectNulls);
  4314. var cfg = this.getDrawCfg(data[0]);
  4315. cfg.origin = data; // path,line 等图的origin 是整个序列
  4316. Util.each(splitArray, function (subData, splitedIndex) {
  4317. cfg.splitedIndex = splitedIndex; // 传入分割片段索引 用于生成id
  4318. cfg.points = subData;
  4319. self.drawShape(cfg.shape, data[0], cfg, container, shapeFactory);
  4320. });
  4321. };
  4322. return Path;
  4323. }(Geom);
  4324. Geom.Path = Path;
  4325. module.exports = Path;
  4326. /***/ }),
  4327. /* 26 */
  4328. /***/ (function(module, exports, __webpack_require__) {
  4329. /**
  4330. * @fileOverview 需要计算所占x轴上的宽度的辅助类
  4331. * @author sima.zhang1990@gmail.com
  4332. * @author dxq613@gmail.com
  4333. */
  4334. var Global = __webpack_require__(1);
  4335. var Util = __webpack_require__(0);
  4336. var SizeMixin = {
  4337. getDefalutSize: function getDefalutSize() {
  4338. var defaultSize = this.get('defaultSize');
  4339. if (!defaultSize) {
  4340. var coord = this.get('coord');
  4341. var xScale = this.getXScale();
  4342. var dataArray = this.get('dataArray');
  4343. var count = xScale.values.length;
  4344. var range = xScale.range;
  4345. var normalizeSize = 1 / count;
  4346. var widthRatio = 1;
  4347. if (coord && coord.isPolar) {
  4348. if (coord.transposed && count > 1) {
  4349. // 极坐标下多层环图
  4350. widthRatio = Global.widthRatio.multiplePie;
  4351. } else {
  4352. widthRatio = Global.widthRatio.rose;
  4353. }
  4354. } else {
  4355. if (xScale.isLinear) {
  4356. normalizeSize *= range[1] - range[0];
  4357. }
  4358. widthRatio = Global.widthRatio.column; // 柱状图要除以2
  4359. }
  4360. normalizeSize *= widthRatio;
  4361. if (this.hasAdjust('dodge')) {
  4362. normalizeSize = normalizeSize / dataArray.length;
  4363. }
  4364. defaultSize = normalizeSize;
  4365. this.set('defaultSize', defaultSize);
  4366. }
  4367. return defaultSize;
  4368. },
  4369. getDimWidth: function getDimWidth(dimName) {
  4370. var coord = this.get('coord');
  4371. var start = coord.convertPoint({
  4372. x: 0,
  4373. y: 0
  4374. });
  4375. var end = coord.convertPoint({
  4376. x: dimName === 'x' ? 1 : 0,
  4377. y: dimName === 'x' ? 0 : 1
  4378. });
  4379. var width = 0;
  4380. if (start && end) {
  4381. width = Math.sqrt(Math.pow(end.x - start.x, 2) + Math.pow(end.y - start.y, 2));
  4382. }
  4383. return width;
  4384. },
  4385. _getWidth: function _getWidth() {
  4386. var width = this.get('_width');
  4387. if (!width) {
  4388. var coord = this.get('coord');
  4389. if (coord && coord.isPolar && !coord.transposed) {
  4390. // 极坐标下 width 为弧长
  4391. width = (coord.endAngle - coord.startAngle) * coord.circleRadius;
  4392. } else {
  4393. width = this.getDimWidth('x'); // 不需要判断transpose
  4394. }
  4395. this.set('_width', width);
  4396. }
  4397. return width;
  4398. },
  4399. _toNormalizedSize: function _toNormalizedSize(size) {
  4400. var width = this._getWidth();
  4401. return size / width;
  4402. },
  4403. _toCoordSize: function _toCoordSize(normalizeSize) {
  4404. var width = this._getWidth();
  4405. return width * normalizeSize;
  4406. },
  4407. getNormalizedSize: function getNormalizedSize(obj) {
  4408. var size = this.getAttrValue('size', obj);
  4409. if (Util.isNil(size)) {
  4410. size = this.getDefalutSize();
  4411. } else {
  4412. size = this._toNormalizedSize(size);
  4413. }
  4414. return size;
  4415. },
  4416. getSize: function getSize(obj) {
  4417. var size = this.getAttrValue('size', obj);
  4418. if (Util.isNil(size)) {
  4419. var normalizeSize = this.getDefalutSize();
  4420. size = this._toCoordSize(normalizeSize);
  4421. }
  4422. return size;
  4423. }
  4424. };
  4425. module.exports = SizeMixin;
  4426. /***/ }),
  4427. /* 27 */
  4428. /***/ (function(module, exports, __webpack_require__) {
  4429. var Core = {};
  4430. var Global = __webpack_require__(1);
  4431. Core.Global = Global;
  4432. Core.version = Global.version;
  4433. Core.Chart = __webpack_require__(24);
  4434. Core.Shape = __webpack_require__(5);
  4435. Core.G = __webpack_require__(6);
  4436. Core.Util = __webpack_require__(0);
  4437. Core.track = function (enable) {
  4438. Global.trackable = enable;
  4439. };
  4440. __webpack_require__(58);
  4441. module.exports = Core;
  4442. /***/ }),
  4443. /* 28 */
  4444. /***/ (function(module, exports, __webpack_require__) {
  4445. /**
  4446. * @fileOverview 默认皮肤
  4447. * @author dxq613@gail.com
  4448. */
  4449. var Util = __webpack_require__(0);
  4450. var color1 = '#E8E8E8'; // 坐标轴线、坐标轴网格线的颜色
  4451. var color2 = '#808080'; // 字体颜色
  4452. var defaultAxis = {
  4453. label: {
  4454. fill: color2,
  4455. fontSize: 10
  4456. },
  4457. line: {
  4458. stroke: color1,
  4459. lineWidth: 1
  4460. },
  4461. grid: {
  4462. type: 'line', // 默认使用线连接
  4463. stroke: color1,
  4464. lineWidth: 1,
  4465. lineDash: [2]
  4466. },
  4467. tickLine: null,
  4468. labelOffset: 7.5
  4469. };
  4470. var Theme = {
  4471. fontFamily: '"Helvetica Neue", "San Francisco", Helvetica, Tahoma, Arial, "PingFang SC", "Hiragino Sans GB", "Heiti SC", "Microsoft YaHei", sans-serif',
  4472. defaultColor: '#1890FF',
  4473. pixelRatio: 1,
  4474. padding: 'auto',
  4475. appendPadding: 15,
  4476. colors: ['#1890FF', '#2FC25B', '#FACC14', '#223273', '#8543E0', '#13C2C2', '#3436C7', '#F04864'],
  4477. shapes: {
  4478. line: ['line', 'dash'],
  4479. point: ['circle', 'hollowCircle']
  4480. },
  4481. sizes: [4, 10],
  4482. axis: {
  4483. bottom: Util.mix({}, defaultAxis, {
  4484. grid: null
  4485. }),
  4486. left: Util.mix({}, defaultAxis, {
  4487. line: null
  4488. }),
  4489. right: Util.mix({}, defaultAxis, {
  4490. line: null
  4491. }),
  4492. circle: Util.mix({}, defaultAxis, {
  4493. line: null
  4494. }),
  4495. radius: Util.mix({}, defaultAxis, {
  4496. labelOffset: 4
  4497. })
  4498. },
  4499. shape: {
  4500. line: {
  4501. lineWidth: 2, // 线的默认宽度
  4502. lineJoin: 'round',
  4503. lineCap: 'round'
  4504. },
  4505. point: {
  4506. lineWidth: 0,
  4507. size: 3 // 圆的默认半径
  4508. },
  4509. area: {
  4510. fillOpacity: 0.1
  4511. }
  4512. },
  4513. _defaultAxis: defaultAxis
  4514. };
  4515. module.exports = Theme;
  4516. /***/ }),
  4517. /* 29 */
  4518. /***/ (function(module, exports) {
  4519. var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
  4520. var DomUtil = void 0;
  4521. /**
  4522. * Detects support for options object argument in addEventListener.
  4523. * https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/addEventListener#Safely_detecting_option_support
  4524. * @private
  4525. */
  4526. var supportsEventListenerOptions = function () {
  4527. var supports = false;
  4528. try {
  4529. var options = Object.defineProperty({}, 'passive', {
  4530. get: function get() {
  4531. supports = true;
  4532. }
  4533. });
  4534. window.addEventListener('e', null, options);
  4535. } catch (e) {
  4536. // continue regardless of error
  4537. }
  4538. return supports;
  4539. }();
  4540. // Default passive to true as expected by Chrome for 'touchstart' and 'touchend' events.
  4541. // https://github.com/chartjs/Chart.js/issues/4287
  4542. var eventListenerOptions = supportsEventListenerOptions ? { passive: true } : false;
  4543. function createEvent(type, chart, x, y, nativeEvent) {
  4544. return {
  4545. type: type,
  4546. chart: chart,
  4547. native: nativeEvent || null,
  4548. x: x !== undefined ? x : null,
  4549. y: y !== undefined ? y : null
  4550. };
  4551. }
  4552. function fromNativeEvent(event, chart) {
  4553. // TODO: chart 改成 dom
  4554. var type = event.type;
  4555. var point = {};
  4556. var touches = event.targetTouches;
  4557. if (touches && touches.length > 0) {
  4558. point.x = touches[0].clientX;
  4559. point.y = touches[0].clientY;
  4560. } else {
  4561. point.x = event.clientX;
  4562. point.y = event.clientY;
  4563. }
  4564. var canvas = chart.get('canvas');
  4565. var pos = DomUtil.getRelativePosition(point, canvas);
  4566. return createEvent(type, chart, pos.x, pos.y, event);
  4567. }
  4568. DomUtil = {
  4569. /* global wx, my, module */
  4570. isWx: (typeof wx === 'undefined' ? 'undefined' : _typeof(wx)) === 'object' && typeof wx.getSystemInfoSync === 'function', // weixin miniprogram
  4571. isMy: (typeof my === 'undefined' ? 'undefined' : _typeof(my)) === 'object' && typeof my.getSystemInfoSync === 'function', // ant miniprogram
  4572. isNode: typeof module !== 'undefined' && typeof module.exports !== 'undefined', // in node
  4573. isBrowser: typeof window !== 'undefined' && typeof window.document !== 'undefined' && typeof window.sessionStorage !== 'undefined', // in browser
  4574. getPixelRatio: function getPixelRatio() {
  4575. return window && window.devicePixelRatio || 1;
  4576. },
  4577. getStyle: function getStyle(el, property) {
  4578. return el.currentStyle ? el.currentStyle[property] : document.defaultView.getComputedStyle(el, null).getPropertyValue(property);
  4579. },
  4580. getWidth: function getWidth(el) {
  4581. var width = this.getStyle(el, 'width');
  4582. if (width === 'auto') {
  4583. width = el.offsetWidth;
  4584. }
  4585. return parseFloat(width);
  4586. },
  4587. getHeight: function getHeight(el) {
  4588. var height = this.getStyle(el, 'height');
  4589. if (height === 'auto') {
  4590. height = el.offsetHeight;
  4591. }
  4592. return parseFloat(height);
  4593. },
  4594. getDomById: function getDomById(id) {
  4595. if (!id) {
  4596. return null;
  4597. }
  4598. return document.getElementById(id);
  4599. },
  4600. getRelativePosition: function getRelativePosition(point, canvas) {
  4601. var canvasDom = canvas.get('el');
  4602. var _canvasDom$getBoundin = canvasDom.getBoundingClientRect(),
  4603. top = _canvasDom$getBoundin.top,
  4604. right = _canvasDom$getBoundin.right,
  4605. bottom = _canvasDom$getBoundin.bottom,
  4606. left = _canvasDom$getBoundin.left;
  4607. var paddingLeft = parseFloat(this.getStyle(canvasDom, 'padding-left'));
  4608. var paddingTop = parseFloat(this.getStyle(canvasDom, 'padding-top'));
  4609. var paddingRight = parseFloat(this.getStyle(canvasDom, 'padding-right'));
  4610. var paddingBottom = parseFloat(this.getStyle(canvasDom, 'padding-bottom'));
  4611. var width = right - left - paddingLeft - paddingRight;
  4612. var height = bottom - top - paddingTop - paddingBottom;
  4613. var pixelRatio = canvas.get('pixelRatio');
  4614. // 为了保证数据查找的精度,这里不要取整
  4615. var mouseX = (point.x - left - paddingLeft) / width * canvasDom.width / pixelRatio;
  4616. var mouseY = (point.y - top - paddingTop) / height * canvasDom.height / pixelRatio;
  4617. return {
  4618. x: mouseX,
  4619. y: mouseY
  4620. };
  4621. },
  4622. addEventListener: function addEventListener(source, type, listener) {
  4623. DomUtil.isBrowser && source.addEventListener(type, listener, eventListenerOptions);
  4624. },
  4625. removeEventListener: function removeEventListener(source, type, listener) {
  4626. DomUtil.isBrowser && source.removeEventListener(type, listener, eventListenerOptions);
  4627. },
  4628. createEvent: function createEvent(event, chart) {
  4629. return fromNativeEvent(event, chart);
  4630. },
  4631. measureText: function measureText(text, font, ctx) {
  4632. if (!ctx) {
  4633. ctx = document.createElement('canvas').getContext('2d');
  4634. }
  4635. ctx.font = font || '12px sans-serif';
  4636. return ctx.measureText(text);
  4637. }
  4638. };
  4639. module.exports = DomUtil;
  4640. /***/ }),
  4641. /* 30 */
  4642. /***/ (function(module, exports, __webpack_require__) {
  4643. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  4644. var Util = __webpack_require__(0);
  4645. var Plot = function () {
  4646. function Plot(cfg) {
  4647. _classCallCheck(this, Plot);
  4648. Util.mix(this, cfg);
  4649. this._init();
  4650. }
  4651. Plot.prototype._init = function _init() {
  4652. var self = this;
  4653. var start = self.start;
  4654. var end = self.end;
  4655. var xMin = Math.min(start.x, end.x);
  4656. var xMax = Math.max(start.x, end.x);
  4657. var yMin = Math.min(start.y, end.y);
  4658. var yMax = Math.max(start.y, end.y);
  4659. this.tl = {
  4660. x: xMin,
  4661. y: yMin
  4662. };
  4663. this.tr = {
  4664. x: xMax,
  4665. y: yMin
  4666. };
  4667. this.bl = {
  4668. x: xMin,
  4669. y: yMax
  4670. };
  4671. this.br = {
  4672. x: xMax,
  4673. y: yMax
  4674. };
  4675. this.width = xMax - xMin;
  4676. this.height = yMax - yMin;
  4677. };
  4678. /**
  4679. * 重置
  4680. * @param {Object} start 起始点
  4681. * @param {Object} end 结束点
  4682. */
  4683. Plot.prototype.reset = function reset(start, end) {
  4684. this.start = start;
  4685. this.end = end;
  4686. this._init();
  4687. };
  4688. /**
  4689. * 点是否在图表的绘制区域内
  4690. * @param {Nubmer} x x坐标点
  4691. * @param {[type]} y y坐标点
  4692. * @return {Boolean} 是否在绘制区域内
  4693. */
  4694. Plot.prototype.isInRange = function isInRange(x, y) {
  4695. if (Util.isObject(x)) {
  4696. y = x.y;
  4697. x = x.x;
  4698. }
  4699. var tl = this.tl;
  4700. var br = this.br;
  4701. return tl.x <= x && x <= br.x && tl.y <= y && y <= br.y;
  4702. };
  4703. return Plot;
  4704. }();
  4705. module.exports = Plot;
  4706. /***/ }),
  4707. /* 31 */
  4708. /***/ (function(module, exports, __webpack_require__) {
  4709. var Coord = __webpack_require__(13);
  4710. __webpack_require__(32);
  4711. module.exports = Coord;
  4712. /***/ }),
  4713. /* 32 */
  4714. /***/ (function(module, exports, __webpack_require__) {
  4715. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  4716. function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
  4717. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
  4718. var Base = __webpack_require__(13);
  4719. var Cartesian = function (_Base) {
  4720. _inherits(Cartesian, _Base);
  4721. function Cartesian() {
  4722. _classCallCheck(this, Cartesian);
  4723. return _possibleConstructorReturn(this, _Base.apply(this, arguments));
  4724. }
  4725. Cartesian.prototype._initDefaultCfg = function _initDefaultCfg() {
  4726. this.type = 'cartesian';
  4727. this.transposed = false;
  4728. this.isRect = true;
  4729. };
  4730. Cartesian.prototype.init = function init(start, end) {
  4731. this.x = {
  4732. start: start.x,
  4733. end: end.x
  4734. };
  4735. this.y = {
  4736. start: start.y,
  4737. end: end.y
  4738. };
  4739. };
  4740. Cartesian.prototype.convertPoint = function convertPoint(point) {
  4741. var self = this;
  4742. var transposed = self.transposed;
  4743. var xDim = transposed ? 'y' : 'x';
  4744. var yDim = transposed ? 'x' : 'y';
  4745. var x = self.x;
  4746. var y = self.y;
  4747. return {
  4748. x: x.start + (x.end - x.start) * point[xDim],
  4749. y: y.start + (y.end - y.start) * point[yDim]
  4750. };
  4751. };
  4752. Cartesian.prototype.invertPoint = function invertPoint(point) {
  4753. var self = this;
  4754. var transposed = self.transposed;
  4755. var xDim = transposed ? 'y' : 'x';
  4756. var yDim = transposed ? 'x' : 'y';
  4757. var x = self.x;
  4758. var y = self.y;
  4759. var rst = {};
  4760. rst[xDim] = (point.x - x.start) / (x.end - x.start);
  4761. rst[yDim] = (point.y - y.start) / (y.end - y.start);
  4762. return rst;
  4763. };
  4764. return Cartesian;
  4765. }(Base);
  4766. Base.Cartesian = Cartesian;
  4767. Base.Rect = Cartesian;
  4768. module.exports = Cartesian;
  4769. /***/ }),
  4770. /* 33 */
  4771. /***/ (function(module, exports, __webpack_require__) {
  4772. module.exports = {
  4773. Position: __webpack_require__(34),
  4774. Shape: __webpack_require__(35),
  4775. Size: __webpack_require__(36),
  4776. Color: __webpack_require__(37)
  4777. };
  4778. /***/ }),
  4779. /* 34 */
  4780. /***/ (function(module, exports, __webpack_require__) {
  4781. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  4782. function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
  4783. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
  4784. var Util = __webpack_require__(0);
  4785. var Base = __webpack_require__(10);
  4786. var Position = function (_Base) {
  4787. _inherits(Position, _Base);
  4788. function Position(cfg) {
  4789. _classCallCheck(this, Position);
  4790. var _this = _possibleConstructorReturn(this, _Base.call(this, cfg));
  4791. _this.names = ['x', 'y'];
  4792. _this.type = 'position';
  4793. return _this;
  4794. }
  4795. Position.prototype.mapping = function mapping(x, y) {
  4796. var scales = this.scales;
  4797. var coord = this.coord;
  4798. var scaleX = scales[0];
  4799. var scaleY = scales[1];
  4800. var rstX = void 0;
  4801. var rstY = void 0;
  4802. var obj = void 0;
  4803. if (Util.isNil(x) || Util.isNil(y)) {
  4804. return [];
  4805. }
  4806. if (Util.isArray(y) && Util.isArray(x)) {
  4807. rstX = [];
  4808. rstY = [];
  4809. for (var i = 0, j = 0, xLen = x.length, yLen = y.length; i < xLen && j < yLen; i++, j++) {
  4810. obj = coord.convertPoint({
  4811. x: scaleX.scale(x[i]),
  4812. y: scaleY.scale(y[j])
  4813. });
  4814. rstX.push(obj.x);
  4815. rstY.push(obj.y);
  4816. }
  4817. } else if (Util.isArray(y)) {
  4818. x = scaleX.scale(x);
  4819. rstY = [];
  4820. Util.each(y, function (yVal) {
  4821. yVal = scaleY.scale(yVal);
  4822. obj = coord.convertPoint({
  4823. x: x,
  4824. y: yVal
  4825. });
  4826. if (rstX && rstX !== obj.x) {
  4827. if (!Util.isArray(rstX)) {
  4828. rstX = [rstX];
  4829. }
  4830. rstX.push(obj.x);
  4831. } else {
  4832. rstX = obj.x;
  4833. }
  4834. rstY.push(obj.y);
  4835. });
  4836. } else if (Util.isArray(x)) {
  4837. y = scaleY.scale(y);
  4838. rstX = [];
  4839. Util.each(x, function (xVal) {
  4840. xVal = scaleX.scale(xVal);
  4841. obj = coord.convertPoint({
  4842. x: xVal,
  4843. y: y
  4844. });
  4845. if (rstY && rstY !== obj.y) {
  4846. if (!Util.isArray(rstY)) {
  4847. rstY = [rstY];
  4848. }
  4849. rstY.push(obj.y);
  4850. } else {
  4851. rstY = obj.y;
  4852. }
  4853. rstX.push(obj.x);
  4854. });
  4855. } else {
  4856. x = scaleX.scale(x);
  4857. y = scaleY.scale(y);
  4858. var point = coord.convertPoint({
  4859. x: x,
  4860. y: y
  4861. });
  4862. rstX = point.x;
  4863. rstY = point.y;
  4864. }
  4865. return [rstX, rstY];
  4866. };
  4867. return Position;
  4868. }(Base);
  4869. module.exports = Position;
  4870. /***/ }),
  4871. /* 35 */
  4872. /***/ (function(module, exports, __webpack_require__) {
  4873. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  4874. function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
  4875. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
  4876. var Base = __webpack_require__(10);
  4877. var Shape = function (_Base) {
  4878. _inherits(Shape, _Base);
  4879. function Shape(cfg) {
  4880. _classCallCheck(this, Shape);
  4881. var _this = _possibleConstructorReturn(this, _Base.call(this, cfg));
  4882. _this.names = ['shape'];
  4883. _this.type = 'shape';
  4884. _this.gradient = null;
  4885. return _this;
  4886. }
  4887. /**
  4888. * @override
  4889. */
  4890. Shape.prototype.getLinearValue = function getLinearValue(percent) {
  4891. var values = this.values;
  4892. var index = Math.round((values.length - 1) * percent);
  4893. return values[index];
  4894. };
  4895. return Shape;
  4896. }(Base);
  4897. module.exports = Shape;
  4898. /***/ }),
  4899. /* 36 */
  4900. /***/ (function(module, exports, __webpack_require__) {
  4901. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  4902. function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
  4903. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
  4904. var Base = __webpack_require__(10);
  4905. var Size = function (_Base) {
  4906. _inherits(Size, _Base);
  4907. function Size(cfg) {
  4908. _classCallCheck(this, Size);
  4909. var _this = _possibleConstructorReturn(this, _Base.call(this, cfg));
  4910. _this.names = ['size'];
  4911. _this.type = 'size';
  4912. _this.gradient = null;
  4913. return _this;
  4914. }
  4915. return Size;
  4916. }(Base);
  4917. module.exports = Size;
  4918. /***/ }),
  4919. /* 37 */
  4920. /***/ (function(module, exports, __webpack_require__) {
  4921. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  4922. function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
  4923. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
  4924. var ColorUtil = __webpack_require__(38);
  4925. var Base = __webpack_require__(10);
  4926. var Util = __webpack_require__(0);
  4927. var Color = function (_Base) {
  4928. _inherits(Color, _Base);
  4929. function Color(cfg) {
  4930. _classCallCheck(this, Color);
  4931. var _this = _possibleConstructorReturn(this, _Base.call(this, cfg));
  4932. _this.names = ['color'];
  4933. _this.type = 'color';
  4934. _this.gradient = null;
  4935. if (Util.isString(_this.values)) {
  4936. _this.linear = true;
  4937. }
  4938. return _this;
  4939. }
  4940. /**
  4941. * @override
  4942. */
  4943. Color.prototype.getLinearValue = function getLinearValue(percent) {
  4944. var gradient = this.gradient;
  4945. if (!gradient) {
  4946. var values = this.values;
  4947. gradient = ColorUtil.gradient(values);
  4948. this.gradient = gradient;
  4949. }
  4950. return gradient(percent);
  4951. };
  4952. return Color;
  4953. }(Base);
  4954. module.exports = Color;
  4955. /***/ }),
  4956. /* 38 */
  4957. /***/ (function(module, exports, __webpack_require__) {
  4958. var Util = __webpack_require__(0);
  4959. // 获取颜色之间的插值
  4960. function getValue(start, end, percent, index) {
  4961. var value = start[index] + (end[index] - start[index]) * percent;
  4962. return value;
  4963. }
  4964. // 数组转换成颜色
  4965. function arr2hex(arr) {
  4966. return '#' + toRGBValue(arr[0]) + toRGBValue(arr[1]) + toRGBValue(arr[2]);
  4967. }
  4968. // 将数值从 0-255 转换成16进制字符串
  4969. function toRGBValue(value) {
  4970. value = Math.round(value);
  4971. value = value.toString(16);
  4972. if (value.length === 1) {
  4973. value = '0' + value;
  4974. }
  4975. return value;
  4976. }
  4977. function calColor(colors, percent) {
  4978. var steps = colors.length - 1;
  4979. var step = Math.floor(steps * percent);
  4980. var left = steps * percent - step;
  4981. var start = colors[step];
  4982. var end = step === steps ? start : colors[step + 1];
  4983. var rgb = arr2hex([getValue(start, end, left, 0), getValue(start, end, left, 1), getValue(start, end, left, 2)]);
  4984. return rgb;
  4985. }
  4986. // rgb 颜色转换成数组
  4987. function hex2arr(str) {
  4988. var arr = [];
  4989. arr.push(parseInt(str.substr(1, 2), 16));
  4990. arr.push(parseInt(str.substr(3, 2), 16));
  4991. arr.push(parseInt(str.substr(5, 2), 16));
  4992. return arr;
  4993. }
  4994. var colorCache = {
  4995. black: '#000000',
  4996. blue: '#0000ff',
  4997. grey: '#808080',
  4998. green: '#008000',
  4999. orange: '#ffa500',
  5000. pink: '#ffc0cb',
  5001. purple: '#800080',
  5002. red: '#ff0000',
  5003. white: '#ffffff',
  5004. yellow: '#ffff00'
  5005. };
  5006. var ColorUtil = {
  5007. /**
  5008. * 将颜色转换到 hex 的格式
  5009. * @param {String} color 颜色
  5010. * @return {String} 将颜色转换到 '#ffffff' 的格式
  5011. */
  5012. toHex: function toHex(color) {
  5013. if (colorCache[color]) {
  5014. return colorCache[color];
  5015. }
  5016. if (color[0] === '#') {
  5017. if (color.length === 7) {
  5018. return color;
  5019. }
  5020. var hex = color.replace(/^#?([a-f\d])([a-f\d])([a-f\d])$/i, function (m, r, g, b) {
  5021. return '#' + r + r + g + g + b + b;
  5022. }); // hex3 to hex6
  5023. colorCache[color] = hex;
  5024. return hex;
  5025. }
  5026. // rgb/rgba to hex
  5027. var rst = color.match(/^rgba?[\s+]?\([\s+]?(\d+)[\s+]?,[\s+]?(\d+)[\s+]?,[\s+]?(\d+)[\s+]?/i);
  5028. rst.shift();
  5029. rst = arr2hex(rst);
  5030. colorCache[color] = rst;
  5031. return rst;
  5032. },
  5033. hex2arr: hex2arr,
  5034. /**
  5035. * 获取渐变函数
  5036. * @param {Array} colors 多个颜色
  5037. * @return {String} 颜色值
  5038. */
  5039. gradient: function gradient(colors) {
  5040. var points = [];
  5041. if (Util.isString(colors)) {
  5042. colors = colors.split('-');
  5043. }
  5044. Util.each(colors, function (color) {
  5045. if (color.indexOf('#') === -1) {
  5046. color = ColorUtil.toHex(color);
  5047. }
  5048. points.push(hex2arr(color));
  5049. });
  5050. return function (percent) {
  5051. return calColor(points, percent);
  5052. };
  5053. }
  5054. };
  5055. module.exports = ColorUtil;
  5056. /***/ }),
  5057. /* 39 */
  5058. /***/ (function(module, exports, __webpack_require__) {
  5059. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  5060. var Util = __webpack_require__(0);
  5061. var Global = __webpack_require__(1);
  5062. var Scale = __webpack_require__(40);
  5063. var SCALE_TYPES_MAP = {
  5064. linear: 'Linear',
  5065. cat: 'Cat',
  5066. timeCat: 'TimeCat',
  5067. identity: 'Identity'
  5068. };
  5069. function getRange(values) {
  5070. if (!values.length) {
  5071. // 空数组需要手动设置 min:0 max:0,否则 linear scale 会报错
  5072. return {
  5073. min: 0,
  5074. max: 0
  5075. };
  5076. }
  5077. var max = Math.max.apply(null, values);
  5078. var min = Math.min.apply(null, values);
  5079. return {
  5080. min: min,
  5081. max: max
  5082. };
  5083. }
  5084. var ScaleController = function () {
  5085. function ScaleController(cfg) {
  5086. _classCallCheck(this, ScaleController);
  5087. // defs 列定义
  5088. this.defs = {};
  5089. Util.mix(this, cfg);
  5090. }
  5091. ScaleController.prototype._getDef = function _getDef(field) {
  5092. var defs = this.defs;
  5093. var def = null;
  5094. if (Global.scales[field] || defs[field]) {
  5095. def = Util.mix({}, Global.scales[field]);
  5096. // 处理覆盖属性的问题
  5097. Util.each(defs[field], function (v, k) {
  5098. if (Util.isNil(v)) {
  5099. delete def[k];
  5100. } else {
  5101. def[k] = v;
  5102. }
  5103. });
  5104. }
  5105. return def;
  5106. };
  5107. ScaleController.prototype._getDefaultType = function _getDefaultType(field, data) {
  5108. var type = 'linear';
  5109. var value = Util.Array.firstValue(data, field);
  5110. if (Util.isArray(value)) {
  5111. value = value[0];
  5112. }
  5113. if (Util.isString(value)) {
  5114. type = 'cat';
  5115. }
  5116. return type;
  5117. };
  5118. ScaleController.prototype._getScaleCfg = function _getScaleCfg(type, field, data) {
  5119. var cfg = {
  5120. field: field
  5121. };
  5122. var values = Util.Array.values(data, field);
  5123. cfg.values = values;
  5124. if (type !== 'cat' && type !== 'timeCat') {
  5125. var _getRange = getRange(values),
  5126. min = _getRange.min,
  5127. max = _getRange.max;
  5128. cfg.min = min;
  5129. cfg.max = max;
  5130. }
  5131. return cfg;
  5132. };
  5133. ScaleController.prototype.createScale = function createScale(field, data) {
  5134. var self = this;
  5135. var def = self._getDef(field);
  5136. var scale = void 0;
  5137. // 如果数据为空直接返回常量度量
  5138. if (!data || !data.length) {
  5139. if (def && def.type) {
  5140. scale = new Scale[SCALE_TYPES_MAP[def.type]](def);
  5141. } else {
  5142. scale = new Scale.Identity({
  5143. value: field,
  5144. field: field.toString(),
  5145. values: [field]
  5146. });
  5147. }
  5148. return scale;
  5149. }
  5150. var firstObj = data[0];
  5151. var firstValue = firstObj[field];
  5152. if (firstValue === null) {
  5153. firstValue = Util.Array.firstValue(data, field);
  5154. }
  5155. if (Util.isNumber(field) || Util.isNil(firstValue) && !def) {
  5156. scale = new Scale.Identity({
  5157. value: field,
  5158. field: field.toString(),
  5159. values: [field]
  5160. });
  5161. } else {
  5162. // 如果已经定义过这个度量
  5163. var type = void 0;
  5164. if (def) {
  5165. type = def.type;
  5166. }
  5167. type = type || self._getDefaultType(field, data);
  5168. var cfg = self._getScaleCfg(type, field, data);
  5169. if (def) {
  5170. Util.mix(cfg, def);
  5171. }
  5172. scale = new Scale[SCALE_TYPES_MAP[type]](cfg);
  5173. }
  5174. return scale;
  5175. };
  5176. return ScaleController;
  5177. }();
  5178. module.exports = ScaleController;
  5179. /***/ }),
  5180. /* 40 */
  5181. /***/ (function(module, exports, __webpack_require__) {
  5182. /**
  5183. * @fileOverview Scale entry, used to reference all the scales
  5184. * @author dxq613@gmail.com
  5185. */
  5186. var Scale = __webpack_require__(8);
  5187. __webpack_require__(41);
  5188. __webpack_require__(44);
  5189. __webpack_require__(21);
  5190. module.exports = Scale;
  5191. /***/ }),
  5192. /* 41 */
  5193. /***/ (function(module, exports, __webpack_require__) {
  5194. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  5195. function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
  5196. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
  5197. /**
  5198. * @fileOverview The measurement of linear data scale function
  5199. * @author dxq613@gmail.com
  5200. */
  5201. var Base = __webpack_require__(8);
  5202. var Util = __webpack_require__(0);
  5203. var numberAuto = __webpack_require__(42);
  5204. /**
  5205. * 线性度量
  5206. * @class Scale.Linear
  5207. */
  5208. var Linear = function (_Base) {
  5209. _inherits(Linear, _Base);
  5210. function Linear() {
  5211. _classCallCheck(this, Linear);
  5212. return _possibleConstructorReturn(this, _Base.apply(this, arguments));
  5213. }
  5214. Linear.prototype._initDefaultCfg = function _initDefaultCfg() {
  5215. this.type = 'linear';
  5216. this.isLinear = true;
  5217. /**
  5218. * min value of the scale
  5219. * @type {Number}
  5220. * @default null
  5221. */
  5222. this.min = null;
  5223. /**
  5224. * max value of the scale
  5225. * @type {Number}
  5226. * @default null
  5227. */
  5228. this.max = null;
  5229. /**
  5230. * 是否为了用户习惯,优化min,max和ticks,如果进行优化,则会根据生成的ticks调整min,max,否则舍弃(min,max)范围之外的ticks
  5231. * @type {Boolean}
  5232. * @default false
  5233. */
  5234. this.nice = true;
  5235. /**
  5236. * 自动生成标记时的个数
  5237. * @type {Number}
  5238. * @default null
  5239. */
  5240. this.tickCount = null;
  5241. /**
  5242. * 坐标轴点之间的间距,指的是真实数据的差值
  5243. * @type {Number}
  5244. * @default null
  5245. */
  5246. this.tickInterval = null;
  5247. /**
  5248. * 格式化函数,输出文本或者tick时的格式化函数
  5249. * @type {Function}
  5250. */
  5251. this.formatter = null;
  5252. /**
  5253. * 输出的值域
  5254. * @type {Array}
  5255. */
  5256. this.range = [0, 1];
  5257. /**
  5258. * 度量的标记
  5259. * @type {Array}
  5260. */
  5261. this.ticks = null;
  5262. /**
  5263. * 参与度量计算的值,可选项
  5264. * @type {Array}
  5265. */
  5266. this.values = [];
  5267. };
  5268. /**
  5269. * @protected
  5270. * @override
  5271. */
  5272. Linear.prototype.init = function init() {
  5273. var self = this;
  5274. if (!self.ticks) {
  5275. self.min = self.translate(self.min);
  5276. self.max = self.translate(self.max);
  5277. self.initTicks();
  5278. } else {
  5279. var ticks = self.ticks;
  5280. var firstValue = self.translate(ticks[0]);
  5281. var lastValue = self.translate(ticks[ticks.length - 1]);
  5282. if (Util.isNil(self.min) || self.min > firstValue) {
  5283. self.min = firstValue;
  5284. }
  5285. if (Util.isNil(self.max) || self.max < lastValue) {
  5286. self.max = lastValue;
  5287. }
  5288. }
  5289. };
  5290. /**
  5291. * 计算坐标点
  5292. * @protected
  5293. * @return {Array} 计算完成的坐标点
  5294. */
  5295. Linear.prototype.calculateTicks = function calculateTicks() {
  5296. var self = this;
  5297. var min = self.min;
  5298. var max = self.max;
  5299. var count = self.tickCount;
  5300. if (count === 1) {
  5301. throw new Error('linear scale\'tickCount should not be 1');
  5302. }
  5303. var interval = self.tickInterval;
  5304. if (max < min) {
  5305. throw new Error('max: ' + max + ' should not be less than min: ' + min);
  5306. }
  5307. var tmp = numberAuto({
  5308. min: min,
  5309. max: max,
  5310. minCount: count,
  5311. maxCount: count,
  5312. interval: interval
  5313. });
  5314. return tmp.ticks;
  5315. };
  5316. // 初始化ticks
  5317. Linear.prototype.initTicks = function initTicks() {
  5318. var self = this;
  5319. var calTicks = self.calculateTicks();
  5320. if (self.nice) {
  5321. // 如果需要优化显示的tick
  5322. self.ticks = calTicks;
  5323. self.min = calTicks[0];
  5324. self.max = calTicks[calTicks.length - 1];
  5325. } else {
  5326. var ticks = [];
  5327. Util.each(calTicks, function (tick) {
  5328. if (tick >= self.min && tick <= self.max) {
  5329. ticks.push(tick);
  5330. }
  5331. });
  5332. self.ticks = ticks;
  5333. }
  5334. };
  5335. /**
  5336. * @override
  5337. */
  5338. Linear.prototype.scale = function scale(value) {
  5339. if (value === null || value === undefined) {
  5340. return NaN;
  5341. }
  5342. var max = this.max;
  5343. var min = this.min;
  5344. if (max === min) {
  5345. return 0;
  5346. }
  5347. var percent = (value - min) / (max - min);
  5348. var rangeMin = this.rangeMin();
  5349. var rangeMax = this.rangeMax();
  5350. return rangeMin + percent * (rangeMax - rangeMin);
  5351. };
  5352. /**
  5353. * @override
  5354. */
  5355. Linear.prototype.invert = function invert(value) {
  5356. var percent = (value - this.rangeMin()) / (this.rangeMax() - this.rangeMin());
  5357. return this.min + percent * (this.max - this.min);
  5358. };
  5359. return Linear;
  5360. }(Base);
  5361. Base.Linear = Linear;
  5362. module.exports = Linear;
  5363. /***/ }),
  5364. /* 42 */
  5365. /***/ (function(module, exports, __webpack_require__) {
  5366. /**
  5367. * @fileOverview 自动计算数字坐标轴
  5368. * @author dxq613@gmail.com
  5369. */
  5370. var Util = __webpack_require__(0);
  5371. var AutoUtil = __webpack_require__(43);
  5372. var MIN_COUNT = 5;
  5373. var MAX_COUNT = 7;
  5374. var INTERVAL_ARRAY = [0, 1, 2, 4, 5, 10];
  5375. module.exports = function (info) {
  5376. var min = info.min;
  5377. var max = info.max;
  5378. var interval = info.interval;
  5379. var ticks = [];
  5380. var minCount = info.minCount || MIN_COUNT;
  5381. var maxCount = info.maxCount || MAX_COUNT;
  5382. var avgCount = (minCount + maxCount) / 2;
  5383. var count = void 0;
  5384. if (Util.isNil(min)) {
  5385. min = 0;
  5386. }
  5387. if (Util.isNil(max)) {
  5388. max = 0;
  5389. }
  5390. if (max === min) {
  5391. if (min === 0) {
  5392. max = 1;
  5393. } else {
  5394. if (min > 0) {
  5395. min = 0;
  5396. } else {
  5397. max = 0;
  5398. }
  5399. }
  5400. if (max - min < 5 && !interval && max - min >= 1) {
  5401. interval = 1;
  5402. }
  5403. }
  5404. if (Util.isNil(interval)) {
  5405. // 计算间距
  5406. var temp = (max - min) / (avgCount - 1);
  5407. interval = AutoUtil.snapFactorTo(temp, INTERVAL_ARRAY, 'ceil');
  5408. if (maxCount !== minCount) {
  5409. count = parseInt((max - min) / interval, 10);
  5410. if (count > maxCount) {
  5411. count = maxCount;
  5412. }
  5413. if (count < minCount) {
  5414. count = minCount;
  5415. }
  5416. // 不确定tick的个数时,使得tick偏小
  5417. interval = AutoUtil.snapFactorTo((max - min) / (count - 1), INTERVAL_ARRAY, 'floor');
  5418. } else {
  5419. count = avgCount;
  5420. }
  5421. }
  5422. if (info.interval || maxCount !== minCount) {
  5423. // 校正 max 和 min
  5424. max = AutoUtil.snapMultiple(max, interval, 'ceil'); // 向上逼近
  5425. min = AutoUtil.snapMultiple(min, interval, 'floor'); // 向下逼近
  5426. count = Math.round((max - min) / interval);
  5427. min = Util.fixedBase(min, interval);
  5428. max = Util.fixedBase(max, interval);
  5429. } else {
  5430. avgCount = parseInt(avgCount, 10); // 取整
  5431. var avg = (max + min) / 2;
  5432. var avgTick = AutoUtil.snapMultiple(avg, interval, 'ceil');
  5433. var sideCount = Math.floor((avgCount - 2) / 2);
  5434. var maxTick = avgTick + sideCount * interval;
  5435. var minTick = void 0;
  5436. if (avgCount % 2 === 0) {
  5437. minTick = avgTick - sideCount * interval;
  5438. } else {
  5439. minTick = avgTick - (sideCount + 1) * interval;
  5440. }
  5441. if (maxTick < max) {
  5442. maxTick = maxTick + interval;
  5443. }
  5444. if (minTick > min) {
  5445. minTick = minTick - interval;
  5446. }
  5447. max = Util.fixedBase(maxTick, interval);
  5448. min = Util.fixedBase(minTick, interval);
  5449. }
  5450. ticks.push(min);
  5451. for (var i = 1; i < count; i++) {
  5452. ticks.push(Util.fixedBase(interval * i + min, interval));
  5453. }
  5454. if (ticks[ticks.length - 1] < max) {
  5455. ticks.push(max);
  5456. }
  5457. return {
  5458. min: min,
  5459. max: max,
  5460. interval: interval,
  5461. count: count,
  5462. ticks: ticks
  5463. };
  5464. };
  5465. /***/ }),
  5466. /* 43 */
  5467. /***/ (function(module, exports) {
  5468. /**
  5469. * @fileOverview 计算方法
  5470. * @author dxq613@gmail.com
  5471. */
  5472. // 获取系数
  5473. function getFactor(v) {
  5474. var factor = 1;
  5475. if (v < 1) {
  5476. var count = 0;
  5477. while (v < 1) {
  5478. factor = factor / 10;
  5479. v = v * 10;
  5480. count++;
  5481. }
  5482. // 浮点数计算出现问题
  5483. if (factor.toString().length > 20) {
  5484. factor = parseFloat(factor.toFixed(count));
  5485. }
  5486. } else {
  5487. while (v > 10) {
  5488. factor = factor * 10;
  5489. v = v / 10;
  5490. }
  5491. }
  5492. return factor;
  5493. }
  5494. // 取小于当前值的
  5495. function arrayFloor(values, value) {
  5496. var length = values.length;
  5497. if (length === 0) {
  5498. return NaN;
  5499. }
  5500. var pre = values[0];
  5501. if (value < values[0]) {
  5502. return NaN;
  5503. }
  5504. if (value >= values[length - 1]) {
  5505. return values[length - 1];
  5506. }
  5507. for (var i = 1, len = values.length; i < len; i++) {
  5508. if (value < values[i]) {
  5509. break;
  5510. }
  5511. pre = values[i];
  5512. }
  5513. return pre;
  5514. }
  5515. // 大于当前值的第一个
  5516. function arrayCeiling(values, value) {
  5517. var length = values.length;
  5518. if (length === 0) {
  5519. return NaN;
  5520. }
  5521. // var pre = values[0];
  5522. var rst = void 0;
  5523. if (value > values[length - 1]) {
  5524. return NaN;
  5525. }
  5526. if (value < values[0]) {
  5527. return values[0];
  5528. }
  5529. for (var i = 1, len = values.length; i < len; i++) {
  5530. if (value <= values[i]) {
  5531. rst = values[i];
  5532. break;
  5533. }
  5534. }
  5535. return rst;
  5536. }
  5537. var Util = {
  5538. // 获取逼近的数值
  5539. snapFactorTo: function snapFactorTo(v, arr, snapType) {
  5540. // 假设 v = -512,isFloor = true
  5541. if (isNaN(v)) {
  5542. return NaN;
  5543. }
  5544. var factor = 1; // 计算系数
  5545. if (v !== 0) {
  5546. if (v < 0) {
  5547. factor = -1;
  5548. }
  5549. v = v * factor; // v = 512
  5550. var tmpFactor = getFactor(v);
  5551. factor = factor * tmpFactor; // factor = -100
  5552. v = v / tmpFactor; // v = 5.12
  5553. }
  5554. if (snapType === 'floor') {
  5555. v = Util.snapFloor(arr, v); // v = 5
  5556. } else if (snapType === 'ceil') {
  5557. v = Util.snapCeiling(arr, v); // v = 6
  5558. } else {
  5559. v = Util.snapTo(arr, v); // 四舍五入 5
  5560. }
  5561. var rst = v * factor;
  5562. // 如果出现浮点数计算问题,需要处理一下
  5563. if (Math.abs(factor) < 1 && rst.toString().length > 20) {
  5564. var decimalVal = parseInt(1 / factor);
  5565. var symbol = factor > 0 ? 1 : -1;
  5566. rst = v / decimalVal * symbol;
  5567. }
  5568. return rst;
  5569. },
  5570. // 获取逼近的倍数
  5571. snapMultiple: function snapMultiple(v, base, snapType) {
  5572. var div = void 0;
  5573. if (snapType === 'ceil') {
  5574. div = Math.ceil(v / base);
  5575. } else if (snapType === 'floor') {
  5576. div = Math.floor(v / base);
  5577. } else {
  5578. div = Math.round(v / base);
  5579. }
  5580. return div * base;
  5581. },
  5582. /**
  5583. * 获取逼近的值,用于对齐数据
  5584. * @param {Array} values 数据集合
  5585. * @param {Number} value 数值
  5586. * @return {Number} 逼近的值
  5587. */
  5588. snapTo: function snapTo(values, value) {
  5589. // 这里假定values是升序排列
  5590. var floorVal = arrayFloor(values, value);
  5591. var ceilingVal = arrayCeiling(values, value);
  5592. if (isNaN(floorVal) || isNaN(ceilingVal)) {
  5593. if (values[0] >= value) {
  5594. return values[0];
  5595. }
  5596. var last = values[values.length - 1];
  5597. if (last <= value) {
  5598. return last;
  5599. }
  5600. }
  5601. if (Math.abs(value - floorVal) < Math.abs(ceilingVal - value)) {
  5602. return floorVal;
  5603. }
  5604. return ceilingVal;
  5605. },
  5606. /**
  5607. * 获取逼近的最小值,用于对齐数据
  5608. * @param {Array} values 数据集合
  5609. * @param {Number} value 数值
  5610. * @return {Number} 逼近的最小值
  5611. */
  5612. snapFloor: function snapFloor(values, value) {
  5613. // 这里假定values是升序排列
  5614. return arrayFloor(values, value);
  5615. },
  5616. /**
  5617. * 获取逼近的最大值,用于对齐数据
  5618. * @param {Array} values 数据集合
  5619. * @param {Number} value 数值
  5620. * @return {Number} 逼近的最大值
  5621. */
  5622. snapCeiling: function snapCeiling(values, value) {
  5623. // 这里假定values是升序排列
  5624. return arrayCeiling(values, value);
  5625. }
  5626. };
  5627. module.exports = Util;
  5628. /***/ }),
  5629. /* 44 */
  5630. /***/ (function(module, exports, __webpack_require__) {
  5631. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  5632. function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
  5633. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
  5634. /**
  5635. * @fileOverview The data is replaced with constant
  5636. * @author dxq613@gmail.com
  5637. */
  5638. var Base = __webpack_require__(8);
  5639. var Util = __webpack_require__(0);
  5640. var Identity = function (_Base) {
  5641. _inherits(Identity, _Base);
  5642. function Identity() {
  5643. _classCallCheck(this, Identity);
  5644. return _possibleConstructorReturn(this, _Base.apply(this, arguments));
  5645. }
  5646. Identity.prototype._initDefaultCfg = function _initDefaultCfg() {
  5647. this.isIdentity = true;
  5648. this.type = 'identity';
  5649. /**
  5650. * 输出的值域
  5651. * @type {Array}
  5652. */
  5653. this.range = [0, 1];
  5654. /**
  5655. * 常量值
  5656. * @type {*}
  5657. */
  5658. this.value = null;
  5659. };
  5660. /**
  5661. * @override
  5662. */
  5663. Identity.prototype.getText = function getText() {
  5664. return this.value.toString();
  5665. };
  5666. /**
  5667. * @override
  5668. */
  5669. Identity.prototype.scale = function scale(value) {
  5670. if (this.value !== value && Util.isNumber(value)) {
  5671. return value;
  5672. }
  5673. return this.range[0];
  5674. };
  5675. /**
  5676. * @override
  5677. */
  5678. Identity.prototype.invert = function invert() {
  5679. return this.value;
  5680. };
  5681. return Identity;
  5682. }(Base);
  5683. Base.Identity = Identity;
  5684. module.exports = Identity;
  5685. /***/ }),
  5686. /* 45 */
  5687. /***/ (function(module, exports, __webpack_require__) {
  5688. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  5689. var Util = __webpack_require__(0);
  5690. var Axis = __webpack_require__(46);
  5691. var Global = __webpack_require__(1);
  5692. var _require = __webpack_require__(6),
  5693. Shape = _require.Shape;
  5694. function formatTicks(ticks) {
  5695. var tmp = ticks.slice(0);
  5696. if (tmp.length > 0) {
  5697. var first = tmp[0];
  5698. var last = tmp[tmp.length - 1];
  5699. if (first.value !== 0) {
  5700. tmp.unshift({
  5701. value: 0
  5702. });
  5703. }
  5704. if (last.value !== 1) {
  5705. tmp.push({
  5706. value: 1
  5707. });
  5708. }
  5709. }
  5710. return tmp;
  5711. }
  5712. var AxisController = function () {
  5713. function AxisController(cfg) {
  5714. _classCallCheck(this, AxisController);
  5715. this.axisCfg = {};
  5716. this.frontPlot = null;
  5717. this.backPlot = null;
  5718. this.axes = {}; // 存储各个坐标轴的配置
  5719. Util.mix(this, cfg);
  5720. }
  5721. // 对应的坐标轴是否隐藏
  5722. AxisController.prototype._isHide = function _isHide(field) {
  5723. var axisCfg = this.axisCfg;
  5724. return !axisCfg || axisCfg[field] === false;
  5725. };
  5726. AxisController.prototype._getLinePosition = function _getLinePosition(scale, dimType, index, transposed) {
  5727. var position = '';
  5728. var field = scale.field;
  5729. var axisCfg = this.axisCfg;
  5730. if (axisCfg[field] && axisCfg[field].position) {
  5731. position = axisCfg[field].position;
  5732. } else if (dimType === 'x') {
  5733. position = transposed ? 'left' : 'bottom';
  5734. } else if (dimType === 'y') {
  5735. position = index ? 'right' : 'left';
  5736. if (transposed) {
  5737. position = 'bottom';
  5738. }
  5739. }
  5740. return position;
  5741. };
  5742. AxisController.prototype._getLineCfg = function _getLineCfg(coord, dimType, position) {
  5743. var start = void 0;
  5744. var end = void 0;
  5745. var factor = 1; // 文本的对齐方式,是顺时针方向还是逆时针方向
  5746. if (dimType === 'x') {
  5747. // x 轴的坐标轴,底部的横坐标
  5748. start = {
  5749. x: 0,
  5750. y: 0
  5751. };
  5752. end = {
  5753. x: 1,
  5754. y: 0
  5755. };
  5756. } else {
  5757. // y轴坐标轴
  5758. if (position === 'right') {
  5759. // 多轴的情况
  5760. start = {
  5761. x: 1,
  5762. y: 0
  5763. };
  5764. end = {
  5765. x: 1,
  5766. y: 1
  5767. };
  5768. } else {
  5769. // 单个y轴,或者第一个y轴
  5770. start = {
  5771. x: 0,
  5772. y: 0
  5773. };
  5774. end = {
  5775. x: 0,
  5776. y: 1
  5777. };
  5778. factor = -1;
  5779. }
  5780. }
  5781. if (coord.transposed) {
  5782. factor *= -1;
  5783. }
  5784. return {
  5785. offsetFactor: factor,
  5786. start: coord.convertPoint(start),
  5787. end: coord.convertPoint(end)
  5788. };
  5789. };
  5790. AxisController.prototype._getCircleCfg = function _getCircleCfg(coord) {
  5791. return {
  5792. startAngle: coord.startAngle,
  5793. endAngle: coord.endAngle,
  5794. center: coord.center,
  5795. radius: coord.circleRadius
  5796. };
  5797. };
  5798. AxisController.prototype._getRadiusCfg = function _getRadiusCfg(coord) {
  5799. var transposed = coord.transposed;
  5800. var start = void 0;
  5801. var end = void 0;
  5802. if (transposed) {
  5803. start = { x: 0, y: 0 };
  5804. end = { x: 1, y: 0 };
  5805. } else {
  5806. start = { x: 0, y: 0 };
  5807. end = { x: 0, y: 1 };
  5808. }
  5809. return {
  5810. offsetFactor: -1,
  5811. start: coord.convertPoint(start),
  5812. end: coord.convertPoint(end)
  5813. };
  5814. };
  5815. AxisController.prototype._getAxisCfg = function _getAxisCfg(coord, scale, verticalScale, dimType, defaultCfg) {
  5816. var self = this;
  5817. var axisCfg = this.axisCfg;
  5818. var ticks = scale.getTicks();
  5819. var cfg = Util.deepMix({
  5820. ticks: ticks,
  5821. frontContainer: this.frontPlot,
  5822. backContainer: this.backPlot
  5823. }, defaultCfg, axisCfg[scale.field]);
  5824. var labels = [];
  5825. var label = cfg.label;
  5826. var count = ticks.length;
  5827. var maxWidth = 0;
  5828. var maxHeight = 0;
  5829. var labelCfg = label;
  5830. Util.each(ticks, function (tick, index) {
  5831. if (Util.isFunction(label)) {
  5832. // 文本的配置项动态可配置
  5833. var executedLabel = label(tick.text, index, count);
  5834. if (executedLabel) {
  5835. labelCfg = Util.mix({}, Global._defaultAxis.label, executedLabel);
  5836. } else {
  5837. labelCfg = null;
  5838. }
  5839. }
  5840. if (labelCfg) {
  5841. var textStyle = {};
  5842. if (labelCfg.textAlign) {
  5843. textStyle.textAlign = labelCfg.textAlign;
  5844. }
  5845. if (labelCfg.textBaseline) {
  5846. textStyle.textBaseline = labelCfg.textBaseline;
  5847. }
  5848. var axisLabel = new Shape.Text({
  5849. className: 'axis-label',
  5850. attrs: Util.mix({
  5851. x: 0,
  5852. y: 0,
  5853. text: tick.text,
  5854. fontFamily: self.chart.get('canvas').get('fontFamily') // 保持字体一致
  5855. }, labelCfg),
  5856. value: tick.value,
  5857. textStyle: textStyle,
  5858. top: labelCfg.top,
  5859. context: self.chart.get('canvas').get('context')
  5860. });
  5861. labels.push(axisLabel);
  5862. var _axisLabel$getBBox = axisLabel.getBBox(),
  5863. width = _axisLabel$getBBox.width,
  5864. height = _axisLabel$getBBox.height;
  5865. maxWidth = Math.max(maxWidth, width);
  5866. maxHeight = Math.max(maxHeight, height);
  5867. }
  5868. });
  5869. cfg.labels = labels;
  5870. cfg.maxWidth = maxWidth;
  5871. cfg.maxHeight = maxHeight;
  5872. return cfg;
  5873. };
  5874. AxisController.prototype._createAxis = function _createAxis(coord, scale, verticalScale, dimType) {
  5875. var index = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : '';
  5876. var self = this;
  5877. var coordType = coord.type;
  5878. var transposed = coord.transposed;
  5879. var type = void 0;
  5880. var key = void 0;
  5881. var defaultCfg = void 0;
  5882. if (coordType === 'cartesian' || coordType === 'rect') {
  5883. // 直角坐标系下
  5884. var position = self._getLinePosition(scale, dimType, index, transposed);
  5885. defaultCfg = Global.axis[position];
  5886. defaultCfg.position = position;
  5887. type = 'Line';
  5888. key = position;
  5889. } else {
  5890. // 极坐标系下
  5891. if (dimType === 'x' && !transposed || dimType === 'y' && transposed) {
  5892. // 圆形坐标轴
  5893. defaultCfg = Global.axis.circle;
  5894. type = 'Circle';
  5895. key = 'circle';
  5896. } else {
  5897. // 半径坐标轴
  5898. defaultCfg = Global.axis.radius;
  5899. type = 'Line';
  5900. key = 'radius';
  5901. }
  5902. }
  5903. var cfg = self._getAxisCfg(coord, scale, verticalScale, dimType, defaultCfg); // 坐标轴的配置项
  5904. cfg.type = type;
  5905. cfg.dimType = dimType;
  5906. cfg.verticalScale = verticalScale;
  5907. cfg.index = index;
  5908. this.axes[key] = cfg;
  5909. };
  5910. AxisController.prototype.createAxis = function createAxis(coord, xScale, yScales) {
  5911. var self = this;
  5912. if (xScale && !self._isHide(xScale.field)) {
  5913. self._createAxis(coord, xScale, yScales[0], 'x'); // 绘制 x 轴
  5914. }
  5915. Util.each(yScales, function (yScale, index) {
  5916. if (!self._isHide(yScale.field)) {
  5917. self._createAxis(coord, yScale, xScale, 'y', index);
  5918. }
  5919. });
  5920. var axes = this.axes;
  5921. var chart = self.chart;
  5922. if (chart._isAutoPadding()) {
  5923. // 数据变更时需要重新计算
  5924. var userPadding = Util.parsePadding(chart.get('padding'));
  5925. var appendPadding = Util.parsePadding(chart.get('appendPadding'));
  5926. var legendRange = chart.get('legendRange') || {
  5927. top: 0,
  5928. right: 0,
  5929. bottom: 0,
  5930. left: 0
  5931. };
  5932. var padding = [userPadding[0] === 'auto' ? legendRange.top + appendPadding[0] * 2 : userPadding[0], userPadding[1] === 'auto' ? legendRange.right + appendPadding[1] : userPadding[1], userPadding[2] === 'auto' ? legendRange.bottom + appendPadding[2] : userPadding[2], userPadding[3] === 'auto' ? legendRange.left + appendPadding[3] : userPadding[3]];
  5933. if (coord.isPolar) {
  5934. // 极坐标
  5935. var circleAxis = axes.circle;
  5936. if (circleAxis) {
  5937. var maxHeight = circleAxis.maxHeight,
  5938. maxWidth = circleAxis.maxWidth,
  5939. labelOffset = circleAxis.labelOffset;
  5940. padding[0] += maxHeight + labelOffset;
  5941. padding[1] += maxWidth + labelOffset;
  5942. padding[2] += maxHeight + labelOffset;
  5943. padding[3] += maxWidth + labelOffset;
  5944. }
  5945. } else {
  5946. // 直角坐标系
  5947. if (axes.right && userPadding[1] === 'auto') {
  5948. var _axes$right = axes.right,
  5949. _maxWidth = _axes$right.maxWidth,
  5950. _labelOffset = _axes$right.labelOffset;
  5951. padding[1] += _maxWidth + _labelOffset;
  5952. }
  5953. if (axes.left && userPadding[3] === 'auto') {
  5954. var _axes$left = axes.left,
  5955. _maxWidth2 = _axes$left.maxWidth,
  5956. _labelOffset2 = _axes$left.labelOffset;
  5957. padding[3] += _maxWidth2 + _labelOffset2;
  5958. }
  5959. if (axes.bottom && userPadding[2] === 'auto') {
  5960. var _axes$bottom = axes.bottom,
  5961. _maxHeight = _axes$bottom.maxHeight,
  5962. _labelOffset3 = _axes$bottom.labelOffset;
  5963. padding[2] += _maxHeight + _labelOffset3;
  5964. }
  5965. }
  5966. chart.set('_padding', padding); // 将计算后的 padding 存储在 _padding 属性中
  5967. chart._updateLayout(padding);
  5968. }
  5969. Util.each(axes, function (axis) {
  5970. var type = axis.type,
  5971. grid = axis.grid,
  5972. verticalScale = axis.verticalScale,
  5973. ticks = axis.ticks,
  5974. dimType = axis.dimType,
  5975. position = axis.position,
  5976. index = axis.index;
  5977. var appendCfg = void 0;
  5978. if (coord.isPolar) {
  5979. if (type === 'Line') {
  5980. appendCfg = self._getRadiusCfg(coord);
  5981. } else if (type === 'Circle') {
  5982. appendCfg = self._getCircleCfg(coord);
  5983. }
  5984. } else {
  5985. appendCfg = self._getLineCfg(coord, dimType, position);
  5986. }
  5987. if (grid && verticalScale) {
  5988. var gridPoints = [];
  5989. var verticalTicks = formatTicks(verticalScale.getTicks());
  5990. Util.each(ticks, function (tick) {
  5991. var subPoints = [];
  5992. Util.each(verticalTicks, function (verticalTick) {
  5993. var x = dimType === 'x' ? tick.value : verticalTick.value;
  5994. var y = dimType === 'x' ? verticalTick.value : tick.value;
  5995. var point = coord.convertPoint({
  5996. x: x,
  5997. y: y
  5998. });
  5999. subPoints.push(point);
  6000. });
  6001. gridPoints.push({
  6002. points: subPoints,
  6003. _id: 'axis-' + dimType + index + '-grid-' + tick.tickValue
  6004. });
  6005. });
  6006. axis.gridPoints = gridPoints;
  6007. if (coord.isPolar && grid.type === 'arc') {
  6008. axis.center = coord.center;
  6009. axis.startAngle = coord.startAngle;
  6010. axis.endAngle = coord.endAngle;
  6011. }
  6012. }
  6013. appendCfg._id = 'axis-' + dimType;
  6014. if (!Util.isNil(index)) {
  6015. appendCfg._id = 'axis-' + dimType + index;
  6016. }
  6017. new Axis[type](Util.mix(axis, appendCfg));
  6018. });
  6019. };
  6020. AxisController.prototype.clear = function clear() {
  6021. this.axes = {};
  6022. this.frontPlot.clear();
  6023. this.backPlot.clear();
  6024. };
  6025. return AxisController;
  6026. }();
  6027. module.exports = AxisController;
  6028. /***/ }),
  6029. /* 46 */
  6030. /***/ (function(module, exports, __webpack_require__) {
  6031. var Abstract = __webpack_require__(15);
  6032. // require('./circle');
  6033. __webpack_require__(47);
  6034. module.exports = Abstract;
  6035. /***/ }),
  6036. /* 47 */
  6037. /***/ (function(module, exports, __webpack_require__) {
  6038. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  6039. function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
  6040. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
  6041. var Util = __webpack_require__(0);
  6042. var Abstract = __webpack_require__(15);
  6043. var Line = function (_Abstract) {
  6044. _inherits(Line, _Abstract);
  6045. function Line() {
  6046. _classCallCheck(this, Line);
  6047. return _possibleConstructorReturn(this, _Abstract.apply(this, arguments));
  6048. }
  6049. Line.prototype._initDefaultCfg = function _initDefaultCfg() {
  6050. _Abstract.prototype._initDefaultCfg.call(this);
  6051. this.start = null;
  6052. this.end = null;
  6053. };
  6054. // 获取坐标轴上的点
  6055. Line.prototype.getOffsetPoint = function getOffsetPoint(value) {
  6056. var start = this.start,
  6057. end = this.end;
  6058. return {
  6059. x: start.x + (end.x - start.x) * value,
  6060. y: start.y + (end.y - start.y) * value
  6061. };
  6062. };
  6063. // 获取坐标轴上点的向量,极坐标下覆盖此方法
  6064. Line.prototype.getAxisVector = function getAxisVector() {
  6065. var start = this.start,
  6066. end = this.end;
  6067. return [end.x - start.x, end.y - start.y];
  6068. };
  6069. Line.prototype.drawLine = function drawLine(lineCfg) {
  6070. var container = this.getContainer(lineCfg.top);
  6071. var start = this.start,
  6072. end = this.end;
  6073. container.addShape('line', {
  6074. className: 'axis-line',
  6075. attrs: Util.mix({
  6076. x1: start.x,
  6077. y1: start.y,
  6078. x2: end.x,
  6079. y2: end.y
  6080. }, lineCfg)
  6081. });
  6082. };
  6083. return Line;
  6084. }(Abstract);
  6085. Abstract.Line = Line;
  6086. module.exports = Line;
  6087. /***/ }),
  6088. /* 48 */
  6089. /***/ (function(module, exports, __webpack_require__) {
  6090. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  6091. var Util = __webpack_require__(0);
  6092. var Container = __webpack_require__(18);
  6093. var Group = __webpack_require__(19);
  6094. var Canvas = function () {
  6095. Canvas.prototype.get = function get(name) {
  6096. return this._attrs[name];
  6097. };
  6098. Canvas.prototype.set = function set(name, value) {
  6099. this._attrs[name] = value;
  6100. };
  6101. function Canvas(cfg) {
  6102. _classCallCheck(this, Canvas);
  6103. this._attrs = Util.mix({
  6104. type: 'canvas',
  6105. children: []
  6106. }, cfg);
  6107. this._initPixelRatio();
  6108. this._initCanvas();
  6109. }
  6110. Canvas.prototype._initPixelRatio = function _initPixelRatio() {
  6111. var pixelRatio = this.get('pixelRatio');
  6112. if (!pixelRatio) {
  6113. this.set('pixelRatio', Util.getPixelRatio());
  6114. }
  6115. };
  6116. Canvas.prototype._beforeDraw = function _beforeDraw() {
  6117. var context = this._attrs.context;
  6118. var el = this._attrs.el;
  6119. !Util.isWx && !Util.isMy && context && context.clearRect(0, 0, el.width, el.height);
  6120. };
  6121. Canvas.prototype._initCanvas = function _initCanvas() {
  6122. var self = this;
  6123. var el = self.get('el');
  6124. var context = self.get('context');
  6125. var canvas = void 0;
  6126. if (context) {
  6127. // CanvasRenderingContext2D
  6128. canvas = context.canvas;
  6129. } else if (Util.isString(el)) {
  6130. // HTMLElement's id
  6131. canvas = Util.getDomById(el);
  6132. } else {
  6133. // HTMLElement
  6134. canvas = el;
  6135. }
  6136. if (!canvas) {
  6137. throw new Error('Please specify the id or el of the chart!');
  6138. }
  6139. if (context && canvas && !canvas.getContext) {
  6140. canvas.getContext = function () {
  6141. return context;
  6142. };
  6143. }
  6144. var width = self.get('width');
  6145. if (!width) {
  6146. width = Util.getWidth(canvas);
  6147. }
  6148. var height = self.get('height');
  6149. if (!height) {
  6150. height = Util.getHeight(canvas);
  6151. }
  6152. self.set('canvas', this);
  6153. self.set('el', canvas);
  6154. self.set('context', context || canvas.getContext('2d'));
  6155. self.changeSize(width, height);
  6156. };
  6157. /**
  6158. * 改变 canvas 的宽高
  6159. * @param {Number} width 宽度
  6160. * @param {Number} height 高度
  6161. */
  6162. Canvas.prototype.changeSize = function changeSize(width, height) {
  6163. var pixelRatio = this.get('pixelRatio');
  6164. var canvasDOM = this.get('el');
  6165. if (Util.isBrowser) {
  6166. canvasDOM.style.width = width + 'px';
  6167. canvasDOM.style.height = height + 'px';
  6168. }
  6169. if (!Util.isWx && !Util.isMy) {
  6170. canvasDOM.width = width * pixelRatio;
  6171. canvasDOM.height = height * pixelRatio;
  6172. if (pixelRatio !== 1) {
  6173. var ctx = this.get('context');
  6174. ctx.scale(pixelRatio, pixelRatio);
  6175. }
  6176. }
  6177. this.set('width', width);
  6178. this.set('height', height);
  6179. };
  6180. /**
  6181. * 获取 canvas 对应 dom 元素的宽度
  6182. * @return {Number} 返回宽度
  6183. */
  6184. Canvas.prototype.getWidth = function getWidth() {
  6185. var pixelRatio = this.get('pixelRatio');
  6186. var width = this.get('width');
  6187. return width * pixelRatio;
  6188. };
  6189. /**
  6190. * 获取 canvas 对应 dom 元素的高度
  6191. * @return {Number} 返回高度
  6192. */
  6193. Canvas.prototype.getHeight = function getHeight() {
  6194. var pixelRatio = this.get('pixelRatio');
  6195. var height = this.get('height');
  6196. return height * pixelRatio;
  6197. };
  6198. /**
  6199. * 将窗口坐标转变成 canvas 坐标
  6200. * @param {Number} clientX 窗口x坐标
  6201. * @param {Number} clientY 窗口y坐标
  6202. * @return {Object} canvas坐标
  6203. */
  6204. Canvas.prototype.getPointByClient = function getPointByClient(clientX, clientY) {
  6205. var el = this.get('el');
  6206. var bbox = el.getBoundingClientRect();
  6207. var width = bbox.right - bbox.left;
  6208. var height = bbox.bottom - bbox.top;
  6209. return {
  6210. x: (clientX - bbox.left) * (el.width / width),
  6211. y: (clientY - bbox.top) * (el.height / height)
  6212. };
  6213. };
  6214. Canvas.prototype.draw = function draw() {
  6215. var self = this;
  6216. if (self._attrs.destroyed) {
  6217. return;
  6218. }
  6219. self._beforeDraw();
  6220. try {
  6221. var context = self._attrs.context;
  6222. var children = self._attrs.children;
  6223. for (var i = 0, len = children.length; i < len; i++) {
  6224. var child = children[i];
  6225. child.draw(context);
  6226. }
  6227. if (Util.isWx || Util.isMy) {
  6228. context.draw();
  6229. }
  6230. } catch (ev) {
  6231. // 绘制时异常,中断重绘
  6232. console.warn('error in draw canvas, detail as:');
  6233. console.warn(ev);
  6234. }
  6235. };
  6236. Canvas.prototype.destroy = function destroy() {
  6237. if (this.get('destroyed')) {
  6238. return;
  6239. }
  6240. this.clear();
  6241. this._attrs = {};
  6242. this.set('destroyed', true);
  6243. };
  6244. return Canvas;
  6245. }();
  6246. Util.mix(Canvas.prototype, Container, {
  6247. getGroupClass: function getGroupClass() {
  6248. return Group;
  6249. }
  6250. });
  6251. module.exports = Canvas;
  6252. /***/ }),
  6253. /* 49 */
  6254. /***/ (function(module, exports, __webpack_require__) {
  6255. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  6256. function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
  6257. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
  6258. var Util = __webpack_require__(0);
  6259. var Shape = __webpack_require__(2);
  6260. var Rect = function (_Shape) {
  6261. _inherits(Rect, _Shape);
  6262. function Rect() {
  6263. _classCallCheck(this, Rect);
  6264. return _possibleConstructorReturn(this, _Shape.apply(this, arguments));
  6265. }
  6266. Rect.prototype._initProperties = function _initProperties() {
  6267. _Shape.prototype._initProperties.call(this);
  6268. this._attrs.canFill = true;
  6269. this._attrs.canStroke = true;
  6270. this._attrs.type = 'rect';
  6271. };
  6272. Rect.prototype.getDefaultAttrs = function getDefaultAttrs() {
  6273. return {
  6274. x: 0,
  6275. y: 0,
  6276. width: 0,
  6277. height: 0,
  6278. radius: 0,
  6279. lineWidth: 0
  6280. };
  6281. };
  6282. Rect.prototype.createPath = function createPath(context) {
  6283. var self = this;
  6284. var attrs = self.get('attrs');
  6285. var x = attrs.x,
  6286. y = attrs.y,
  6287. width = attrs.width,
  6288. height = attrs.height;
  6289. context.beginPath();
  6290. var radius = attrs.radius;
  6291. if (!radius || !(width * height)) {
  6292. context.rect(x, y, width, height);
  6293. } else {
  6294. radius = Util.parsePadding(radius);
  6295. context.moveTo(x + radius[0], y);
  6296. context.lineTo(x + width - radius[1], y);
  6297. context.arc(x + width - radius[1], y + radius[1], radius[1], -Math.PI / 2, 0, false);
  6298. context.lineTo(x + width, y + height - radius[2]);
  6299. context.arc(x + width - radius[2], y + height - radius[2], radius[2], 0, Math.PI / 2, false);
  6300. context.lineTo(x + radius[3], y + height);
  6301. context.arc(x + radius[3], y + height - radius[3], radius[3], Math.PI / 2, Math.PI, false);
  6302. context.lineTo(x, y + radius[0]);
  6303. context.arc(x + radius[0], y + radius[0], radius[0], Math.PI, Math.PI * 3 / 2, false);
  6304. context.closePath();
  6305. }
  6306. };
  6307. Rect.prototype.calculateBox = function calculateBox() {
  6308. var attrs = this.get('attrs');
  6309. var x = attrs.x,
  6310. y = attrs.y,
  6311. width = attrs.width,
  6312. height = attrs.height;
  6313. return {
  6314. minX: x,
  6315. minY: y,
  6316. maxX: x + width,
  6317. maxY: y + height
  6318. };
  6319. };
  6320. return Rect;
  6321. }(Shape);
  6322. Shape.Rect = Rect;
  6323. module.exports = Rect;
  6324. /***/ }),
  6325. /* 50 */
  6326. /***/ (function(module, exports, __webpack_require__) {
  6327. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  6328. function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
  6329. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
  6330. var Shape = __webpack_require__(2);
  6331. var Circle = function (_Shape) {
  6332. _inherits(Circle, _Shape);
  6333. function Circle() {
  6334. _classCallCheck(this, Circle);
  6335. return _possibleConstructorReturn(this, _Shape.apply(this, arguments));
  6336. }
  6337. Circle.prototype._initProperties = function _initProperties() {
  6338. _Shape.prototype._initProperties.call(this);
  6339. this._attrs.canFill = true;
  6340. this._attrs.canStroke = true;
  6341. this._attrs.type = 'circle';
  6342. };
  6343. Circle.prototype.getDefaultAttrs = function getDefaultAttrs() {
  6344. return {
  6345. x: 0,
  6346. y: 0,
  6347. r: 0,
  6348. lineWidth: 0
  6349. };
  6350. };
  6351. Circle.prototype.createPath = function createPath(context) {
  6352. var attrs = this.get('attrs');
  6353. var x = attrs.x,
  6354. y = attrs.y,
  6355. r = attrs.r;
  6356. context.beginPath();
  6357. context.arc(x, y, r, 0, Math.PI * 2, false);
  6358. context.closePath();
  6359. };
  6360. Circle.prototype.calculateBox = function calculateBox() {
  6361. var attrs = this.get('attrs');
  6362. var x = attrs.x,
  6363. y = attrs.y,
  6364. r = attrs.r;
  6365. return {
  6366. minX: x - r,
  6367. maxX: x + r,
  6368. minY: y - r,
  6369. maxY: y + r
  6370. };
  6371. };
  6372. return Circle;
  6373. }(Shape);
  6374. Shape.Circle = Circle;
  6375. module.exports = Circle;
  6376. /***/ }),
  6377. /* 51 */
  6378. /***/ (function(module, exports, __webpack_require__) {
  6379. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  6380. function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
  6381. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
  6382. var Shape = __webpack_require__(2);
  6383. var bbox = __webpack_require__(7);
  6384. var Line = function (_Shape) {
  6385. _inherits(Line, _Shape);
  6386. function Line() {
  6387. _classCallCheck(this, Line);
  6388. return _possibleConstructorReturn(this, _Shape.apply(this, arguments));
  6389. }
  6390. Line.prototype._initProperties = function _initProperties() {
  6391. _Shape.prototype._initProperties.call(this);
  6392. this._attrs.canStroke = true;
  6393. this._attrs.type = 'line';
  6394. };
  6395. Line.prototype.getDefaultAttrs = function getDefaultAttrs() {
  6396. return {
  6397. x1: 0,
  6398. y1: 0,
  6399. x2: 0,
  6400. y2: 0,
  6401. lineWidth: 1
  6402. };
  6403. };
  6404. Line.prototype.createPath = function createPath(context) {
  6405. var attrs = this.get('attrs');
  6406. var x1 = attrs.x1,
  6407. y1 = attrs.y1,
  6408. x2 = attrs.x2,
  6409. y2 = attrs.y2;
  6410. context.beginPath();
  6411. context.moveTo(x1, y1);
  6412. context.lineTo(x2, y2);
  6413. };
  6414. Line.prototype.calculateBox = function calculateBox() {
  6415. var attrs = this.get('attrs');
  6416. var x1 = attrs.x1,
  6417. y1 = attrs.y1,
  6418. x2 = attrs.x2,
  6419. y2 = attrs.y2;
  6420. return bbox.getBBoxFromLine(x1, y1, x2, y2);
  6421. };
  6422. return Line;
  6423. }(Shape);
  6424. Shape.Line = Line;
  6425. module.exports = Line;
  6426. /***/ }),
  6427. /* 52 */
  6428. /***/ (function(module, exports, __webpack_require__) {
  6429. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  6430. function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
  6431. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
  6432. var Shape = __webpack_require__(2);
  6433. var bbox = __webpack_require__(7);
  6434. var Polygon = function (_Shape) {
  6435. _inherits(Polygon, _Shape);
  6436. function Polygon() {
  6437. _classCallCheck(this, Polygon);
  6438. return _possibleConstructorReturn(this, _Shape.apply(this, arguments));
  6439. }
  6440. Polygon.prototype._initProperties = function _initProperties() {
  6441. _Shape.prototype._initProperties.call(this);
  6442. this._attrs.canFill = true;
  6443. this._attrs.canStroke = true;
  6444. this._attrs.type = 'polygon';
  6445. };
  6446. Polygon.prototype.getDefaultAttrs = function getDefaultAttrs() {
  6447. return {
  6448. points: null,
  6449. lineWidth: 0
  6450. };
  6451. };
  6452. Polygon.prototype.createPath = function createPath(context) {
  6453. var self = this;
  6454. var attrs = self.get('attrs');
  6455. var points = attrs.points;
  6456. context.beginPath();
  6457. for (var i = 0, len = points.length; i < len; i++) {
  6458. var point = points[i];
  6459. if (i === 0) {
  6460. context.moveTo(point.x, point.y);
  6461. } else {
  6462. context.lineTo(point.x, point.y);
  6463. }
  6464. }
  6465. context.closePath();
  6466. };
  6467. Polygon.prototype.calculateBox = function calculateBox() {
  6468. var attrs = this.get('attrs');
  6469. var points = attrs.points;
  6470. return bbox.getBBoxFromPoints(points);
  6471. };
  6472. return Polygon;
  6473. }(Shape);
  6474. Shape.Polygon = Polygon;
  6475. module.exports = Polygon;
  6476. /***/ }),
  6477. /* 53 */
  6478. /***/ (function(module, exports, __webpack_require__) {
  6479. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  6480. function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
  6481. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
  6482. var Shape = __webpack_require__(2);
  6483. var Smooth = __webpack_require__(23);
  6484. var bbox = __webpack_require__(7);
  6485. var Polyline = function (_Shape) {
  6486. _inherits(Polyline, _Shape);
  6487. function Polyline() {
  6488. _classCallCheck(this, Polyline);
  6489. return _possibleConstructorReturn(this, _Shape.apply(this, arguments));
  6490. }
  6491. Polyline.prototype._initProperties = function _initProperties() {
  6492. _Shape.prototype._initProperties.call(this);
  6493. this._attrs.canFill = true;
  6494. this._attrs.canStroke = true;
  6495. this._attrs.type = 'polyline';
  6496. };
  6497. Polyline.prototype.getDefaultAttrs = function getDefaultAttrs() {
  6498. return {
  6499. points: null,
  6500. lineWidth: 1,
  6501. smooth: false
  6502. };
  6503. };
  6504. Polyline.prototype.createPath = function createPath(context) {
  6505. var self = this;
  6506. var attrs = self.get('attrs');
  6507. var points = attrs.points,
  6508. smooth = attrs.smooth;
  6509. context.beginPath();
  6510. context.moveTo(points[0].x, points[0].y);
  6511. if (smooth) {
  6512. var constaint = [[0, 0], [1, 1]];
  6513. var sps = Smooth.smooth(points, false, constaint);
  6514. for (var i = 0, n = sps.length; i < n; i++) {
  6515. var sp = sps[i];
  6516. context.bezierCurveTo(sp[1], sp[2], sp[3], sp[4], sp[5], sp[6]);
  6517. }
  6518. } else {
  6519. var _i = void 0;
  6520. var l = void 0;
  6521. for (_i = 1, l = points.length - 1; _i < l; _i++) {
  6522. context.lineTo(points[_i].x, points[_i].y);
  6523. }
  6524. context.lineTo(points[l].x, points[l].y);
  6525. }
  6526. };
  6527. Polyline.prototype.calculateBox = function calculateBox() {
  6528. var attrs = this.get('attrs');
  6529. var points = attrs.points,
  6530. smooth = attrs.smooth;
  6531. if (smooth) {
  6532. var newPoints = [];
  6533. var constaint = [[0, 0], [1, 1]];
  6534. var sps = Smooth.smooth(points, false, constaint);
  6535. for (var i = 0, n = sps.length; i < n; i++) {
  6536. var sp = sps[i];
  6537. if (i === 0) {
  6538. newPoints.push([points[0].x, points[0].y, sp[1], sp[2], sp[3], sp[4], sp[5], sp[6]]);
  6539. } else {
  6540. var lastPoint = sps[i - 1];
  6541. newPoints.push([lastPoint[5], lastPoint[6], sp[1], sp[2], sp[3], sp[4], sp[5], sp[6]]);
  6542. }
  6543. }
  6544. return bbox.getBBoxFromBezierGroup(newPoints);
  6545. }
  6546. return bbox.getBBoxFromPoints(points);
  6547. };
  6548. return Polyline;
  6549. }(Shape);
  6550. Shape.Polyline = Polyline;
  6551. module.exports = Polyline;
  6552. /***/ }),
  6553. /* 54 */
  6554. /***/ (function(module, exports, __webpack_require__) {
  6555. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  6556. function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
  6557. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
  6558. var Shape = __webpack_require__(2);
  6559. var bbox = __webpack_require__(7);
  6560. var Arc = function (_Shape) {
  6561. _inherits(Arc, _Shape);
  6562. function Arc() {
  6563. _classCallCheck(this, Arc);
  6564. return _possibleConstructorReturn(this, _Shape.apply(this, arguments));
  6565. }
  6566. Arc.prototype._initProperties = function _initProperties() {
  6567. _Shape.prototype._initProperties.call(this);
  6568. this._attrs.canStroke = true;
  6569. this._attrs.type = 'arc';
  6570. };
  6571. Arc.prototype.getDefaultAttrs = function getDefaultAttrs() {
  6572. return {
  6573. x: 0,
  6574. y: 0,
  6575. r: 0,
  6576. startAngle: 0,
  6577. endAngle: Math.PI * 2,
  6578. clockwise: false,
  6579. lineWidth: 1
  6580. };
  6581. };
  6582. Arc.prototype.createPath = function createPath(context) {
  6583. var attrs = this.get('attrs');
  6584. var x = attrs.x,
  6585. y = attrs.y,
  6586. r = attrs.r,
  6587. startAngle = attrs.startAngle,
  6588. endAngle = attrs.endAngle,
  6589. clockwise = attrs.clockwise;
  6590. context.beginPath();
  6591. context.arc(x, y, r, startAngle, endAngle, clockwise);
  6592. };
  6593. Arc.prototype.calculateBox = function calculateBox() {
  6594. var attrs = this.get('attrs');
  6595. var x = attrs.x,
  6596. y = attrs.y,
  6597. r = attrs.r,
  6598. startAngle = attrs.startAngle,
  6599. endAngle = attrs.endAngle,
  6600. clockwise = attrs.clockwise;
  6601. return bbox.getBBoxFromArc(x, y, r, startAngle, endAngle, clockwise);
  6602. };
  6603. return Arc;
  6604. }(Shape);
  6605. Shape.Arc = Arc;
  6606. module.exports = Arc;
  6607. /***/ }),
  6608. /* 55 */
  6609. /***/ (function(module, exports, __webpack_require__) {
  6610. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  6611. function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
  6612. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
  6613. var Shape = __webpack_require__(2);
  6614. var bbox = __webpack_require__(7);
  6615. var Sector = function (_Shape) {
  6616. _inherits(Sector, _Shape);
  6617. function Sector() {
  6618. _classCallCheck(this, Sector);
  6619. return _possibleConstructorReturn(this, _Shape.apply(this, arguments));
  6620. }
  6621. Sector.prototype._initProperties = function _initProperties() {
  6622. _Shape.prototype._initProperties.call(this);
  6623. this._attrs.canFill = true;
  6624. this._attrs.canStroke = true;
  6625. this._attrs.type = 'sector';
  6626. };
  6627. Sector.prototype.getDefaultAttrs = function getDefaultAttrs() {
  6628. return {
  6629. x: 0,
  6630. y: 0,
  6631. lineWidth: 0,
  6632. r: 0,
  6633. r0: 0,
  6634. startAngle: 0,
  6635. endAngle: Math.PI * 2,
  6636. clockwise: false
  6637. };
  6638. };
  6639. Sector.prototype.createPath = function createPath(context) {
  6640. var attrs = this.get('attrs');
  6641. var x = attrs.x,
  6642. y = attrs.y,
  6643. startAngle = attrs.startAngle,
  6644. endAngle = attrs.endAngle,
  6645. r = attrs.r,
  6646. r0 = attrs.r0,
  6647. clockwise = attrs.clockwise;
  6648. context.beginPath();
  6649. var unitX = Math.cos(startAngle);
  6650. var unitY = Math.sin(startAngle);
  6651. context.moveTo(unitX * r0 + x, unitY * r0 + y);
  6652. context.lineTo(unitX * r + x, unitY * r + y);
  6653. context.arc(x, y, r, startAngle, endAngle, clockwise);
  6654. context.lineTo(Math.cos(endAngle) * r0 + x, Math.sin(endAngle) * r0 + y);
  6655. if (r0 !== 0) {
  6656. context.arc(x, y, r0, endAngle, startAngle, !clockwise);
  6657. }
  6658. context.closePath();
  6659. };
  6660. Sector.prototype.calculateBox = function calculateBox() {
  6661. var attrs = this.get('attrs');
  6662. var x = attrs.x,
  6663. y = attrs.y,
  6664. r = attrs.r,
  6665. r0 = attrs.r0,
  6666. startAngle = attrs.startAngle,
  6667. endAngle = attrs.endAngle,
  6668. clockwise = attrs.clockwise;
  6669. var outerBBox = bbox.getBBoxFromArc(x, y, r, startAngle, endAngle, clockwise);
  6670. var innerBBox = bbox.getBBoxFromArc(x, y, r0, startAngle, endAngle, clockwise);
  6671. return {
  6672. minX: Math.min(outerBBox.minX, innerBBox.minX),
  6673. minY: Math.min(outerBBox.minY, innerBBox.minY),
  6674. maxX: Math.max(outerBBox.maxX, innerBBox.maxX),
  6675. maxY: Math.max(outerBBox.maxY, innerBBox.maxY)
  6676. };
  6677. };
  6678. return Sector;
  6679. }(Shape);
  6680. Shape.Sector = Sector;
  6681. module.exports = Sector;
  6682. /***/ }),
  6683. /* 56 */
  6684. /***/ (function(module, exports, __webpack_require__) {
  6685. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  6686. function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
  6687. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
  6688. var Util = __webpack_require__(0);
  6689. var Shape = __webpack_require__(2);
  6690. var textWidthCacheCounter = 0;
  6691. var textWidthCache = {};
  6692. var TEXT_CACHE_MAX = 5000;
  6693. var Text = function (_Shape) {
  6694. _inherits(Text, _Shape);
  6695. function Text() {
  6696. _classCallCheck(this, Text);
  6697. return _possibleConstructorReturn(this, _Shape.apply(this, arguments));
  6698. }
  6699. Text.prototype._initProperties = function _initProperties() {
  6700. _Shape.prototype._initProperties.call(this);
  6701. this._attrs.canFill = true;
  6702. this._attrs.canStroke = true;
  6703. this._attrs.type = 'text';
  6704. };
  6705. Text.prototype.getDefaultAttrs = function getDefaultAttrs() {
  6706. return {
  6707. lineWidth: 0,
  6708. lineCount: 1,
  6709. fontSize: 12,
  6710. fontFamily: 'sans-serif',
  6711. fontStyle: 'normal',
  6712. fontWeight: 'normal',
  6713. fontVariant: 'normal',
  6714. textAlign: 'start',
  6715. textBaseline: 'bottom',
  6716. lineHeight: null,
  6717. textArr: null
  6718. };
  6719. };
  6720. Text.prototype._getFontStyle = function _getFontStyle() {
  6721. var attrs = this._attrs.attrs;
  6722. var fontSize = attrs.fontSize,
  6723. fontFamily = attrs.fontFamily,
  6724. fontWeight = attrs.fontWeight,
  6725. fontStyle = attrs.fontStyle,
  6726. fontVariant = attrs.fontVariant;
  6727. return fontStyle + ' ' + fontVariant + ' ' + fontWeight + ' ' + fontSize + 'px ' + fontFamily;
  6728. };
  6729. Text.prototype._afterAttrsSet = function _afterAttrsSet() {
  6730. var attrs = this._attrs.attrs;
  6731. attrs.font = this._getFontStyle();
  6732. if (attrs.text) {
  6733. var text = attrs.text;
  6734. var textArr = void 0;
  6735. if (Util.isString(text) && text.indexOf('\n') !== -1) {
  6736. textArr = text.split('\n');
  6737. var lineCount = textArr.length;
  6738. attrs.lineCount = lineCount;
  6739. attrs.textArr = textArr;
  6740. }
  6741. }
  6742. this.set('attrs', attrs);
  6743. };
  6744. Text.prototype._getTextHeight = function _getTextHeight() {
  6745. var attrs = this._attrs.attrs;
  6746. if (attrs.height) {
  6747. return attrs.height;
  6748. }
  6749. var lineCount = attrs.lineCount;
  6750. var fontSize = attrs.fontSize * 1;
  6751. if (lineCount > 1) {
  6752. var spaceingY = this._getSpaceingY();
  6753. return fontSize * lineCount + spaceingY * (lineCount - 1);
  6754. }
  6755. return fontSize;
  6756. };
  6757. Text.prototype._getSpaceingY = function _getSpaceingY() {
  6758. var attrs = this._attrs.attrs;
  6759. var lineHeight = attrs.lineHeight;
  6760. var fontSize = attrs.fontSize * 1;
  6761. return lineHeight ? lineHeight - fontSize : fontSize * 0.14;
  6762. };
  6763. Text.prototype.drawInner = function drawInner(context) {
  6764. var self = this;
  6765. var attrs = self._attrs.attrs;
  6766. var text = attrs.text;
  6767. if (!text) {
  6768. return;
  6769. }
  6770. var textArr = attrs.textArr;
  6771. var fontSize = attrs.fontSize * 1;
  6772. var spaceingY = self._getSpaceingY();
  6773. var x = attrs.x;
  6774. var y = attrs.y;
  6775. if (attrs.rotate) {
  6776. // 文本旋转
  6777. context.translate(x, y);
  6778. context.rotate(attrs.rotate);
  6779. x = 0;
  6780. y = 0;
  6781. }
  6782. var textBaseline = attrs.textBaseline;
  6783. var height = void 0;
  6784. if (textArr) {
  6785. height = self._getTextHeight();
  6786. }
  6787. var subY = void 0;
  6788. // context.beginPath();
  6789. if (self.hasFill()) {
  6790. var fillOpacity = attrs.fillOpacity;
  6791. if (!Util.isNil(fillOpacity) && fillOpacity !== 1) {
  6792. context.globalAlpha = fillOpacity;
  6793. }
  6794. if (textArr) {
  6795. for (var i = 0, len = textArr.length; i < len; i++) {
  6796. var subText = textArr[i];
  6797. subY = y + i * (spaceingY + fontSize) - height + fontSize; // bottom;
  6798. if (textBaseline === 'middle') {
  6799. subY += height - fontSize - (height - fontSize) / 2;
  6800. }
  6801. if (textBaseline === 'top') {
  6802. subY += height - fontSize;
  6803. }
  6804. context.fillText(subText, x, subY);
  6805. }
  6806. } else {
  6807. context.fillText(text, x, y);
  6808. }
  6809. }
  6810. if (self.hasStroke()) {
  6811. if (textArr) {
  6812. for (var _i = 0, _len = textArr.length; _i < _len; _i++) {
  6813. var _subText = textArr[_i];
  6814. subY = y + _i * (spaceingY + fontSize) - height + fontSize; // bottom;
  6815. if (textBaseline === 'middle') {
  6816. subY += height - fontSize - (height - fontSize) / 2;
  6817. }
  6818. if (textBaseline === 'top') {
  6819. subY += height - fontSize;
  6820. }
  6821. context.strokeText(_subText, x, subY);
  6822. }
  6823. } else {
  6824. context.strokeText(text, x, y);
  6825. }
  6826. }
  6827. };
  6828. Text.prototype.calculateBox = function calculateBox() {
  6829. var self = this;
  6830. var attrs = self._attrs.attrs;
  6831. var x = attrs.x,
  6832. y = attrs.y,
  6833. textAlign = attrs.textAlign,
  6834. textBaseline = attrs.textBaseline;
  6835. var width = self._getTextWidth(); // attrs.width
  6836. if (!width) {
  6837. // 如果width不存在,四点共其实点
  6838. return {
  6839. minX: x,
  6840. minY: y,
  6841. maxX: x,
  6842. maxY: y
  6843. };
  6844. }
  6845. var height = self._getTextHeight(); // attrs.height
  6846. var point = {
  6847. x: x,
  6848. y: y - height
  6849. }; // default textAlign: start, textBaseline: bottom
  6850. if (textAlign) {
  6851. if (textAlign === 'end' || textAlign === 'right') {
  6852. point.x -= width;
  6853. } else if (textAlign === 'center') {
  6854. point.x -= width / 2;
  6855. }
  6856. }
  6857. if (textBaseline) {
  6858. if (textBaseline === 'top') {
  6859. point.y += height;
  6860. } else if (textBaseline === 'middle') {
  6861. point.y += height / 2;
  6862. }
  6863. }
  6864. return {
  6865. minX: point.x,
  6866. minY: point.y,
  6867. maxX: point.x + width,
  6868. maxY: point.y + height
  6869. };
  6870. };
  6871. Text.prototype._getTextWidth = function _getTextWidth() {
  6872. var attrs = this._attrs.attrs;
  6873. if (attrs.width) {
  6874. return attrs.width;
  6875. }
  6876. var text = attrs.text;
  6877. var context = this.get('context');
  6878. if (Util.isNil(text)) return undefined;
  6879. var font = attrs.font;
  6880. var textArr = attrs.textArr;
  6881. var key = text + '' + font;
  6882. if (textWidthCache[key]) {
  6883. return textWidthCache[key];
  6884. }
  6885. var width = 0;
  6886. if (textArr) {
  6887. for (var i = 0, length = textArr.length; i < length; i++) {
  6888. var subText = textArr[i];
  6889. width = Math.max(width, Util.measureText(subText, font, context).width);
  6890. }
  6891. } else {
  6892. width = Util.measureText(text, font, context).width;
  6893. }
  6894. if (textWidthCacheCounter > TEXT_CACHE_MAX) {
  6895. textWidthCacheCounter = 0;
  6896. textWidthCache = {};
  6897. }
  6898. textWidthCacheCounter++;
  6899. textWidthCache[key] = width;
  6900. return width;
  6901. };
  6902. return Text;
  6903. }(Shape);
  6904. Shape.Text = Text;
  6905. module.exports = Text;
  6906. /***/ }),
  6907. /* 57 */
  6908. /***/ (function(module, exports, __webpack_require__) {
  6909. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  6910. function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
  6911. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
  6912. var Shape = __webpack_require__(2);
  6913. var Custom = function (_Shape) {
  6914. _inherits(Custom, _Shape);
  6915. function Custom() {
  6916. _classCallCheck(this, Custom);
  6917. return _possibleConstructorReturn(this, _Shape.apply(this, arguments));
  6918. }
  6919. Custom.prototype._initProperties = function _initProperties() {
  6920. _Shape.prototype._initProperties.call(this);
  6921. this._attrs.canFill = true;
  6922. this._attrs.canStroke = true;
  6923. this._attrs.createPath = null;
  6924. this._attrs.type = 'custom';
  6925. };
  6926. Custom.prototype.createPath = function createPath(context) {
  6927. var createPath = this.get('createPath');
  6928. createPath && createPath.call(this, context);
  6929. };
  6930. Custom.prototype.calculateBox = function calculateBox() {
  6931. var calculateBox = this.get('calculateBox');
  6932. return calculateBox && calculateBox.call(this);
  6933. };
  6934. return Custom;
  6935. }(Shape);
  6936. Shape.Custom = Custom;
  6937. module.exports = Custom;
  6938. /***/ }),
  6939. /* 58 */
  6940. /***/ (function(module, exports, __webpack_require__) {
  6941. /**
  6942. * @fileOverview track f2
  6943. * @author sima.zhang1990@gmail.com
  6944. */
  6945. var Global = __webpack_require__(1);
  6946. var Util = __webpack_require__(0);
  6947. var SERVER_URL = 'https://kcart.alipay.com/web/bi.do';
  6948. // 延迟发送请求
  6949. setTimeout(function () {
  6950. if (Global.trackable && Util.isBrowser) {
  6951. // 只对 h5 环境下进行统计
  6952. var image = new Image();
  6953. var newObj = {
  6954. pg: document.URL,
  6955. r: new Date().getTime(),
  6956. f2: true,
  6957. version: Global.version,
  6958. page_type: 'syslog'
  6959. };
  6960. var d = encodeURIComponent(JSON.stringify([newObj]));
  6961. image.src = SERVER_URL + '?BIProfile=merge&d=' + d;
  6962. }
  6963. }, 3000);
  6964. /***/ }),
  6965. /* 59 */
  6966. /***/ (function(module, exports, __webpack_require__) {
  6967. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  6968. function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
  6969. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
  6970. var Path = __webpack_require__(25);
  6971. var Geom = __webpack_require__(4);
  6972. __webpack_require__(20);
  6973. var Line = function (_Path) {
  6974. _inherits(Line, _Path);
  6975. function Line() {
  6976. _classCallCheck(this, Line);
  6977. return _possibleConstructorReturn(this, _Path.apply(this, arguments));
  6978. }
  6979. /**
  6980. * 获取默认的配置属性
  6981. * @protected
  6982. * @return {Object} 默认属性
  6983. */
  6984. Line.prototype.getDefaultCfg = function getDefaultCfg() {
  6985. var cfg = _Path.prototype.getDefaultCfg.call(this);
  6986. cfg.type = 'line';
  6987. cfg.sortable = true;
  6988. return cfg;
  6989. };
  6990. return Line;
  6991. }(Path);
  6992. Geom.Line = Line;
  6993. module.exports = Line;
  6994. /***/ }),
  6995. /* 60 */
  6996. /***/ (function(module, exports, __webpack_require__) {
  6997. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  6998. function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
  6999. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
  7000. var Geom = __webpack_require__(4);
  7001. var Util = __webpack_require__(0);
  7002. var SizeMixin = __webpack_require__(26);
  7003. __webpack_require__(61);
  7004. var Interval = function (_Geom) {
  7005. _inherits(Interval, _Geom);
  7006. /**
  7007. * 获取默认的配置属性
  7008. * @protected
  7009. * @return {Object} 默认属性
  7010. */
  7011. Interval.prototype.getDefaultCfg = function getDefaultCfg() {
  7012. var cfg = _Geom.prototype.getDefaultCfg.call(this);
  7013. cfg.type = 'interval';
  7014. cfg.shapeType = 'interval';
  7015. cfg.generatePoints = true;
  7016. return cfg;
  7017. };
  7018. function Interval(cfg) {
  7019. _classCallCheck(this, Interval);
  7020. var _this = _possibleConstructorReturn(this, _Geom.call(this, cfg));
  7021. Util.mix(_this, SizeMixin);
  7022. return _this;
  7023. }
  7024. Interval.prototype.createShapePointsCfg = function createShapePointsCfg(obj) {
  7025. var cfg = _Geom.prototype.createShapePointsCfg.call(this, obj);
  7026. cfg.size = this.getNormalizedSize(obj);
  7027. return cfg;
  7028. };
  7029. Interval.prototype.clearInner = function clearInner() {
  7030. _Geom.prototype.clearInner.call(this);
  7031. this.set('defaultSize', null);
  7032. };
  7033. return Interval;
  7034. }(Geom);
  7035. Geom.Interval = Interval;
  7036. module.exports = Interval;
  7037. /***/ }),
  7038. /* 61 */
  7039. /***/ (function(module, exports, __webpack_require__) {
  7040. var Util = __webpack_require__(0);
  7041. var Shape = __webpack_require__(5);
  7042. var Vector2 = __webpack_require__(3);
  7043. var Global = __webpack_require__(1);
  7044. function getRectPoints(cfg) {
  7045. var x = cfg.x,
  7046. y = cfg.y,
  7047. y0 = cfg.y0,
  7048. size = cfg.size;
  7049. // 有3种情况,
  7050. // 1. y,x都不是数组
  7051. // 2. y是数组,x不是
  7052. // 3. x是数组,y不是
  7053. var ymin = y0;
  7054. var ymax = y;
  7055. if (Util.isArray(y)) {
  7056. ymax = y[1];
  7057. ymin = y[0];
  7058. }
  7059. var xmin = void 0;
  7060. var xmax = void 0;
  7061. if (Util.isArray(x)) {
  7062. xmin = x[0];
  7063. xmax = x[1];
  7064. } else {
  7065. xmin = x - size / 2;
  7066. xmax = x + size / 2;
  7067. }
  7068. return [{ x: xmin, y: ymin }, { x: xmin, y: ymax }, { x: xmax, y: ymax }, { x: xmax, y: ymin }];
  7069. }
  7070. function getRectRange(points) {
  7071. var xValues = [];
  7072. var yValues = [];
  7073. for (var i = 0, len = points.length; i < len; i++) {
  7074. var point = points[i];
  7075. xValues.push(point.x);
  7076. yValues.push(point.y);
  7077. }
  7078. var xMin = Math.min.apply(null, xValues);
  7079. var yMin = Math.min.apply(null, yValues);
  7080. var xMax = Math.max.apply(null, xValues);
  7081. var yMax = Math.max.apply(null, yValues);
  7082. return {
  7083. x: xMin,
  7084. y: yMin,
  7085. width: xMax - xMin,
  7086. height: yMax - yMin
  7087. };
  7088. }
  7089. var Interval = Shape.registerFactory('interval', {
  7090. defaultShapeType: 'rect',
  7091. getDefaultPoints: function getDefaultPoints(cfg) {
  7092. return getRectPoints(cfg);
  7093. }
  7094. });
  7095. Shape.registerShape('interval', 'rect', {
  7096. draw: function draw(cfg, container) {
  7097. var points = this.parsePoints(cfg.points);
  7098. var style = Util.mix({
  7099. fill: cfg.color
  7100. }, Global.shape.interval, cfg.style);
  7101. if (cfg.isInCircle) {
  7102. var newPoints = points.slice(0);
  7103. if (this._coord.transposed) {
  7104. newPoints = [points[0], points[3], points[2], points[1]];
  7105. }
  7106. var _cfg$center = cfg.center,
  7107. x = _cfg$center.x,
  7108. y = _cfg$center.y;
  7109. var v = [1, 0];
  7110. var v0 = [newPoints[0].x - x, newPoints[0].y - y];
  7111. var v1 = [newPoints[1].x - x, newPoints[1].y - y];
  7112. var v2 = [newPoints[2].x - x, newPoints[2].y - y];
  7113. var startAngle = Vector2.angleTo(v, v1);
  7114. var endAngle = Vector2.angleTo(v, v2);
  7115. var r0 = Vector2.length(v0);
  7116. var r = Vector2.length(v1);
  7117. if (startAngle >= 1.5 * Math.PI) {
  7118. startAngle = startAngle - 2 * Math.PI;
  7119. }
  7120. if (endAngle >= 1.5 * Math.PI) {
  7121. endAngle = endAngle - 2 * Math.PI;
  7122. }
  7123. return container.addShape('Sector', {
  7124. className: 'interval',
  7125. attrs: Util.mix({
  7126. x: x,
  7127. y: y,
  7128. r: r,
  7129. r0: r0,
  7130. startAngle: startAngle,
  7131. endAngle: endAngle
  7132. }, style)
  7133. });
  7134. }
  7135. var rectCfg = getRectRange(points);
  7136. return container.addShape('rect', {
  7137. className: 'interval',
  7138. attrs: Util.mix(rectCfg, style)
  7139. });
  7140. }
  7141. });
  7142. module.exports = Interval;
  7143. /***/ }),
  7144. /* 62 */
  7145. /***/ (function(module, exports, __webpack_require__) {
  7146. var Adjust = __webpack_require__(11);
  7147. __webpack_require__(63);
  7148. __webpack_require__(64);
  7149. module.exports = Adjust;
  7150. /***/ }),
  7151. /* 63 */
  7152. /***/ (function(module, exports, __webpack_require__) {
  7153. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  7154. function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
  7155. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
  7156. /**
  7157. * @fileOverview 数据分组
  7158. * @author dxq613@gmail.com
  7159. */
  7160. var Util = __webpack_require__(0);
  7161. var Adjust = __webpack_require__(11);
  7162. var Global = __webpack_require__(1);
  7163. var Dodge = function (_Adjust) {
  7164. _inherits(Dodge, _Adjust);
  7165. function Dodge() {
  7166. _classCallCheck(this, Dodge);
  7167. return _possibleConstructorReturn(this, _Adjust.apply(this, arguments));
  7168. }
  7169. Dodge.prototype._initDefaultCfg = function _initDefaultCfg() {
  7170. /**
  7171. * 调整过程中,2个数据的间距
  7172. * @type {Number}
  7173. */
  7174. this.marginRatio = Global.widthRatio.dodgeMargin;
  7175. /**
  7176. * 调整占单位宽度的比例,例如:占2个分类间距的 1/2
  7177. * @type {Number}
  7178. */
  7179. this.dodgeRatio = Global.widthRatio.column;
  7180. };
  7181. Dodge.prototype.getDodgeOffset = function getDodgeOffset(range, index, count) {
  7182. var self = this;
  7183. var pre = range.pre;
  7184. var next = range.next;
  7185. var tickLength = next - pre;
  7186. var width = tickLength * self.dodgeRatio / count;
  7187. var margin = self.marginRatio * width;
  7188. var offset = 1 / 2 * (tickLength - count * width - (count - 1) * margin) + ((index + 1) * width + index * margin) - 1 / 2 * width - 1 / 2 * tickLength;
  7189. return (pre + next) / 2 + offset;
  7190. };
  7191. Dodge.prototype.processAdjust = function processAdjust(dataArray) {
  7192. var self = this;
  7193. var count = dataArray.length;
  7194. var xField = self.xField;
  7195. Util.each(dataArray, function (data, index) {
  7196. for (var i = 0, len = data.length; i < len; i++) {
  7197. var obj = data[i];
  7198. var value = obj[xField];
  7199. var range = {
  7200. pre: value - 0.5,
  7201. next: value + 0.5
  7202. };
  7203. var dodgeValue = self.getDodgeOffset(range, index, count);
  7204. obj[xField] = dodgeValue;
  7205. }
  7206. });
  7207. };
  7208. return Dodge;
  7209. }(Adjust);
  7210. Adjust.Dodge = Dodge;
  7211. module.exports = Dodge;
  7212. /***/ }),
  7213. /* 64 */
  7214. /***/ (function(module, exports, __webpack_require__) {
  7215. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  7216. function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
  7217. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
  7218. /**
  7219. * @fileOverview Stack data
  7220. * @author dxq613@gmail.com
  7221. */
  7222. var Util = __webpack_require__(0);
  7223. var Adjust = __webpack_require__(11);
  7224. var Stack = function (_Adjust) {
  7225. _inherits(Stack, _Adjust);
  7226. function Stack() {
  7227. _classCallCheck(this, Stack);
  7228. return _possibleConstructorReturn(this, _Adjust.apply(this, arguments));
  7229. }
  7230. Stack.prototype._initDefaultCfg = function _initDefaultCfg() {
  7231. this.xField = null;
  7232. this.yField = null;
  7233. };
  7234. Stack.prototype.processAdjust = function processAdjust(dataArray) {
  7235. var self = this;
  7236. var xField = self.xField;
  7237. var yField = self.yField;
  7238. var count = dataArray.length;
  7239. var stackCache = {
  7240. positive: {},
  7241. negative: {}
  7242. };
  7243. for (var i = 0; i < count; i++) {
  7244. var data = dataArray[i];
  7245. for (var j = 0, len = data.length; j < len; j++) {
  7246. var item = data[j];
  7247. var x = item[xField];
  7248. var y = item[yField];
  7249. var xkey = x.toString();
  7250. y = Util.isArray(y) ? y[1] : y;
  7251. if (!Util.isNil(y)) {
  7252. var direction = y >= 0 ? 'positive' : 'negative';
  7253. if (!stackCache[direction][xkey]) {
  7254. stackCache[direction][xkey] = 0;
  7255. }
  7256. item[yField] = [stackCache[direction][xkey], y + stackCache[direction][xkey]];
  7257. stackCache[direction][xkey] += y;
  7258. }
  7259. }
  7260. }
  7261. };
  7262. return Stack;
  7263. }(Adjust);
  7264. Adjust.Stack = Stack;
  7265. module.exports = Stack;
  7266. /***/ }),
  7267. /* 65 */
  7268. /***/ (function(module, exports, __webpack_require__) {
  7269. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  7270. function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
  7271. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
  7272. var Base = __webpack_require__(13);
  7273. var Vector2 = __webpack_require__(3);
  7274. var Matrix = __webpack_require__(14);
  7275. var Polar = function (_Base) {
  7276. _inherits(Polar, _Base);
  7277. function Polar() {
  7278. _classCallCheck(this, Polar);
  7279. return _possibleConstructorReturn(this, _Base.apply(this, arguments));
  7280. }
  7281. Polar.prototype._initDefaultCfg = function _initDefaultCfg() {
  7282. this.type = 'polar';
  7283. this.startAngle = -Math.PI / 2;
  7284. this.endAngle = Math.PI * 3 / 2;
  7285. this.inner = 0;
  7286. this.innerRadius = 0; // alias
  7287. this.isPolar = true;
  7288. this.transposed = false;
  7289. this.center = null;
  7290. this.radius = null; // 相对半径
  7291. };
  7292. Polar.prototype.init = function init(start, end) {
  7293. var self = this;
  7294. var inner = self.inner || self.innerRadius;
  7295. var width = Math.abs(end.x - start.x);
  7296. var height = Math.abs(end.y - start.y);
  7297. var maxRadius = void 0;
  7298. var center = void 0;
  7299. if (self.startAngle === -Math.PI && self.endAngle === 0) {
  7300. maxRadius = Math.min(width / 2, height);
  7301. center = {
  7302. x: (start.x + end.x) / 2,
  7303. y: start.y
  7304. };
  7305. } else {
  7306. maxRadius = Math.min(width, height) / 2;
  7307. center = {
  7308. x: (start.x + end.x) / 2,
  7309. y: (start.y + end.y) / 2
  7310. };
  7311. }
  7312. var radius = self.radius; // 相对半径
  7313. if (radius > 0 && radius <= 1) {
  7314. maxRadius = maxRadius * radius;
  7315. }
  7316. this.x = {
  7317. start: self.startAngle,
  7318. end: self.endAngle
  7319. };
  7320. this.y = {
  7321. start: maxRadius * inner,
  7322. end: maxRadius
  7323. };
  7324. this.center = center;
  7325. this.circleRadius = maxRadius; // 绝对半径
  7326. };
  7327. Polar.prototype.convertPoint = function convertPoint(point) {
  7328. var self = this;
  7329. var center = self.center;
  7330. var transposed = self.transposed;
  7331. var xDim = transposed ? 'y' : 'x';
  7332. var yDim = transposed ? 'x' : 'y';
  7333. var x = self.x;
  7334. var y = self.y;
  7335. var angle = x.start + (x.end - x.start) * point[xDim];
  7336. var radius = y.start + (y.end - y.start) * point[yDim];
  7337. return {
  7338. x: center.x + Math.cos(angle) * radius,
  7339. y: center.y + Math.sin(angle) * radius
  7340. };
  7341. };
  7342. Polar.prototype.invertPoint = function invertPoint(point) {
  7343. var self = this;
  7344. var center = self.center,
  7345. transposed = self.transposed,
  7346. x = self.x,
  7347. y = self.y;
  7348. var xDim = transposed ? 'y' : 'x';
  7349. var yDim = transposed ? 'x' : 'y';
  7350. var m = [1, 0, 0, 1, 0, 0];
  7351. Matrix.rotate(m, m, x.start);
  7352. var startV = [1, 0];
  7353. Vector2.transformMat2d(startV, startV, m);
  7354. startV = [startV[0], startV[1]];
  7355. var pointV = [point.x - center.x, point.y - center.y];
  7356. if (Vector2.zero(pointV)) {
  7357. return {
  7358. x: 0,
  7359. y: 0
  7360. };
  7361. }
  7362. var theta = Vector2.angleTo(startV, pointV, x.end < x.start);
  7363. if (Math.abs(theta - Math.PI * 2) < 0.001) {
  7364. theta = 0;
  7365. }
  7366. var l = Vector2.length(pointV);
  7367. var percentX = theta / (x.end - x.start);
  7368. percentX = x.end - x.start > 0 ? percentX : -percentX;
  7369. var percentY = (l - y.start) / (y.end - y.start);
  7370. var rst = {};
  7371. rst[xDim] = percentX;
  7372. rst[yDim] = percentY;
  7373. return rst;
  7374. };
  7375. return Polar;
  7376. }(Base);
  7377. Base.Polar = Polar;
  7378. module.exports = Polar;
  7379. /***/ }),
  7380. /* 66 */
  7381. /***/ (function(module, exports, __webpack_require__) {
  7382. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  7383. function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
  7384. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
  7385. /**
  7386. * 一些小的图标,用于 tooltip 和 legend 的 marker
  7387. * @type {Object}
  7388. */
  7389. var Util = __webpack_require__(0);
  7390. var _require = __webpack_require__(6),
  7391. Shape = _require.Shape;
  7392. var SYMBOLS = {
  7393. // 圆
  7394. circle: function circle(x, y, r, ctx) {
  7395. ctx.arc(x, y, r, 0, Math.PI * 2, false);
  7396. },
  7397. // 正方形
  7398. square: function square(x, y, r, ctx) {
  7399. ctx.moveTo(x - r, y - r);
  7400. ctx.lineTo(x + r, y - r);
  7401. ctx.lineTo(x + r, y + r);
  7402. ctx.lineTo(x - r, y + r);
  7403. ctx.closePath();
  7404. }
  7405. };
  7406. var Marker = function (_Shape) {
  7407. _inherits(Marker, _Shape);
  7408. function Marker() {
  7409. _classCallCheck(this, Marker);
  7410. return _possibleConstructorReturn(this, _Shape.apply(this, arguments));
  7411. }
  7412. Marker.prototype._initProperties = function _initProperties() {
  7413. _Shape.prototype._initProperties.call(this);
  7414. this._attrs.canFill = true;
  7415. this._attrs.canStroke = true;
  7416. this._attrs.type = 'marker';
  7417. };
  7418. Marker.prototype.getDefaultAttrs = function getDefaultAttrs() {
  7419. return {
  7420. x: 0,
  7421. y: 0,
  7422. lineWidth: 0
  7423. };
  7424. };
  7425. Marker.prototype.createPath = function createPath(context) {
  7426. var attrs = this.get('attrs');
  7427. var x = attrs.x,
  7428. y = attrs.y,
  7429. radius = attrs.radius;
  7430. var symbol = attrs.symbol || 'circle';
  7431. var method = void 0;
  7432. if (Util.isFunction(symbol)) {
  7433. method = symbol;
  7434. } else {
  7435. method = SYMBOLS[symbol];
  7436. }
  7437. context.beginPath();
  7438. method(x, y, radius, context, this);
  7439. };
  7440. Marker.prototype.calculateBox = function calculateBox() {
  7441. var attrs = this.get('attrs');
  7442. var x = attrs.x,
  7443. y = attrs.y,
  7444. radius = attrs.radius;
  7445. return {
  7446. minX: x - radius,
  7447. minY: y - radius,
  7448. maxX: x + radius,
  7449. maxY: y + radius
  7450. };
  7451. };
  7452. return Marker;
  7453. }(Shape);
  7454. module.exports = Marker;
  7455. /***/ }),
  7456. /* 67 */
  7457. /***/ (function(module, exports, __webpack_require__) {
  7458. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  7459. var Util = __webpack_require__(0);
  7460. var _require = __webpack_require__(6),
  7461. Group = _require.Group;
  7462. var Marker = __webpack_require__(66);
  7463. var MARKER_RADIUS = 3;
  7464. var List = function () {
  7465. List.prototype.getDefaultCfg = function getDefaultCfg() {
  7466. return {
  7467. showTitle: false,
  7468. /**
  7469. * 标题文本
  7470. * @type {?String}
  7471. */
  7472. title: null,
  7473. /**
  7474. * 记录项的集合
  7475. * @type {?Array}
  7476. */
  7477. items: null,
  7478. /**
  7479. * 标题距离记录项的间距
  7480. * @type {Number}
  7481. */
  7482. titleGap: 12,
  7483. /**
  7484. * 各个记录项水平方向的间距
  7485. * @type {Number}
  7486. */
  7487. itemGap: 10,
  7488. /**
  7489. * 各个记录项水平方向的间距
  7490. * @type {Number}
  7491. */
  7492. itemMarginBottom: 12,
  7493. /**
  7494. * 记录项文本格式化
  7495. * @type {[type]}
  7496. */
  7497. itemFormatter: null,
  7498. itemWidth: null,
  7499. /**
  7500. * marker 和文字的距离
  7501. * @type {Number}
  7502. */
  7503. wordSpace: 6,
  7504. /**
  7505. * 在画布上的位置
  7506. * @type {[type]}
  7507. */
  7508. x: 0,
  7509. /**
  7510. * 在画布上的位置
  7511. * @type {[type]}
  7512. */
  7513. y: 0,
  7514. /**
  7515. * 布局方式
  7516. * @type {String}
  7517. */
  7518. layout: 'horizontal',
  7519. /**
  7520. * name 和 value 的连接字符串
  7521. * @type {String}
  7522. */
  7523. joinString: ': '
  7524. };
  7525. };
  7526. function List(cfg) {
  7527. _classCallCheck(this, List);
  7528. Util.deepMix(this, this.getDefaultCfg(), cfg);
  7529. this._init();
  7530. this._renderTitle();
  7531. this._renderItems();
  7532. }
  7533. List.prototype._init = function _init() {
  7534. var container = new Group({
  7535. zIndex: this.zIndex || 0
  7536. });
  7537. this.container = container;
  7538. var wrapper = container.addGroup();
  7539. this.wrapper = wrapper;
  7540. var itemsGroup = wrapper.addGroup({
  7541. className: 'itemsGroup'
  7542. });
  7543. this.itemsGroup = itemsGroup;
  7544. if (this.parent) {
  7545. // 如果传入了父容器
  7546. this.parent.add(container);
  7547. }
  7548. };
  7549. List.prototype._renderTitle = function _renderTitle(title) {
  7550. title = title || this.title;
  7551. var titleHeight = 0;
  7552. if (this.showTitle && title) {
  7553. var wrapper = this.wrapper,
  7554. titleStyle = this.titleStyle;
  7555. var titleShape = wrapper.addShape('text', {
  7556. className: 'title',
  7557. attrs: Util.mix({
  7558. x: 0,
  7559. y: 0,
  7560. text: title
  7561. }, titleStyle)
  7562. });
  7563. titleHeight = titleShape.getBBox().height + this.titleGap;
  7564. this.titleShape = titleShape;
  7565. }
  7566. this._titleHeight = titleHeight;
  7567. };
  7568. List.prototype._renderItems = function _renderItems(items) {
  7569. var self = this;
  7570. items = items || self.items;
  7571. if (!items) {
  7572. return;
  7573. }
  7574. if (self.reversed) {
  7575. items.reverse();
  7576. }
  7577. Util.each(items, function (item, index) {
  7578. self._addItem(item, index);
  7579. });
  7580. if (items.length > 1) {
  7581. this._adjustItems();
  7582. }
  7583. this._renderBackground(); // 渲染背景
  7584. };
  7585. List.prototype._renderBackground = function _renderBackground() {
  7586. var background = this.background;
  7587. if (background) {
  7588. var container = this.container;
  7589. var wrapper = this.wrapper;
  7590. var _wrapper$getBBox = wrapper.getBBox(),
  7591. minX = _wrapper$getBBox.minX,
  7592. minY = _wrapper$getBBox.minY,
  7593. width = _wrapper$getBBox.width,
  7594. height = _wrapper$getBBox.height;
  7595. var padding = background.padding || [0, 0, 0, 0];
  7596. padding = Util.parsePadding(padding);
  7597. var attrs = Util.mix({
  7598. x: minX - padding[3],
  7599. y: minY - padding[0],
  7600. width: width + padding[1] + padding[3],
  7601. height: height + padding[0] + padding[2]
  7602. }, background);
  7603. var backShape = this.backShape;
  7604. if (backShape) {
  7605. backShape.attr(attrs);
  7606. } else {
  7607. backShape = container.addShape('Rect', {
  7608. zIndex: -1,
  7609. attrs: attrs
  7610. });
  7611. }
  7612. this.backShape = backShape;
  7613. container.sort();
  7614. }
  7615. };
  7616. List.prototype._addItem = function _addItem(item) {
  7617. var itemsGroup = this.itemsGroup;
  7618. var itemGroup = itemsGroup.addGroup({
  7619. name: item.name,
  7620. value: item.value, // 显示的内容
  7621. dataValue: item.dataValue, // 图例项对应原始数据中的数值
  7622. checked: item.checked
  7623. });
  7624. var unCheckStyle = this.unCheckStyle,
  7625. unCheckColor = this.unCheckColor,
  7626. nameStyle = this.nameStyle,
  7627. valueStyle = this.valueStyle,
  7628. wordSpace = this.wordSpace;
  7629. var marker = item.marker,
  7630. value = item.value;
  7631. var startX = 0;
  7632. if (unCheckColor) {
  7633. // unCheckColor 属性兼容,建议使用 unCheckStyle
  7634. unCheckStyle.fill = unCheckColor;
  7635. }
  7636. if (marker) {
  7637. // 如果有 marker 添加 marker, 格式: { radius, symbol, fill / stroke }
  7638. var radius = marker.radius || MARKER_RADIUS;
  7639. var markerAttrs = Util.mix({
  7640. x: radius,
  7641. y: this._titleHeight
  7642. }, marker);
  7643. if (item.checked === false) {
  7644. Util.mix(markerAttrs, unCheckStyle);
  7645. }
  7646. var markerShape = new Marker({
  7647. className: 'item-marker',
  7648. attrs: markerAttrs
  7649. });
  7650. itemGroup.add(markerShape);
  7651. startX += markerShape.getBBox().width + wordSpace;
  7652. }
  7653. var nameText = void 0;
  7654. var name = item.name;
  7655. if (name) {
  7656. var joinString = this.joinString || '';
  7657. name = value ? name + joinString : name;
  7658. nameText = itemGroup.addShape('text', {
  7659. className: 'name',
  7660. attrs: Util.mix({
  7661. x: startX,
  7662. y: this._titleHeight,
  7663. text: this._formatItemValue(name)
  7664. }, nameStyle, item.checked === false ? unCheckStyle : null)
  7665. });
  7666. }
  7667. if (value) {
  7668. var valueX = startX;
  7669. if (nameText) {
  7670. valueX += nameText.getBBox().width;
  7671. }
  7672. itemGroup.addShape('text', {
  7673. className: 'value',
  7674. attrs: Util.mix({
  7675. x: valueX,
  7676. y: this._titleHeight,
  7677. text: value
  7678. }, valueStyle, item.checked === false ? unCheckStyle : null)
  7679. });
  7680. }
  7681. return itemGroup;
  7682. };
  7683. List.prototype._formatItemValue = function _formatItemValue(value) {
  7684. var formatter = this.itemFormatter;
  7685. if (formatter) {
  7686. value = formatter.call(this, value);
  7687. }
  7688. return value;
  7689. };
  7690. List.prototype._getMaxItemWidth = function _getMaxItemWidth() {
  7691. var width = void 0;
  7692. var itemWidth = this.itemWidth;
  7693. if (Util.isNumber(itemWidth) || Util.isNil(itemWidth)) {
  7694. return itemWidth;
  7695. }
  7696. // 采用默认的栅栏布局
  7697. if (itemWidth === 'auto') {
  7698. var itemsGroup = this.itemsGroup;
  7699. var children = itemsGroup.get('children');
  7700. var count = children.length;
  7701. var maxItemWidth = 0;
  7702. for (var i = 0; i < count; i++) {
  7703. var _children$i$getBBox = children[i].getBBox(),
  7704. _width = _children$i$getBBox.width;
  7705. maxItemWidth = Math.max(maxItemWidth, _width);
  7706. }
  7707. var maxLength = this.maxLength;
  7708. var itemGap = this.itemGap;
  7709. var twoAvgWidth = (maxLength - itemGap) / 2;
  7710. var threeAvgWidth = (maxLength - itemGap * 2) / 3;
  7711. if (count === 2) {
  7712. width = Math.max(maxItemWidth, twoAvgWidth);
  7713. } else {
  7714. // 1. max <= 3Avg, 3Avg
  7715. // 2. 3Avg < max && max < 2avg, 2avg
  7716. // 3. max > 2avg, max, 一列布局
  7717. if (maxItemWidth <= threeAvgWidth) {
  7718. width = threeAvgWidth;
  7719. } else if (maxItemWidth <= twoAvgWidth) {
  7720. width = twoAvgWidth;
  7721. } else {
  7722. width = maxItemWidth;
  7723. }
  7724. }
  7725. return width;
  7726. }
  7727. };
  7728. List.prototype._adjustHorizontal = function _adjustHorizontal() {
  7729. var maxLength = this.maxLength,
  7730. itemsGroup = this.itemsGroup;
  7731. var children = itemsGroup.get('children');
  7732. var itemGap = this.itemGap,
  7733. itemMarginBottom = this.itemMarginBottom;
  7734. var titleHeight = this._titleHeight;
  7735. var row = 0;
  7736. var rowWidth = 0;
  7737. var width = void 0;
  7738. var height = void 0;
  7739. var itemWidth = this._getMaxItemWidth();
  7740. var legendHitBoxes = [];
  7741. for (var i = 0, len = children.length; i < len; i++) {
  7742. var child = children[i];
  7743. var box = child.getBBox();
  7744. var childHeight = box.height;
  7745. var childWidth = box.width;
  7746. width = itemWidth || childWidth;
  7747. height = childHeight + itemMarginBottom;
  7748. if (width - (maxLength - rowWidth) > 0.0001) {
  7749. row++;
  7750. rowWidth = 0;
  7751. }
  7752. child.moveTo(rowWidth, row * height);
  7753. legendHitBoxes.push({
  7754. x: rowWidth,
  7755. y: row * height + titleHeight - childHeight / 2,
  7756. width: childWidth * 1.375,
  7757. height: childHeight * 1.375
  7758. });
  7759. rowWidth += width + itemGap;
  7760. }
  7761. this.legendHitBoxes = legendHitBoxes;
  7762. return;
  7763. };
  7764. List.prototype._adjustVertical = function _adjustVertical() {
  7765. var maxLength = this.maxLength,
  7766. itemsGroup = this.itemsGroup; // 垂直布局,则 maxLength 代表容器的高度
  7767. var itemGap = this.itemGap,
  7768. itemMarginBottom = this.itemMarginBottom,
  7769. itemWidth = this.itemWidth;
  7770. var titleHeight = this._titleHeight;
  7771. var children = itemsGroup.get('children');
  7772. var colHeight = 0;
  7773. var width = void 0;
  7774. var height = void 0;
  7775. var maxItemWidth = 0;
  7776. var totalWidth = 0;
  7777. var legendHitBoxes = [];
  7778. for (var i = 0, length = children.length; i < length; i++) {
  7779. var child = children[i];
  7780. var bbox = child.getBBox();
  7781. width = bbox.width;
  7782. height = bbox.height;
  7783. if (Util.isNumber(itemWidth)) {
  7784. maxItemWidth = itemWidth + itemGap;
  7785. } else if (width > maxItemWidth) {
  7786. maxItemWidth = width + itemGap;
  7787. }
  7788. if (maxLength - colHeight < height) {
  7789. colHeight = 0;
  7790. totalWidth += maxItemWidth;
  7791. child.moveTo(totalWidth, 0);
  7792. legendHitBoxes.push({
  7793. x: totalWidth,
  7794. y: titleHeight - height / 2,
  7795. width: width * 1.375,
  7796. height: height * 1.375
  7797. });
  7798. } else {
  7799. child.moveTo(totalWidth, colHeight);
  7800. legendHitBoxes.push({
  7801. x: totalWidth,
  7802. y: colHeight - height / 2 + titleHeight,
  7803. width: width * 1.375,
  7804. height: height * 1.375
  7805. });
  7806. }
  7807. colHeight += height + itemMarginBottom;
  7808. }
  7809. this.legendHitBoxes = legendHitBoxes;
  7810. return;
  7811. };
  7812. List.prototype._adjustItems = function _adjustItems() {
  7813. var layout = this.layout;
  7814. if (layout === 'horizontal') {
  7815. this._adjustHorizontal();
  7816. } else {
  7817. this._adjustVertical();
  7818. }
  7819. };
  7820. List.prototype.moveTo = function moveTo(x, y) {
  7821. this.x = x;
  7822. this.y = y;
  7823. var container = this.container;
  7824. container && container.moveTo(x, y);
  7825. return this;
  7826. };
  7827. List.prototype.setItems = function setItems(items) {
  7828. this.clearItems();
  7829. this._renderItems(items);
  7830. };
  7831. List.prototype.setTitle = function setTitle(title) {
  7832. var titleShape = this.titleShape;
  7833. if (titleShape) {
  7834. titleShape.attr('text', title);
  7835. } else {
  7836. this._renderTitle(title);
  7837. }
  7838. };
  7839. List.prototype.clearItems = function clearItems() {
  7840. var itemsGroup = this.itemsGroup;
  7841. itemsGroup.clear();
  7842. };
  7843. List.prototype.getWidth = function getWidth() {
  7844. var container = this.container;
  7845. var bbox = container.getBBox();
  7846. return bbox.width;
  7847. };
  7848. List.prototype.getHeight = function getHeight() {
  7849. var container = this.container;
  7850. var bbox = container.getBBox();
  7851. return bbox.height;
  7852. };
  7853. List.prototype.show = function show() {
  7854. var container = this.container;
  7855. container.show();
  7856. };
  7857. List.prototype.hide = function hide() {
  7858. var container = this.container;
  7859. container.hide();
  7860. };
  7861. List.prototype.clear = function clear() {
  7862. var container = this.container;
  7863. container.clear();
  7864. container.remove(true);
  7865. };
  7866. return List;
  7867. }();
  7868. module.exports = List;
  7869. /***/ }),
  7870. /* 68 */
  7871. /***/ (function(module, exports, __webpack_require__) {
  7872. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  7873. function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
  7874. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
  7875. var Util = __webpack_require__(0);
  7876. var Geom = __webpack_require__(4);
  7877. __webpack_require__(69);
  7878. var Point = function (_Geom) {
  7879. _inherits(Point, _Geom);
  7880. function Point() {
  7881. _classCallCheck(this, Point);
  7882. return _possibleConstructorReturn(this, _Geom.apply(this, arguments));
  7883. }
  7884. Point.prototype.getDefaultCfg = function getDefaultCfg() {
  7885. var cfg = _Geom.prototype.getDefaultCfg.call(this);
  7886. cfg.type = 'point';
  7887. cfg.shapeType = 'point';
  7888. cfg.generatePoints = true;
  7889. return cfg;
  7890. };
  7891. Point.prototype.draw = function draw(data, shapeFactory) {
  7892. var self = this;
  7893. var container = self.get('container');
  7894. Util.each(data, function (obj) {
  7895. var shape = obj.shape;
  7896. var cfg = self.getDrawCfg(obj);
  7897. if (Util.isArray(obj.y)) {
  7898. var hasStack = self.hasAdjust('stack'); // 判断是否存在 stack 层叠
  7899. Util.each(obj.y, function (y, idx) {
  7900. cfg.y = y;
  7901. if (!hasStack || idx !== 0) {
  7902. self.drawShape(shape, obj, cfg, container, shapeFactory);
  7903. }
  7904. });
  7905. } else if (!Util.isNil(obj.y)) {
  7906. self.drawShape(shape, obj, cfg, container, shapeFactory);
  7907. }
  7908. });
  7909. };
  7910. return Point;
  7911. }(Geom);
  7912. Geom.Point = Point;
  7913. module.exports = Point;
  7914. /***/ }),
  7915. /* 69 */
  7916. /***/ (function(module, exports, __webpack_require__) {
  7917. var Util = __webpack_require__(0);
  7918. var Global = __webpack_require__(1);
  7919. var ShapeUtil = __webpack_require__(12);
  7920. var Shape = __webpack_require__(5);
  7921. var SHAPES = ['circle', 'hollowCircle', 'rect'];
  7922. var Point = Shape.registerFactory('point', {
  7923. defaultShapeType: 'circle',
  7924. getDefaultPoints: function getDefaultPoints(pointInfo) {
  7925. return ShapeUtil.splitPoints(pointInfo);
  7926. }
  7927. });
  7928. function getPointsCfg(cfg) {
  7929. var style = {
  7930. lineWidth: 0,
  7931. stroke: cfg.color,
  7932. fill: cfg.color
  7933. };
  7934. if (cfg.size) {
  7935. style.size = cfg.size;
  7936. }
  7937. Util.mix(style, cfg.style);
  7938. return Util.mix({}, Global.shape.point, style);
  7939. }
  7940. function drawShape(cfg, container, shape) {
  7941. if (cfg.size === 0) return;
  7942. var pointCfg = getPointsCfg(cfg);
  7943. var size = pointCfg.r || pointCfg.size;
  7944. var x = cfg.x;
  7945. var y = !Util.isArray(cfg.y) ? [cfg.y] : cfg.y;
  7946. if (shape === 'hollowCircle') {
  7947. pointCfg.lineWidth = 1;
  7948. pointCfg.fill = null;
  7949. }
  7950. for (var i = 0, len = y.length; i < len; i++) {
  7951. if (shape === 'rect') {
  7952. return container.addShape('Rect', {
  7953. className: 'point',
  7954. attrs: Util.mix({
  7955. x: x - size,
  7956. y: y[i] - size,
  7957. width: size * 2,
  7958. height: size * 2
  7959. }, pointCfg)
  7960. });
  7961. }
  7962. return container.addShape('Circle', {
  7963. className: 'point',
  7964. attrs: Util.mix({
  7965. x: x,
  7966. y: y[i],
  7967. r: size
  7968. }, pointCfg)
  7969. });
  7970. }
  7971. }
  7972. Util.each(SHAPES, function (shapeType) {
  7973. Shape.registerShape('point', shapeType, {
  7974. draw: function draw(cfg, container) {
  7975. return drawShape(cfg, container, shapeType);
  7976. }
  7977. });
  7978. });
  7979. module.exports = Point;
  7980. /***/ }),
  7981. /* 70 */
  7982. /***/ (function(module, exports, __webpack_require__) {
  7983. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  7984. function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
  7985. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
  7986. /**
  7987. * @fileOverview 面积图
  7988. * @author dxq613 @gmail.com
  7989. * @author sima.zhang1990@gmail.com
  7990. */
  7991. var Geom = __webpack_require__(4);
  7992. var ShapeUtil = __webpack_require__(12);
  7993. var Util = __webpack_require__(0);
  7994. __webpack_require__(71);
  7995. var Area = function (_Geom) {
  7996. _inherits(Area, _Geom);
  7997. function Area() {
  7998. _classCallCheck(this, Area);
  7999. return _possibleConstructorReturn(this, _Geom.apply(this, arguments));
  8000. }
  8001. /**
  8002. * 获取默认的配置属性
  8003. * @protected
  8004. * @return {Object} 默认属性
  8005. */
  8006. Area.prototype.getDefaultCfg = function getDefaultCfg() {
  8007. var cfg = _Geom.prototype.getDefaultCfg.call(this);
  8008. cfg.type = 'area';
  8009. cfg.shapeType = 'area';
  8010. cfg.generatePoints = true;
  8011. cfg.sortable = true;
  8012. return cfg;
  8013. };
  8014. Area.prototype.draw = function draw(data, shapeFactory) {
  8015. var self = this;
  8016. var container = self.get('container');
  8017. var cfg = this.getDrawCfg(data[0]);
  8018. var yScale = self.getYScale();
  8019. var connectNulls = self.get('connectNulls');
  8020. var splitArray = ShapeUtil.splitArray(data, yScale.field, connectNulls);
  8021. cfg.origin = data; // path,line,area 等图的origin 是整个序列
  8022. Util.each(splitArray, function (subData, splitedIndex) {
  8023. cfg.splitedIndex = splitedIndex; // 传入分割片段索引 用于生成id
  8024. var points = subData.map(function (obj) {
  8025. return obj.points;
  8026. });
  8027. cfg.points = points;
  8028. self.drawShape(cfg.shape, data[0], cfg, container, shapeFactory);
  8029. });
  8030. };
  8031. return Area;
  8032. }(Geom);
  8033. Geom.Area = Area;
  8034. module.exports = Area;
  8035. /***/ }),
  8036. /* 71 */
  8037. /***/ (function(module, exports, __webpack_require__) {
  8038. var Util = __webpack_require__(0);
  8039. var Shape = __webpack_require__(5);
  8040. var Smooth = __webpack_require__(23);
  8041. var Global = __webpack_require__(1);
  8042. // 是否相等
  8043. function equals(v1, v2) {
  8044. return Math.abs(v1 - v2) < 0.00001;
  8045. }
  8046. // 是否等于圆心的点
  8047. function equalsCenter(points, center) {
  8048. var eqls = true;
  8049. Util.each(points, function (point) {
  8050. if (!equals(point.x, center.x) || !equals(point.y, center.y)) {
  8051. eqls = false;
  8052. return false;
  8053. }
  8054. });
  8055. return eqls;
  8056. }
  8057. function drawRectShape(topPoints, bottomPoints, container, style, isSmooth) {
  8058. var shape = void 0;
  8059. var points = topPoints.concat(bottomPoints);
  8060. if (isSmooth) {
  8061. shape = container.addShape('Custom', {
  8062. className: 'area',
  8063. attrs: Util.mix({
  8064. points: points
  8065. }, style),
  8066. createPath: function createPath(context) {
  8067. var constaint = [// 范围
  8068. [0, 0], [1, 1]];
  8069. var points = this._attrs.attrs.points;
  8070. var pointsLen = points.length;
  8071. var topPoints = points.slice(0, pointsLen / 2);
  8072. var bottomPoints = points.slice(pointsLen / 2, pointsLen);
  8073. var topSps = Smooth.smooth(topPoints, false, constaint);
  8074. context.beginPath();
  8075. context.moveTo(topPoints[0].x, topPoints[0].y);
  8076. for (var i = 0, n = topSps.length; i < n; i++) {
  8077. var sp = topSps[i];
  8078. context.bezierCurveTo(sp[1], sp[2], sp[3], sp[4], sp[5], sp[6]);
  8079. }
  8080. if (bottomPoints.length) {
  8081. var bottomSps = Smooth.smooth(bottomPoints, false, constaint);
  8082. context.lineTo(bottomPoints[0].x, bottomPoints[0].y);
  8083. for (var _i = 0, _n = bottomSps.length; _i < _n; _i++) {
  8084. var _sp = bottomSps[_i];
  8085. context.bezierCurveTo(_sp[1], _sp[2], _sp[3], _sp[4], _sp[5], _sp[6]);
  8086. }
  8087. }
  8088. context.closePath();
  8089. }
  8090. });
  8091. } else {
  8092. shape = container.addShape('Polyline', {
  8093. className: 'area',
  8094. attrs: Util.mix({
  8095. points: points
  8096. }, style)
  8097. });
  8098. }
  8099. return shape;
  8100. }
  8101. function drawShape(cfg, container, isSmooth) {
  8102. var self = this;
  8103. var points = cfg.points;
  8104. var topPoints = []; // 区域图上面的点
  8105. var bottomPoints = []; // 区域图下面的点
  8106. Util.each(points, function (point) {
  8107. bottomPoints.push(point[0]);
  8108. topPoints.push(point[1]);
  8109. });
  8110. var style = Util.mix({
  8111. fillStyle: cfg.color
  8112. }, Global.shape.area, cfg.style);
  8113. bottomPoints.reverse(); // 下面
  8114. topPoints = self.parsePoints(topPoints);
  8115. bottomPoints = self.parsePoints(bottomPoints);
  8116. if (cfg.isInCircle) {
  8117. topPoints.push(topPoints[0]); // 闭合路径
  8118. bottomPoints.unshift(bottomPoints[bottomPoints.length - 1]); // 闭合路径
  8119. if (equalsCenter(bottomPoints, cfg.center)) {
  8120. // 如果内部点等于圆心,不绘制
  8121. bottomPoints = [];
  8122. }
  8123. }
  8124. return drawRectShape(topPoints, bottomPoints, container, style, isSmooth);
  8125. }
  8126. var Area = Shape.registerFactory('area', {
  8127. defaultShapeType: 'area',
  8128. // 如果存在多个点,分割成单个的点, 不考虑多个x对应一个y的情况
  8129. getDefaultPoints: function getDefaultPoints(obj) {
  8130. var x = obj.x;
  8131. var y = obj.y;
  8132. var y0 = obj.y0; // 最小值
  8133. y = Util.isArray(y) ? y : [y0, y];
  8134. var points = [];
  8135. points.push({
  8136. x: x,
  8137. y: y[0]
  8138. }, {
  8139. x: x,
  8140. y: y[1]
  8141. });
  8142. return points;
  8143. }
  8144. });
  8145. var SHAPES = ['area', 'smooth'];
  8146. Util.each(SHAPES, function (shapeType) {
  8147. Shape.registerShape('area', shapeType, {
  8148. draw: function draw(cfg, container) {
  8149. var smooth = shapeType === 'smooth';
  8150. return drawShape.call(this, cfg, container, smooth);
  8151. }
  8152. });
  8153. });
  8154. module.exports = Area;
  8155. /***/ }),
  8156. /* 72 */
  8157. /***/ (function(module, exports, __webpack_require__) {
  8158. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  8159. function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
  8160. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
  8161. var Util = __webpack_require__(0);
  8162. var Abstract = __webpack_require__(15);
  8163. var Circle = function (_Abstract) {
  8164. _inherits(Circle, _Abstract);
  8165. function Circle() {
  8166. _classCallCheck(this, Circle);
  8167. return _possibleConstructorReturn(this, _Abstract.apply(this, arguments));
  8168. }
  8169. Circle.prototype._initDefaultCfg = function _initDefaultCfg() {
  8170. _Abstract.prototype._initDefaultCfg.call(this);
  8171. this.startAngle = -Math.PI / 2; // 起始角度,弧度
  8172. this.endAngle = Math.PI * 3 / 2; // 结束角度,弧度
  8173. this.radius = null; // 半径
  8174. this.center = null; // 圆心
  8175. };
  8176. // 获取坐标轴上的点
  8177. Circle.prototype.getOffsetPoint = function getOffsetPoint(value) {
  8178. var startAngle = this.startAngle,
  8179. endAngle = this.endAngle;
  8180. var angle = startAngle + (endAngle - startAngle) * value;
  8181. return this._getCirclePoint(angle);
  8182. };
  8183. // 获取圆上的点
  8184. Circle.prototype._getCirclePoint = function _getCirclePoint(angle, radius) {
  8185. var self = this;
  8186. var center = self.center;
  8187. radius = radius || self.radius;
  8188. return {
  8189. x: center.x + Math.cos(angle) * radius,
  8190. y: center.y + Math.sin(angle) * radius
  8191. };
  8192. };
  8193. Circle.prototype.getTextAlignInfo = function getTextAlignInfo(point, offset) {
  8194. var self = this;
  8195. var offsetVector = self.getOffsetVector(point, offset);
  8196. var align = void 0;
  8197. var baseLine = 'middle';
  8198. if (offsetVector[0] > 0) {
  8199. align = 'left';
  8200. } else if (offsetVector[0] < 0) {
  8201. align = 'right';
  8202. } else {
  8203. align = 'center';
  8204. if (offsetVector[1] > 0) {
  8205. baseLine = 'top';
  8206. } else if (offsetVector[1] < 0) {
  8207. baseLine = 'bottom';
  8208. }
  8209. }
  8210. return {
  8211. textAlign: align,
  8212. textBaseline: baseLine
  8213. };
  8214. };
  8215. // 获取坐标轴上点的向量,极坐标下覆盖此方法
  8216. Circle.prototype.getAxisVector = function getAxisVector(point) {
  8217. var center = this.center;
  8218. var factor = this.offsetFactor;
  8219. return [(point.y - center.y) * factor, (point.x - center.x) * -1 * factor];
  8220. };
  8221. Circle.prototype.drawLine = function drawLine(lineCfg) {
  8222. var center = this.center,
  8223. radius = this.radius,
  8224. startAngle = this.startAngle,
  8225. endAngle = this.endAngle;
  8226. var container = this.getContainer(lineCfg.top);
  8227. container.addShape('arc', {
  8228. className: 'axis-line',
  8229. attrs: Util.mix({
  8230. x: center.x,
  8231. y: center.y,
  8232. r: radius,
  8233. startAngle: startAngle,
  8234. endAngle: endAngle
  8235. }, lineCfg)
  8236. });
  8237. };
  8238. return Circle;
  8239. }(Abstract);
  8240. Abstract.Circle = Circle;
  8241. module.exports = Circle;
  8242. /***/ }),
  8243. /* 73 */
  8244. /***/ (function(module, exports, __webpack_require__) {
  8245. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  8246. function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
  8247. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
  8248. /**
  8249. * @fileOverview 时间数据作为分类类型
  8250. * @author dxq613@gmail.com
  8251. */
  8252. var Base = __webpack_require__(8);
  8253. var Category = __webpack_require__(21);
  8254. var Util = __webpack_require__(0);
  8255. var fecha = __webpack_require__(74);
  8256. var catAuto = __webpack_require__(22);
  8257. /**
  8258. * 度量的构造函数
  8259. * @class Scale.TimeCategory
  8260. */
  8261. var TimeCategory = function (_Category) {
  8262. _inherits(TimeCategory, _Category);
  8263. function TimeCategory() {
  8264. _classCallCheck(this, TimeCategory);
  8265. return _possibleConstructorReturn(this, _Category.apply(this, arguments));
  8266. }
  8267. TimeCategory.prototype._initDefaultCfg = function _initDefaultCfg() {
  8268. this.type = 'timeCat';
  8269. /**
  8270. * 是否需要排序,默认进行排序
  8271. * @type {Boolean}
  8272. */
  8273. this.sortable = true;
  8274. this.tickCount = 5;
  8275. /**
  8276. * 时间格式化
  8277. * @type {String}
  8278. */
  8279. this.mask = 'YYYY-MM-DD';
  8280. /**
  8281. * 输出的值域
  8282. * @type {Array}
  8283. */
  8284. this.range = [0, 1];
  8285. /**
  8286. * 度量的标记
  8287. * @type {Array}
  8288. */
  8289. this.ticks = null;
  8290. /**
  8291. * 参与度量计算的值,可选项
  8292. * @type {Array}
  8293. */
  8294. this.values = [];
  8295. /**
  8296. * 是否分类度量
  8297. * @type {Boolean}
  8298. */
  8299. this.isCategory = true;
  8300. };
  8301. TimeCategory.prototype.init = function init() {
  8302. var self = this;
  8303. var values = this.values;
  8304. // 针对时间分类类型,会将时间统一转换为时间戳
  8305. Util.each(values, function (v, i) {
  8306. values[i] = self._toTimeStamp(v);
  8307. });
  8308. if (this.sortable) {
  8309. // 允许排序
  8310. values.sort(function (v1, v2) {
  8311. return v1 - v2;
  8312. });
  8313. }
  8314. if (!self.ticks) {
  8315. self.ticks = this.calculateTicks(false);
  8316. }
  8317. };
  8318. /**
  8319. * 计算 ticks
  8320. * @return {array} 返回 ticks 数组
  8321. */
  8322. TimeCategory.prototype.calculateTicks = function calculateTicks() /* formated */{
  8323. var self = this;
  8324. var count = self.tickCount;
  8325. var temp = catAuto({
  8326. maxCount: count,
  8327. data: self.values
  8328. });
  8329. var ticks = temp.ticks;
  8330. // if (formated) {
  8331. // Util.each(ticks, function(value, index) {
  8332. // ticks[index] = fecha.format(value, self.mask);
  8333. // });
  8334. // }
  8335. return ticks;
  8336. };
  8337. /**
  8338. * @override
  8339. */
  8340. TimeCategory.prototype.translate = function translate(value) {
  8341. value = this._toTimeStamp(value);
  8342. var index = this.values.indexOf(value);
  8343. if (index === -1) {
  8344. if (Util.isNumber(value) && value < this.values.length) {
  8345. index = value;
  8346. } else {
  8347. index = NaN;
  8348. }
  8349. }
  8350. return index;
  8351. };
  8352. /**
  8353. * @override
  8354. */
  8355. TimeCategory.prototype.scale = function scale(value) {
  8356. var rangeMin = this.rangeMin();
  8357. var rangeMax = this.rangeMax();
  8358. var index = this.translate(value);
  8359. var percent = void 0;
  8360. if (this.values.length === 1) {
  8361. percent = index;
  8362. } else if (index > -1) {
  8363. percent = index / (this.values.length - 1);
  8364. } else {
  8365. percent = 0;
  8366. }
  8367. return rangeMin + percent * (rangeMax - rangeMin);
  8368. };
  8369. /**
  8370. * @override
  8371. */
  8372. TimeCategory.prototype.getText = function getText(value) {
  8373. var result = '';
  8374. var index = this.translate(value);
  8375. if (index > -1) {
  8376. result = this.values[index];
  8377. } else {
  8378. result = value;
  8379. }
  8380. var formatter = this.formatter;
  8381. result = parseInt(result, 10);
  8382. result = formatter ? formatter(result) : fecha.format(result, this.mask);
  8383. return result;
  8384. };
  8385. /**
  8386. * @override
  8387. */
  8388. TimeCategory.prototype.getTicks = function getTicks() {
  8389. var self = this;
  8390. var ticks = this.ticks;
  8391. var rst = [];
  8392. Util.each(ticks, function (tick) {
  8393. var obj = void 0;
  8394. if (Util.isObject(tick)) {
  8395. obj = tick;
  8396. } else {
  8397. obj = {
  8398. text: Util.isString(tick) ? tick : self.getText(tick),
  8399. value: self.scale(tick)
  8400. };
  8401. }
  8402. rst.push(obj);
  8403. });
  8404. return rst;
  8405. };
  8406. // 将时间转换为时间戳
  8407. TimeCategory.prototype._toTimeStamp = function _toTimeStamp(value) {
  8408. if (Util.isString(value)) {
  8409. if (value.indexOf('T') > 0) {
  8410. value = new Date(value).getTime();
  8411. } else {
  8412. value = new Date(value.replace(/-/ig, '/')).getTime();
  8413. }
  8414. }
  8415. if (Util.isDate(value)) {
  8416. value = value.getTime();
  8417. }
  8418. return value;
  8419. };
  8420. return TimeCategory;
  8421. }(Category);
  8422. Base.TimeCat = TimeCategory;
  8423. module.exports = TimeCategory;
  8424. /***/ }),
  8425. /* 74 */
  8426. /***/ (function(module, exports, __webpack_require__) {
  8427. var __WEBPACK_AMD_DEFINE_RESULT__;(function (main) {
  8428. 'use strict';
  8429. /**
  8430. * Parse or format dates
  8431. * @class fecha
  8432. */
  8433. var fecha = {};
  8434. var token = /d{1,4}|M{1,4}|YY(?:YY)?|S{1,3}|Do|ZZ|([HhMsDm])\1?|[aA]|"[^"]*"|'[^']*'/g;
  8435. var twoDigits = /\d\d?/;
  8436. var threeDigits = /\d{3}/;
  8437. var fourDigits = /\d{4}/;
  8438. var word = /[0-9]*['a-z\u00A0-\u05FF\u0700-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]+|[\u0600-\u06FF\/]+(\s*?[\u0600-\u06FF]+){1,2}/i;
  8439. var literal = /\[([^]*?)\]/gm;
  8440. var noop = function noop() {};
  8441. function shorten(arr, sLen) {
  8442. var newArr = [];
  8443. for (var i = 0, len = arr.length; i < len; i++) {
  8444. newArr.push(arr[i].substr(0, sLen));
  8445. }
  8446. return newArr;
  8447. }
  8448. function monthUpdate(arrName) {
  8449. return function (d, v, i18n) {
  8450. var index = i18n[arrName].indexOf(v.charAt(0).toUpperCase() + v.substr(1).toLowerCase());
  8451. if (~index) {
  8452. d.month = index;
  8453. }
  8454. };
  8455. }
  8456. function pad(val, len) {
  8457. val = String(val);
  8458. len = len || 2;
  8459. while (val.length < len) {
  8460. val = '0' + val;
  8461. }
  8462. return val;
  8463. }
  8464. var dayNames = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'];
  8465. var monthNames = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
  8466. var monthNamesShort = shorten(monthNames, 3);
  8467. var dayNamesShort = shorten(dayNames, 3);
  8468. fecha.i18n = {
  8469. dayNamesShort: dayNamesShort,
  8470. dayNames: dayNames,
  8471. monthNamesShort: monthNamesShort,
  8472. monthNames: monthNames,
  8473. amPm: ['am', 'pm'],
  8474. DoFn: function DoFn(D) {
  8475. return D + ['th', 'st', 'nd', 'rd'][D % 10 > 3 ? 0 : (D - D % 10 !== 10) * D % 10];
  8476. }
  8477. };
  8478. var formatFlags = {
  8479. D: function D(dateObj) {
  8480. return dateObj.getDate();
  8481. },
  8482. DD: function DD(dateObj) {
  8483. return pad(dateObj.getDate());
  8484. },
  8485. Do: function Do(dateObj, i18n) {
  8486. return i18n.DoFn(dateObj.getDate());
  8487. },
  8488. d: function d(dateObj) {
  8489. return dateObj.getDay();
  8490. },
  8491. dd: function dd(dateObj) {
  8492. return pad(dateObj.getDay());
  8493. },
  8494. ddd: function ddd(dateObj, i18n) {
  8495. return i18n.dayNamesShort[dateObj.getDay()];
  8496. },
  8497. dddd: function dddd(dateObj, i18n) {
  8498. return i18n.dayNames[dateObj.getDay()];
  8499. },
  8500. M: function M(dateObj) {
  8501. return dateObj.getMonth() + 1;
  8502. },
  8503. MM: function MM(dateObj) {
  8504. return pad(dateObj.getMonth() + 1);
  8505. },
  8506. MMM: function MMM(dateObj, i18n) {
  8507. return i18n.monthNamesShort[dateObj.getMonth()];
  8508. },
  8509. MMMM: function MMMM(dateObj, i18n) {
  8510. return i18n.monthNames[dateObj.getMonth()];
  8511. },
  8512. YY: function YY(dateObj) {
  8513. return String(dateObj.getFullYear()).substr(2);
  8514. },
  8515. YYYY: function YYYY(dateObj) {
  8516. return pad(dateObj.getFullYear(), 4);
  8517. },
  8518. h: function h(dateObj) {
  8519. return dateObj.getHours() % 12 || 12;
  8520. },
  8521. hh: function hh(dateObj) {
  8522. return pad(dateObj.getHours() % 12 || 12);
  8523. },
  8524. H: function H(dateObj) {
  8525. return dateObj.getHours();
  8526. },
  8527. HH: function HH(dateObj) {
  8528. return pad(dateObj.getHours());
  8529. },
  8530. m: function m(dateObj) {
  8531. return dateObj.getMinutes();
  8532. },
  8533. mm: function mm(dateObj) {
  8534. return pad(dateObj.getMinutes());
  8535. },
  8536. s: function s(dateObj) {
  8537. return dateObj.getSeconds();
  8538. },
  8539. ss: function ss(dateObj) {
  8540. return pad(dateObj.getSeconds());
  8541. },
  8542. S: function S(dateObj) {
  8543. return Math.round(dateObj.getMilliseconds() / 100);
  8544. },
  8545. SS: function SS(dateObj) {
  8546. return pad(Math.round(dateObj.getMilliseconds() / 10), 2);
  8547. },
  8548. SSS: function SSS(dateObj) {
  8549. return pad(dateObj.getMilliseconds(), 3);
  8550. },
  8551. a: function a(dateObj, i18n) {
  8552. return dateObj.getHours() < 12 ? i18n.amPm[0] : i18n.amPm[1];
  8553. },
  8554. A: function A(dateObj, i18n) {
  8555. return dateObj.getHours() < 12 ? i18n.amPm[0].toUpperCase() : i18n.amPm[1].toUpperCase();
  8556. },
  8557. ZZ: function ZZ(dateObj) {
  8558. var o = dateObj.getTimezoneOffset();
  8559. return (o > 0 ? '-' : '+') + pad(Math.floor(Math.abs(o) / 60) * 100 + Math.abs(o) % 60, 4);
  8560. }
  8561. };
  8562. var parseFlags = {
  8563. D: [twoDigits, function (d, v) {
  8564. d.day = v;
  8565. }],
  8566. Do: [new RegExp(twoDigits.source + word.source), function (d, v) {
  8567. d.day = parseInt(v, 10);
  8568. }],
  8569. M: [twoDigits, function (d, v) {
  8570. d.month = v - 1;
  8571. }],
  8572. YY: [twoDigits, function (d, v) {
  8573. var da = new Date(),
  8574. cent = +('' + da.getFullYear()).substr(0, 2);
  8575. d.year = '' + (v > 68 ? cent - 1 : cent) + v;
  8576. }],
  8577. h: [twoDigits, function (d, v) {
  8578. d.hour = v;
  8579. }],
  8580. m: [twoDigits, function (d, v) {
  8581. d.minute = v;
  8582. }],
  8583. s: [twoDigits, function (d, v) {
  8584. d.second = v;
  8585. }],
  8586. YYYY: [fourDigits, function (d, v) {
  8587. d.year = v;
  8588. }],
  8589. S: [/\d/, function (d, v) {
  8590. d.millisecond = v * 100;
  8591. }],
  8592. SS: [/\d{2}/, function (d, v) {
  8593. d.millisecond = v * 10;
  8594. }],
  8595. SSS: [threeDigits, function (d, v) {
  8596. d.millisecond = v;
  8597. }],
  8598. d: [twoDigits, noop],
  8599. ddd: [word, noop],
  8600. MMM: [word, monthUpdate('monthNamesShort')],
  8601. MMMM: [word, monthUpdate('monthNames')],
  8602. a: [word, function (d, v, i18n) {
  8603. var val = v.toLowerCase();
  8604. if (val === i18n.amPm[0]) {
  8605. d.isPm = false;
  8606. } else if (val === i18n.amPm[1]) {
  8607. d.isPm = true;
  8608. }
  8609. }],
  8610. ZZ: [/([\+\-]\d\d:?\d\d|Z)/, function (d, v) {
  8611. if (v === 'Z') v = '+00:00';
  8612. var parts = (v + '').match(/([\+\-]|\d\d)/gi),
  8613. minutes;
  8614. if (parts) {
  8615. minutes = +(parts[1] * 60) + parseInt(parts[2], 10);
  8616. d.timezoneOffset = parts[0] === '+' ? minutes : -minutes;
  8617. }
  8618. }]
  8619. };
  8620. parseFlags.dd = parseFlags.d;
  8621. parseFlags.dddd = parseFlags.ddd;
  8622. parseFlags.DD = parseFlags.D;
  8623. parseFlags.mm = parseFlags.m;
  8624. parseFlags.hh = parseFlags.H = parseFlags.HH = parseFlags.h;
  8625. parseFlags.MM = parseFlags.M;
  8626. parseFlags.ss = parseFlags.s;
  8627. parseFlags.A = parseFlags.a;
  8628. // Some common format strings
  8629. fecha.masks = {
  8630. default: 'ddd MMM DD YYYY HH:mm:ss',
  8631. shortDate: 'M/D/YY',
  8632. mediumDate: 'MMM D, YYYY',
  8633. longDate: 'MMMM D, YYYY',
  8634. fullDate: 'dddd, MMMM D, YYYY',
  8635. shortTime: 'HH:mm',
  8636. mediumTime: 'HH:mm:ss',
  8637. longTime: 'HH:mm:ss.SSS'
  8638. };
  8639. /***
  8640. * Format a date
  8641. * @method format
  8642. * @param {Date|number} dateObj
  8643. * @param {string} mask Format of the date, i.e. 'mm-dd-yy' or 'shortDate'
  8644. */
  8645. fecha.format = function (dateObj, mask, i18nSettings) {
  8646. var i18n = i18nSettings || fecha.i18n;
  8647. if (typeof dateObj === 'number') {
  8648. dateObj = new Date(dateObj);
  8649. }
  8650. if (Object.prototype.toString.call(dateObj) !== '[object Date]' || isNaN(dateObj.getTime())) {
  8651. throw new Error('Invalid Date in fecha.format');
  8652. }
  8653. mask = fecha.masks[mask] || mask || fecha.masks['default'];
  8654. var literals = [];
  8655. // Make literals inactive by replacing them with ??
  8656. mask = mask.replace(literal, function ($0, $1) {
  8657. literals.push($1);
  8658. return '??';
  8659. });
  8660. // Apply formatting rules
  8661. mask = mask.replace(token, function ($0) {
  8662. return $0 in formatFlags ? formatFlags[$0](dateObj, i18n) : $0.slice(1, $0.length - 1);
  8663. });
  8664. // Inline literal values back into the formatted value
  8665. return mask.replace(/\?\?/g, function () {
  8666. return literals.shift();
  8667. });
  8668. };
  8669. /**
  8670. * Parse a date string into an object, changes - into /
  8671. * @method parse
  8672. * @param {string} dateStr Date string
  8673. * @param {string} format Date parse format
  8674. * @returns {Date|boolean}
  8675. */
  8676. fecha.parse = function (dateStr, format, i18nSettings) {
  8677. var i18n = i18nSettings || fecha.i18n;
  8678. if (typeof format !== 'string') {
  8679. throw new Error('Invalid format in fecha.parse');
  8680. }
  8681. format = fecha.masks[format] || format;
  8682. // Avoid regular expression denial of service, fail early for really long strings
  8683. // https://www.owasp.org/index.php/Regular_expression_Denial_of_Service_-_ReDoS
  8684. if (dateStr.length > 1000) {
  8685. return false;
  8686. }
  8687. var isValid = true;
  8688. var dateInfo = {};
  8689. format.replace(token, function ($0) {
  8690. if (parseFlags[$0]) {
  8691. var info = parseFlags[$0];
  8692. var index = dateStr.search(info[0]);
  8693. if (!~index) {
  8694. isValid = false;
  8695. } else {
  8696. dateStr.replace(info[0], function (result) {
  8697. info[1](dateInfo, result, i18n);
  8698. dateStr = dateStr.substr(index + result.length);
  8699. return result;
  8700. });
  8701. }
  8702. }
  8703. return parseFlags[$0] ? '' : $0.slice(1, $0.length - 1);
  8704. });
  8705. if (!isValid) {
  8706. return false;
  8707. }
  8708. var today = new Date();
  8709. if (dateInfo.isPm === true && dateInfo.hour != null && +dateInfo.hour !== 12) {
  8710. dateInfo.hour = +dateInfo.hour + 12;
  8711. } else if (dateInfo.isPm === false && +dateInfo.hour === 12) {
  8712. dateInfo.hour = 0;
  8713. }
  8714. var date;
  8715. if (dateInfo.timezoneOffset != null) {
  8716. dateInfo.minute = +(dateInfo.minute || 0) - +dateInfo.timezoneOffset;
  8717. date = new Date(Date.UTC(dateInfo.year || today.getFullYear(), dateInfo.month || 0, dateInfo.day || 1, dateInfo.hour || 0, dateInfo.minute || 0, dateInfo.second || 0, dateInfo.millisecond || 0));
  8718. } else {
  8719. date = new Date(dateInfo.year || today.getFullYear(), dateInfo.month || 0, dateInfo.day || 1, dateInfo.hour || 0, dateInfo.minute || 0, dateInfo.second || 0, dateInfo.millisecond || 0);
  8720. }
  8721. return date;
  8722. };
  8723. /* istanbul ignore next */
  8724. if (typeof module !== 'undefined' && module.exports) {
  8725. module.exports = fecha;
  8726. } else if (true) {
  8727. !(__WEBPACK_AMD_DEFINE_RESULT__ = function () {
  8728. return fecha;
  8729. }.call(exports, __webpack_require__, exports, module),
  8730. __WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__));
  8731. } else {
  8732. main.fecha = fecha;
  8733. }
  8734. })(this);
  8735. /***/ }),
  8736. /* 75 */
  8737. /***/ (function(module, exports, __webpack_require__) {
  8738. module.exports = {
  8739. Text: __webpack_require__(76),
  8740. Line: __webpack_require__(77),
  8741. Arc: __webpack_require__(78),
  8742. Rect: __webpack_require__(79),
  8743. Html: __webpack_require__(80),
  8744. Tag: __webpack_require__(81)
  8745. };
  8746. /***/ }),
  8747. /* 76 */
  8748. /***/ (function(module, exports, __webpack_require__) {
  8749. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  8750. function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
  8751. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
  8752. var Util = __webpack_require__(0);
  8753. var GuideBase = __webpack_require__(9);
  8754. var Text = function (_GuideBase) {
  8755. _inherits(Text, _GuideBase);
  8756. function Text() {
  8757. _classCallCheck(this, Text);
  8758. return _possibleConstructorReturn(this, _GuideBase.apply(this, arguments));
  8759. }
  8760. Text.prototype._initDefaultCfg = function _initDefaultCfg() {
  8761. this.type = 'text';
  8762. /**
  8763. * 辅助文本的位置
  8764. * @type {Function | Array}
  8765. */
  8766. this.position = null;
  8767. /**
  8768. * 辅助文本的显示文字
  8769. * @type {String}
  8770. */
  8771. this.content = null;
  8772. /**
  8773. * 辅助文本的样式配置
  8774. * @type {Object}
  8775. */
  8776. this.style = {
  8777. fill: '#000'
  8778. };
  8779. /**
  8780. * x 方向的偏移量
  8781. * @type {Number}
  8782. */
  8783. this.offsetX = 0;
  8784. /**
  8785. * y 方向的偏移量
  8786. * @type {Number}
  8787. */
  8788. this.offsetY = 0;
  8789. };
  8790. Text.prototype.render = function render(coord, container) {
  8791. var position = this.position;
  8792. var point = this.parsePoint(coord, position);
  8793. var content = this.content,
  8794. style = this.style,
  8795. offsetX = this.offsetX,
  8796. offsetY = this.offsetY;
  8797. if (offsetX) {
  8798. point.x += offsetX;
  8799. }
  8800. if (offsetY) {
  8801. point.y += offsetY;
  8802. }
  8803. var shape = container.addShape('text', {
  8804. className: 'guide-text',
  8805. attrs: Util.mix({
  8806. x: point.x,
  8807. y: point.y,
  8808. text: content
  8809. }, style)
  8810. });
  8811. this.element = shape;
  8812. return shape;
  8813. };
  8814. return Text;
  8815. }(GuideBase);
  8816. GuideBase.Text = Text;
  8817. module.exports = Text;
  8818. /***/ }),
  8819. /* 77 */
  8820. /***/ (function(module, exports, __webpack_require__) {
  8821. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  8822. function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
  8823. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
  8824. var Util = __webpack_require__(0);
  8825. var GuideBase = __webpack_require__(9);
  8826. var Line = function (_GuideBase) {
  8827. _inherits(Line, _GuideBase);
  8828. function Line() {
  8829. _classCallCheck(this, Line);
  8830. return _possibleConstructorReturn(this, _GuideBase.apply(this, arguments));
  8831. }
  8832. Line.prototype._initDefaultCfg = function _initDefaultCfg() {
  8833. this.type = 'line';
  8834. this.start = [];
  8835. this.end = [];
  8836. this.style = {
  8837. stroke: '#000',
  8838. lineWidth: 1
  8839. };
  8840. };
  8841. Line.prototype.render = function render(coord, container) {
  8842. var points = [];
  8843. points[0] = this.parsePoint(coord, this.start);
  8844. points[1] = this.parsePoint(coord, this.end);
  8845. var shape = container.addShape('Line', {
  8846. className: 'guide-line',
  8847. attrs: Util.mix({
  8848. x1: points[0].x,
  8849. y1: points[0].y,
  8850. x2: points[1].x,
  8851. y2: points[1].y
  8852. }, this.style)
  8853. });
  8854. this.element = shape;
  8855. return shape;
  8856. };
  8857. return Line;
  8858. }(GuideBase);
  8859. GuideBase.Line = Line;
  8860. module.exports = Line;
  8861. /***/ }),
  8862. /* 78 */
  8863. /***/ (function(module, exports, __webpack_require__) {
  8864. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  8865. function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
  8866. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
  8867. var Util = __webpack_require__(0);
  8868. var GuideBase = __webpack_require__(9);
  8869. var Arc = function (_GuideBase) {
  8870. _inherits(Arc, _GuideBase);
  8871. function Arc() {
  8872. _classCallCheck(this, Arc);
  8873. return _possibleConstructorReturn(this, _GuideBase.apply(this, arguments));
  8874. }
  8875. Arc.prototype._initDefaultCfg = function _initDefaultCfg() {
  8876. this.type = 'arc';
  8877. /**
  8878. * 起点
  8879. * @type {Array | Function}
  8880. */
  8881. this.start = [];
  8882. /**
  8883. * 终点
  8884. * @type {Array | Function}
  8885. */
  8886. this.end = [];
  8887. /**
  8888. * 辅助文本的样式配置
  8889. * @type {Object}
  8890. */
  8891. this.style = {
  8892. stroke: '#999',
  8893. lineWidth: 1
  8894. };
  8895. };
  8896. Arc.prototype.render = function render(coord, container) {
  8897. var self = this;
  8898. var start = self.parsePoint(coord, self.start);
  8899. var end = self.parsePoint(coord, self.end);
  8900. var coordCenter = coord.center;
  8901. var radius = Math.sqrt((start.x - coordCenter.x) * (start.x - coordCenter.x) + (start.y - coordCenter.y) * (start.y - coordCenter.y));
  8902. var startAngle = Math.atan2(start.y - coordCenter.y, start.x - coordCenter.x);
  8903. var endAngle = Math.atan2(end.y - coordCenter.y, end.x - coordCenter.x);
  8904. var shape = container.addShape('arc', {
  8905. className: 'guide-arc',
  8906. attrs: Util.mix({
  8907. x: coordCenter.x,
  8908. y: coordCenter.y,
  8909. r: radius,
  8910. startAngle: startAngle,
  8911. endAngle: endAngle
  8912. }, self.style)
  8913. });
  8914. self.element = shape;
  8915. return shape;
  8916. };
  8917. return Arc;
  8918. }(GuideBase);
  8919. GuideBase.Arc = Arc;
  8920. module.exports = Arc;
  8921. /***/ }),
  8922. /* 79 */
  8923. /***/ (function(module, exports, __webpack_require__) {
  8924. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  8925. function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
  8926. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
  8927. var Util = __webpack_require__(0);
  8928. var GuideBase = __webpack_require__(9);
  8929. var Rect = function (_GuideBase) {
  8930. _inherits(Rect, _GuideBase);
  8931. function Rect() {
  8932. _classCallCheck(this, Rect);
  8933. return _possibleConstructorReturn(this, _GuideBase.apply(this, arguments));
  8934. }
  8935. Rect.prototype._initDefaultCfg = function _initDefaultCfg() {
  8936. this.type = 'rect';
  8937. this.start = [];
  8938. this.end = [];
  8939. this.style = {
  8940. fill: '#CCD7EB',
  8941. opacity: 0.4
  8942. };
  8943. };
  8944. Rect.prototype.render = function render(coord, container) {
  8945. var start = this.parsePoint(coord, this.start);
  8946. var end = this.parsePoint(coord, this.end);
  8947. var shape = container.addShape('rect', {
  8948. className: 'guide-rect',
  8949. attrs: Util.mix({
  8950. x: start.x,
  8951. y: start.y,
  8952. width: Math.abs(end.x - start.x),
  8953. height: Math.abs(start.y - end.y)
  8954. }, this.style)
  8955. });
  8956. this.element = shape;
  8957. return shape;
  8958. };
  8959. return Rect;
  8960. }(GuideBase);
  8961. GuideBase.Rect = Rect;
  8962. module.exports = Rect;
  8963. /***/ }),
  8964. /* 80 */
  8965. /***/ (function(module, exports, __webpack_require__) {
  8966. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  8967. function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
  8968. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
  8969. var Util = __webpack_require__(0);
  8970. var GuideBase = __webpack_require__(9);
  8971. function getOffsetFromAlign(alignX, alignY, width, height) {
  8972. var result = [];
  8973. if (alignX === 'left' && alignY === 'top') {
  8974. result[0] = 0;
  8975. result[1] = 0;
  8976. } else if (alignX === 'right' && alignY === 'top') {
  8977. result[0] = -width;
  8978. result[1] = 0;
  8979. } else if (alignX === 'left' && alignY === 'bottom') {
  8980. result[0] = 0;
  8981. result[1] = Math.floor(-height);
  8982. } else if (alignX === 'right' && alignY === 'bottom') {
  8983. result[0] = Math.floor(-width);
  8984. result[1] = Math.floor(-height);
  8985. } else if (alignX === 'right' && alignY === 'middle') {
  8986. result[0] = Math.floor(-width);
  8987. result[1] = Math.floor(-height / 2);
  8988. } else if (alignX === 'left' && alignY === 'middle') {
  8989. result[0] = 0;
  8990. result[1] = Math.floor(-height / 2);
  8991. } else if (alignX === 'center' && alignY === 'bottom') {
  8992. result[0] = Math.floor(-width / 2);
  8993. result[1] = Math.floor(-height);
  8994. } else if (alignX === 'center' && alignY === 'top') {
  8995. result[0] = Math.floor(-width / 2);
  8996. result[1] = 0;
  8997. } else {
  8998. result[0] = Math.floor(-width / 2);
  8999. result[1] = Math.floor(-height / 2);
  9000. }
  9001. return result;
  9002. }
  9003. function modifyCSS(DOM, CSS) {
  9004. for (var key in CSS) {
  9005. if (CSS.hasOwnProperty(key)) {
  9006. DOM.style[key] = CSS[key];
  9007. }
  9008. }
  9009. return DOM;
  9010. }
  9011. function createDom(str) {
  9012. var container = document.createElement('div');
  9013. str = str.replace(/(^\s*)|(\s*$)/g, '');
  9014. container.innerHTML = '' + str;
  9015. return container.childNodes[0];
  9016. }
  9017. var Html = function (_GuideBase) {
  9018. _inherits(Html, _GuideBase);
  9019. function Html() {
  9020. _classCallCheck(this, Html);
  9021. return _possibleConstructorReturn(this, _GuideBase.apply(this, arguments));
  9022. }
  9023. Html.prototype._initDefaultCfg = function _initDefaultCfg() {
  9024. this.type = 'html';
  9025. /**
  9026. * dom 显示位置点
  9027. * @type {Object | Array}
  9028. */
  9029. this.position = null;
  9030. /**
  9031. * 水平方向对齐方式,可取值 'left'、'center'、'right'
  9032. * @type {String}
  9033. */
  9034. this.alignX = 'center';
  9035. /**
  9036. * 垂直方向对齐方式,可取值 'top'、'middle'、'bottom'
  9037. * @type {String}
  9038. */
  9039. this.alignY = 'middle';
  9040. /**
  9041. * x 方向的偏移量
  9042. * @type {Number}
  9043. */
  9044. this.offsetX = null;
  9045. /**
  9046. * y 方向的偏移量
  9047. * @type {Number}
  9048. */
  9049. this.offsetY = null;
  9050. /**
  9051. * html内容
  9052. *@type {String | Function}
  9053. */
  9054. this.html = null;
  9055. };
  9056. // override paint
  9057. Html.prototype.render = function render(coord, container) {
  9058. var self = this;
  9059. var position = self.parsePoint(coord, self.position);
  9060. var myNode = createDom(self.html);
  9061. myNode = modifyCSS(myNode, {
  9062. position: 'absolute',
  9063. top: Math.floor(position.y) + 'px',
  9064. left: Math.floor(position.x) + 'px',
  9065. visibility: 'hidden'
  9066. });
  9067. var parentNode = container.get('canvas').get('el').parentNode;
  9068. parentNode = modifyCSS(parentNode, {
  9069. position: 'relative'
  9070. });
  9071. // 创建html guide 的容器
  9072. var wrapperNode = void 0;
  9073. if (parentNode.getElementsByClassName('guideWapper').length > 0) {
  9074. wrapperNode = parentNode.getElementsByClassName('guideWapper')[0];
  9075. } else {
  9076. wrapperNode = createDom('<div class="guideWapper"></div>');
  9077. wrapperNode = modifyCSS(wrapperNode, {
  9078. position: 'absolute',
  9079. top: 0,
  9080. left: 0
  9081. });
  9082. parentNode.appendChild(wrapperNode);
  9083. }
  9084. wrapperNode.appendChild(myNode);
  9085. var alignX = self.alignX,
  9086. alignY = self.alignY,
  9087. offsetX = self.offsetX,
  9088. offsetY = self.offsetY;
  9089. var width = Util.getWidth(myNode);
  9090. var height = Util.getHeight(myNode);
  9091. var newOffset = getOffsetFromAlign(alignX, alignY, width, height);
  9092. position.x = position.x + newOffset[0];
  9093. position.y = position.y + newOffset[1];
  9094. if (offsetX) {
  9095. position.x += offsetX;
  9096. }
  9097. if (offsetY) {
  9098. position.y += offsetY;
  9099. }
  9100. modifyCSS(myNode, {
  9101. top: Math.floor(position.y) + 'px',
  9102. left: Math.floor(position.x) + 'px',
  9103. visibility: 'visible'
  9104. });
  9105. self.element = wrapperNode;
  9106. };
  9107. Html.prototype.remove = function remove() {
  9108. var element = this.element;
  9109. element && element.remove();
  9110. };
  9111. return Html;
  9112. }(GuideBase);
  9113. GuideBase.Html = Html;
  9114. module.exports = Html;
  9115. /***/ }),
  9116. /* 81 */
  9117. /***/ (function(module, exports, __webpack_require__) {
  9118. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  9119. function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
  9120. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
  9121. var Util = __webpack_require__(0);
  9122. var GuideBase = __webpack_require__(9);
  9123. var Tag = function (_GuideBase) {
  9124. _inherits(Tag, _GuideBase);
  9125. function Tag() {
  9126. _classCallCheck(this, Tag);
  9127. return _possibleConstructorReturn(this, _GuideBase.apply(this, arguments));
  9128. }
  9129. Tag.prototype._initDefaultCfg = function _initDefaultCfg() {
  9130. this.type = 'tag';
  9131. this.position = null;
  9132. this.content = null;
  9133. this.direct = 'tl'; // 默认 tag 位置
  9134. this.autoAdjust = true; // 当 tag 出轨时,拉它一把,悬崖勒马
  9135. this.offsetX = 0;
  9136. this.offsetY = 0;
  9137. this.side = 4; // 三角标的边长
  9138. this.background = {
  9139. padding: 5, // tag 内边距
  9140. radius: 2, // tag 圆角
  9141. fill: '#1890FF' // tag 背景色
  9142. }; // tag 背景框样式
  9143. this.textStyle = {
  9144. fontSize: 12,
  9145. fill: '#fff',
  9146. textAlign: 'center',
  9147. textBaseline: 'middle'
  9148. }; // 文本样式
  9149. this.withPoint = true; // 是否带点
  9150. this.pointStyle = {
  9151. fill: '#1890FF',
  9152. r: 3,
  9153. lineWidth: 1,
  9154. stroke: '#fff'
  9155. }; // 点的样式
  9156. };
  9157. Tag.prototype._getDirect = function _getDirect(container, point, tagWidth, tagHeight) {
  9158. var direct = this.direct;
  9159. var side = this.side;
  9160. var canvas = container.get('canvas');
  9161. var clientWidth = canvas.get('width');
  9162. var clientHeight = canvas.get('height');
  9163. var x = point.x,
  9164. y = point.y;
  9165. var vertical = direct[0];
  9166. var horizontal = direct[1];
  9167. // 垂直方向位置调整
  9168. if (vertical === 't' && y - side - tagHeight < 0) {
  9169. vertical = 'b';
  9170. } else if (vertical === 'b' && y + side + tagHeight > clientHeight) {
  9171. vertical = 't';
  9172. }
  9173. // 水平方向位置调整
  9174. var diff = vertical === 'c' ? side : 0;
  9175. if (horizontal === 'l' && x - diff - tagWidth < 0) {
  9176. horizontal = 'r';
  9177. } else if (horizontal === 'r' && x + diff + tagWidth > clientWidth) {
  9178. horizontal = 'l';
  9179. } else if (horizontal === 'c') {
  9180. if (tagWidth / 2 + x + diff > clientWidth) {
  9181. horizontal = 'l';
  9182. } else if (x - tagWidth / 2 - diff < 0) {
  9183. horizontal = 'r';
  9184. }
  9185. }
  9186. direct = vertical + horizontal;
  9187. return direct;
  9188. };
  9189. Tag.prototype.render = function render(coord, container) {
  9190. var position = this.parsePoint(coord, this.position);
  9191. var content = this.content,
  9192. background = this.background,
  9193. textStyle = this.textStyle;
  9194. var shapes = [];
  9195. var wrapperContainer = container.addGroup({
  9196. className: 'guide-tag'
  9197. });
  9198. if (this.withPoint) {
  9199. var pointShape = wrapperContainer.addShape('Circle', {
  9200. className: 'guide-tag-point',
  9201. attrs: Util.mix({
  9202. x: position.x,
  9203. y: position.y
  9204. }, this.pointStyle)
  9205. });
  9206. shapes.push(pointShape);
  9207. }
  9208. var tagContainer = wrapperContainer.addGroup();
  9209. // 绘制文本
  9210. var tagText = tagContainer.addShape('text', {
  9211. className: 'guide-tag-text',
  9212. zIndex: 1,
  9213. attrs: Util.mix({
  9214. x: 0,
  9215. y: 0,
  9216. text: content
  9217. }, textStyle)
  9218. });
  9219. shapes.push(tagText);
  9220. // 绘制背景框
  9221. var textBBox = tagText.getBBox();
  9222. var padding = Util.parsePadding(background.padding);
  9223. var tagWidth = textBBox.width + padding[1] + padding[3];
  9224. var tagHeight = textBBox.height + padding[0] + padding[2];
  9225. var yMin = textBBox.minY - padding[0];
  9226. var xMin = textBBox.minX - padding[3];
  9227. var tagBg = tagContainer.addShape('rect', {
  9228. className: 'guide-tag-bg',
  9229. zIndex: -1,
  9230. attrs: Util.mix({
  9231. x: xMin,
  9232. y: yMin,
  9233. width: tagWidth,
  9234. height: tagHeight
  9235. }, background)
  9236. });
  9237. shapes.push(tagBg);
  9238. var direct = this.autoAdjust ? this._getDirect(container, position, tagWidth, tagHeight) : this.direct;
  9239. var side = this.side;
  9240. var x = position.x + this.offsetX;
  9241. var y = position.y + this.offsetY;
  9242. var arrowPoints = void 0;
  9243. var radius = Util.parsePadding(background.radius);
  9244. if (direct === 'tl') {
  9245. arrowPoints = [{ x: tagWidth + xMin - side - 1, y: tagHeight + yMin - 1 }, // 这个 1 是为了防止出现白边
  9246. { x: tagWidth + xMin, y: tagHeight + yMin - 1 }, { x: tagWidth + xMin, y: tagHeight + side + yMin }];
  9247. radius[2] = 0;
  9248. x = x - tagWidth;
  9249. y = y - side - tagHeight;
  9250. } else if (direct === 'cl') {
  9251. arrowPoints = [{ x: tagWidth + xMin - 1, y: (tagHeight - side) / 2 + yMin - 1 }, { x: tagWidth + xMin - 1, y: (tagHeight + side) / 2 + yMin + 1 }, { x: tagWidth + side + xMin, y: tagHeight / 2 + yMin }];
  9252. x = x - tagWidth - side;
  9253. y = y - tagHeight / 2;
  9254. } else if (direct === 'bl') {
  9255. arrowPoints = [{ x: tagWidth + xMin, y: -side + yMin }, { x: tagWidth + xMin - side - 1, y: yMin + 1 }, { x: tagWidth + xMin, y: yMin + 1 }];
  9256. radius[1] = 0;
  9257. x = x - tagWidth;
  9258. y = y + side;
  9259. } else if (direct === 'bc') {
  9260. arrowPoints = [{ x: tagWidth / 2 + xMin, y: -side + yMin }, { x: (tagWidth - side) / 2 + xMin - 1, y: yMin + 1 }, { x: (tagWidth + side) / 2 + xMin + 1, y: yMin + 1 }];
  9261. x = x - tagWidth / 2;
  9262. y = y + side;
  9263. } else if (direct === 'br') {
  9264. arrowPoints = [{ x: xMin, y: yMin - side }, { x: xMin, y: yMin + 1 }, { x: xMin + side + 1, y: yMin + 1 }];
  9265. radius[0] = 0;
  9266. y = y + side;
  9267. } else if (direct === 'cr') {
  9268. arrowPoints = [{ x: xMin - side, y: tagHeight / 2 + yMin }, { x: xMin + 1, y: (tagHeight - side) / 2 + yMin - 1 }, { x: xMin + 1, y: (tagHeight + side) / 2 + yMin + 1 }];
  9269. x = x + side;
  9270. y = y - tagHeight / 2;
  9271. } else if (direct === 'tr') {
  9272. arrowPoints = [{ x: xMin, y: tagHeight + side + yMin }, { x: xMin, y: tagHeight + yMin - 1 }, { x: side + xMin + 1, y: tagHeight + yMin - 1 }];
  9273. radius[3] = 0;
  9274. y = y - tagHeight - side;
  9275. } else if (direct === 'tc') {
  9276. arrowPoints = [{ x: (tagWidth - side) / 2 + xMin - 1, y: tagHeight + yMin - 1 }, { x: (tagWidth + side) / 2 + xMin + 1, y: tagHeight + yMin - 1 }, { x: tagWidth / 2 + xMin, y: tagHeight + side + yMin }];
  9277. x = x - tagWidth / 2;
  9278. y = y - tagHeight - side;
  9279. }
  9280. var sideShape = tagContainer.addShape('Polygon', {
  9281. className: 'guide-tag-side',
  9282. zIndex: 0,
  9283. attrs: {
  9284. points: arrowPoints,
  9285. fill: background.fill
  9286. }
  9287. });
  9288. shapes.push(sideShape);
  9289. tagBg.attr('radius', radius);
  9290. tagContainer.moveTo(x - xMin, y - yMin);
  9291. tagContainer.sort();
  9292. this.element = wrapperContainer;
  9293. return shapes;
  9294. };
  9295. return Tag;
  9296. }(GuideBase);
  9297. GuideBase.Tag = Tag;
  9298. module.exports = Tag;
  9299. /***/ }),
  9300. /* 82 */
  9301. /***/ (function(module, exports, __webpack_require__) {
  9302. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  9303. var Util = __webpack_require__(0);
  9304. var Global = __webpack_require__(1);
  9305. var Tooltip = __webpack_require__(83);
  9306. // Register the default configuration for Tooltip
  9307. Global.tooltip = Util.deepMix({
  9308. triggerOn: ['touchstart', 'touchmove'],
  9309. // triggerOff: 'touchend',
  9310. alwaysShow: false, // 当移出触发区域,是否仍显示提示框内容,默认为 false,移出触发区域 tooltip 消失,设置为 true 可以保证一直显示提示框内容
  9311. showTitle: false,
  9312. showCrosshairs: false,
  9313. crosshairsStyle: {
  9314. stroke: 'rgba(0, 0, 0, 0.25)',
  9315. lineWidth: 1
  9316. },
  9317. showTooltipMarker: true,
  9318. background: {
  9319. radius: 1,
  9320. fill: 'rgba(0, 0, 0, 0.65)',
  9321. padding: [3, 5]
  9322. },
  9323. titleStyle: {
  9324. fontSize: 12,
  9325. fill: '#fff',
  9326. textAlign: 'start',
  9327. textBaseline: 'top'
  9328. },
  9329. nameStyle: {
  9330. fontSize: 12,
  9331. fill: 'rgba(255, 255, 255, 0.65)',
  9332. textAlign: 'start',
  9333. textBaseline: 'middle'
  9334. },
  9335. valueStyle: {
  9336. fontSize: 12,
  9337. fill: '#fff',
  9338. textAlign: 'start',
  9339. textBaseline: 'middle'
  9340. },
  9341. showItemMarker: true,
  9342. itemMarkerStyle: {
  9343. radius: 3,
  9344. symbol: 'circle',
  9345. lineWidth: 1,
  9346. stroke: '#fff'
  9347. },
  9348. layout: 'horizontal'
  9349. }, Global.tooltip || {});
  9350. function _getTooltipValueScale(geom) {
  9351. var colorAttr = geom.getAttr('color');
  9352. if (colorAttr) {
  9353. var colorScale = colorAttr.getScale(colorAttr.type);
  9354. if (colorScale.isLinear) {
  9355. return colorScale;
  9356. }
  9357. }
  9358. var xScale = geom.getXScale();
  9359. var yScale = geom.getYScale();
  9360. if (yScale) {
  9361. return yScale;
  9362. }
  9363. return xScale;
  9364. }
  9365. function getTooltipName(geom, origin) {
  9366. var name = void 0;
  9367. var nameScale = void 0;
  9368. var groupScales = geom._getGroupScales();
  9369. if (groupScales.length) {
  9370. // 如果存在分组类型,取第一个分组类型
  9371. Util.each(groupScales, function (scale) {
  9372. nameScale = scale;
  9373. return false;
  9374. });
  9375. }
  9376. if (nameScale) {
  9377. var field = nameScale.field;
  9378. name = nameScale.getText(origin[field]);
  9379. } else {
  9380. var valueScale = _getTooltipValueScale(geom);
  9381. name = valueScale.alias || valueScale.field;
  9382. }
  9383. return name;
  9384. }
  9385. function getTooltipValue(geom, origin) {
  9386. var scale = _getTooltipValueScale(geom);
  9387. return scale.getText(origin[scale.field]);
  9388. }
  9389. function getTooltipTitle(geom, origin) {
  9390. var position = geom.getAttr('position');
  9391. var field = position.getFields()[0];
  9392. var scale = geom.get('scales')[field];
  9393. return scale.getText(origin[scale.field]);
  9394. }
  9395. function _indexOfArray(items, item) {
  9396. var rst = -1;
  9397. Util.each(items, function (sub, index) {
  9398. if (sub.title === item.title && sub.name === item.name && sub.value === item.value && sub.color === item.color) {
  9399. rst = index;
  9400. return false;
  9401. }
  9402. });
  9403. return rst;
  9404. }
  9405. // 去除重复的值, 去除不同图形相同数据,只展示一份即可
  9406. function _uniqItems(items) {
  9407. var tmp = [];
  9408. Util.each(items, function (item) {
  9409. var index = _indexOfArray(tmp, item);
  9410. if (index === -1) {
  9411. tmp.push(item);
  9412. } else {
  9413. tmp[index] = item;
  9414. }
  9415. });
  9416. return tmp;
  9417. }
  9418. function isEqual(arr1, arr2) {
  9419. return JSON.stringify(arr1) === JSON.stringify(arr2);
  9420. }
  9421. var TooltipController = function () {
  9422. function TooltipController(cfg) {
  9423. _classCallCheck(this, TooltipController);
  9424. this.enable = true;
  9425. this.cfg = {};
  9426. this.tooltip = null;
  9427. this.chart = null;
  9428. this.timeStamp = 0;
  9429. Util.mix(this, cfg);
  9430. var chart = this.chart;
  9431. this.canvasDom = chart.get('canvas').get('el');
  9432. }
  9433. TooltipController.prototype._setCrosshairsCfg = function _setCrosshairsCfg() {
  9434. var self = this;
  9435. var chart = self.chart;
  9436. var defaultCfg = Util.mix({}, Global.tooltip);
  9437. var geoms = chart.get('geoms');
  9438. var shapes = [];
  9439. Util.each(geoms, function (geom) {
  9440. var type = geom.get('type');
  9441. if (Util.indexOf(shapes, type) === -1) {
  9442. shapes.push(type);
  9443. }
  9444. });
  9445. var coordType = chart.get('coord').type;
  9446. if (geoms.length && (coordType === 'cartesian' || coordType === 'rect')) {
  9447. if (shapes.length === 1 && ['line', 'area', 'path', 'point'].indexOf(shapes[0]) !== -1) {
  9448. Util.mix(defaultCfg, {
  9449. showCrosshairs: true
  9450. });
  9451. }
  9452. }
  9453. return defaultCfg;
  9454. };
  9455. TooltipController.prototype._getMaxLength = function _getMaxLength() {
  9456. var cfg = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  9457. var layout = cfg.layout,
  9458. plotRange = cfg.plotRange;
  9459. return layout === 'horizontal' ? plotRange.br.x - plotRange.bl.x : plotRange.bl.y - plotRange.tr.y;
  9460. };
  9461. TooltipController.prototype.render = function render() {
  9462. var self = this;
  9463. if (self.tooltip || !self.enable) {
  9464. return;
  9465. }
  9466. var chart = self.chart;
  9467. var canvas = chart.get('canvas');
  9468. var frontPlot = chart.get('frontPlot').addGroup({
  9469. className: 'tooltipContainer',
  9470. zIndex: 10
  9471. });
  9472. var backPlot = chart.get('backPlot').addGroup({
  9473. className: 'tooltipContainer'
  9474. });
  9475. var plotRange = chart.get('plotRange');
  9476. var coord = chart.get('coord');
  9477. var defaultCfg = self._setCrosshairsCfg();
  9478. var cfg = self.cfg;
  9479. cfg = Util.deepMix({
  9480. plotRange: plotRange,
  9481. frontPlot: frontPlot,
  9482. backPlot: backPlot,
  9483. canvas: canvas,
  9484. fixed: coord.transposed || coord.isPolar
  9485. }, defaultCfg, cfg);
  9486. cfg.maxLength = self._getMaxLength(cfg);
  9487. this.cfg = cfg;
  9488. var tooltip = new Tooltip(cfg);
  9489. self.tooltip = tooltip;
  9490. self.bindEvents();
  9491. };
  9492. TooltipController.prototype.clear = function clear() {
  9493. var tooltip = this.tooltip;
  9494. tooltip && tooltip.destroy();
  9495. this.tooltip = null;
  9496. this.prePoint = null;
  9497. this.unBindEvents();
  9498. };
  9499. TooltipController.prototype._getTooltipMarkerStyle = function _getTooltipMarkerStyle() {
  9500. var cfg = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  9501. var type = cfg.type,
  9502. items = cfg.items;
  9503. var tooltipCfg = this.cfg;
  9504. if (type === 'rect') {
  9505. var x = void 0;
  9506. var y = void 0;
  9507. var width = void 0;
  9508. var height = void 0;
  9509. var chart = this.chart;
  9510. var _chart$get = chart.get('plotRange'),
  9511. tl = _chart$get.tl,
  9512. br = _chart$get.br;
  9513. var coord = chart.get('coord');
  9514. var firstItem = items[0];
  9515. var lastItem = items[items.length - 1];
  9516. var intervalWidth = firstItem.width;
  9517. if (coord.transposed) {
  9518. x = tl.x;
  9519. y = lastItem.y - intervalWidth * 0.75;
  9520. width = br.x - tl.x;
  9521. height = firstItem.y - lastItem.y + 1.5 * intervalWidth;
  9522. } else {
  9523. x = firstItem.x - intervalWidth * 0.75;
  9524. y = tl.y;
  9525. width = lastItem.x - firstItem.x + 1.5 * intervalWidth;
  9526. height = br.y - tl.y;
  9527. }
  9528. cfg.style = Util.mix({
  9529. x: x,
  9530. y: y,
  9531. width: width,
  9532. height: height,
  9533. fill: '#CCD6EC',
  9534. opacity: 0.3
  9535. }, tooltipCfg.tooltipMarkerStyle);
  9536. } else {
  9537. cfg.style = Util.mix({
  9538. radius: 4,
  9539. fill: '#fff',
  9540. lineWidth: 2
  9541. }, tooltipCfg.tooltipMarkerStyle);
  9542. }
  9543. return cfg;
  9544. };
  9545. TooltipController.prototype._setTooltip = function _setTooltip(point, items) {
  9546. var tooltipMarkerCfg = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
  9547. var lastActive = this._lastActive;
  9548. var tooltip = this.tooltip;
  9549. var cfg = this.cfg;
  9550. items = _uniqItems(items); // 过滤重复的记录项
  9551. if (cfg.onShow) {
  9552. // tooltip 展示
  9553. cfg.onShow({
  9554. x: point.x,
  9555. y: point.y,
  9556. tooltip: tooltip,
  9557. items: items,
  9558. tooltipMarkerCfg: tooltipMarkerCfg
  9559. });
  9560. }
  9561. if (isEqual(lastActive, items)) {
  9562. return;
  9563. }
  9564. this._lastActive = items;
  9565. if (cfg.onChange || Util.isFunction(cfg.custom)) {
  9566. // 兼容之前的写法
  9567. var onChange = cfg.onChange || cfg.custom;
  9568. onChange({
  9569. x: point.x,
  9570. y: point.y,
  9571. tooltip: tooltip,
  9572. items: items,
  9573. tooltipMarkerCfg: tooltipMarkerCfg
  9574. });
  9575. }
  9576. if (!cfg.custom) {
  9577. var first = items[0];
  9578. var title = first.title || first.name;
  9579. tooltip.setContent(title, items);
  9580. }
  9581. tooltip.setPosition(items);
  9582. var markerItems = tooltipMarkerCfg.items;
  9583. if (cfg.showTooltipMarker && markerItems.length) {
  9584. tooltipMarkerCfg = this._getTooltipMarkerStyle(tooltipMarkerCfg);
  9585. tooltip.setMarkers(tooltipMarkerCfg);
  9586. } else {
  9587. tooltip.clearMarkers();
  9588. }
  9589. tooltip.show();
  9590. };
  9591. TooltipController.prototype.showTooltip = function showTooltip(point) {
  9592. var self = this;
  9593. var chart = self.chart;
  9594. var tooltipMarkerType = void 0;
  9595. var tooltipMarkerItems = [];
  9596. var items = [];
  9597. var cfg = self.cfg;
  9598. var marker = void 0;
  9599. if (cfg.showItemMarker) {
  9600. marker = cfg.itemMarkerStyle;
  9601. }
  9602. var geoms = chart.get('geoms');
  9603. var coord = chart.get('coord');
  9604. Util.each(geoms, function (geom) {
  9605. var type = geom.get('type');
  9606. var records = geom.getSnapRecords(point);
  9607. Util.each(records, function (record) {
  9608. if (record.x && record.y) {
  9609. var x = record.x,
  9610. y = record.y,
  9611. _origin = record._origin,
  9612. color = record.color;
  9613. var tooltipItem = {
  9614. x: x,
  9615. y: Util.isArray(y) ? y[1] : y,
  9616. color: color || Global.defaultColor,
  9617. origin: _origin,
  9618. name: getTooltipName(geom, _origin),
  9619. value: getTooltipValue(geom, _origin),
  9620. title: getTooltipTitle(geom, _origin)
  9621. };
  9622. if (marker) {
  9623. tooltipItem.marker = Util.mix({
  9624. fill: color || Global.defaultColor
  9625. }, marker);
  9626. }
  9627. items.push(tooltipItem);
  9628. if (['line', 'area', 'path'].indexOf(type) !== -1) {
  9629. tooltipMarkerType = 'circle';
  9630. tooltipMarkerItems.push(tooltipItem);
  9631. } else if (type === 'interval' && (coord.type === 'cartesian' || coord.type === 'rect')) {
  9632. tooltipMarkerType = 'rect';
  9633. tooltipItem.width = geom.getSize(record._origin);
  9634. tooltipMarkerItems.push(tooltipItem);
  9635. }
  9636. }
  9637. });
  9638. });
  9639. if (items.length) {
  9640. var tooltipMarkerCfg = {
  9641. items: tooltipMarkerItems,
  9642. type: tooltipMarkerType
  9643. };
  9644. self._setTooltip(point, items, tooltipMarkerCfg);
  9645. } else {
  9646. self.hideTooltip();
  9647. }
  9648. };
  9649. TooltipController.prototype.hideTooltip = function hideTooltip() {
  9650. var cfg = this.cfg;
  9651. this._lastActive = [];
  9652. var tooltip = this.tooltip;
  9653. if (tooltip) {
  9654. tooltip.hide();
  9655. if (cfg.onHide) {
  9656. cfg.onHide({
  9657. tooltip: tooltip
  9658. });
  9659. }
  9660. var canvas = this.chart.get('canvas');
  9661. canvas.draw();
  9662. }
  9663. };
  9664. TooltipController.prototype.handleShowEvent = function handleShowEvent(ev) {
  9665. var chart = this.chart;
  9666. var plot = chart.get('plotRange');
  9667. var _Util$createEvent = Util.createEvent(ev, chart),
  9668. x = _Util$createEvent.x,
  9669. y = _Util$createEvent.y;
  9670. if (!(x >= plot.tl.x && x <= plot.tr.x && y >= plot.tl.y && y <= plot.br.y) && !this.cfg.alwaysShow) {
  9671. // not in chart plot
  9672. this.hideTooltip();
  9673. return;
  9674. }
  9675. var lastTimeStamp = this.timeStamp;
  9676. var timeStamp = +new Date();
  9677. if (timeStamp - lastTimeStamp > 16) {
  9678. this.showTooltip({ x: x, y: y });
  9679. this.timeStamp = timeStamp;
  9680. }
  9681. };
  9682. TooltipController.prototype.handleHideEvent = function handleHideEvent() {
  9683. this.hideTooltip();
  9684. };
  9685. TooltipController.prototype.handleDocEvent = function handleDocEvent(ev) {
  9686. var canvasDom = this.canvasDom;
  9687. if (ev.target !== canvasDom) {
  9688. this.hideTooltip();
  9689. }
  9690. };
  9691. TooltipController.prototype._handleEvent = function _handleEvent(methodName, method, action) {
  9692. var canvasDom = this.canvasDom;
  9693. Util.each([].concat(methodName), function (aMethod) {
  9694. if (action === 'bind') {
  9695. Util.addEventListener(canvasDom, aMethod, method);
  9696. } else {
  9697. Util.removeEventListener(canvasDom, aMethod, method);
  9698. }
  9699. });
  9700. };
  9701. TooltipController.prototype.bindEvents = function bindEvents() {
  9702. var cfg = this.cfg;
  9703. var triggerOn = cfg.triggerOn,
  9704. triggerOff = cfg.triggerOff,
  9705. alwaysShow = cfg.alwaysShow;
  9706. var showMethod = Util.wrapBehavior(this, 'handleShowEvent');
  9707. var hideMethod = Util.wrapBehavior(this, 'handleHideEvent');
  9708. triggerOn && this._handleEvent(triggerOn, showMethod, 'bind');
  9709. triggerOff && this._handleEvent(triggerOff, hideMethod, 'bind');
  9710. // TODO: 当用户点击 canvas 外的事件时 tooltip 消失
  9711. if (!alwaysShow) {
  9712. var docMethod = Util.wrapBehavior(this, 'handleDocEvent');
  9713. Util.isBrowser && Util.addEventListener(document, 'touchstart', docMethod);
  9714. }
  9715. };
  9716. TooltipController.prototype.unBindEvents = function unBindEvents() {
  9717. var cfg = this.cfg;
  9718. var triggerOn = cfg.triggerOn,
  9719. triggerOff = cfg.triggerOff,
  9720. alwaysShow = cfg.alwaysShow;
  9721. var showMethod = Util.getWrapBehavior(this, 'handleShowEvent');
  9722. var hideMethod = Util.getWrapBehavior(this, 'handleHideEvent');
  9723. triggerOn && this._handleEvent(triggerOn, showMethod, 'unBind');
  9724. triggerOff && this._handleEvent(triggerOff, hideMethod, 'unBind');
  9725. // TODO: 当用户点击 canvas 外的事件时 tooltip 消失
  9726. if (!alwaysShow) {
  9727. var docMethod = Util.getWrapBehavior(this, 'handleDocEvent');
  9728. Util.isBrowser && Util.removeEventListener(document, 'touchstart', docMethod);
  9729. }
  9730. };
  9731. return TooltipController;
  9732. }();
  9733. module.exports = {
  9734. init: function init(chart) {
  9735. var tooltipController = new TooltipController({
  9736. chart: chart
  9737. });
  9738. chart.set('tooltipController', tooltipController);
  9739. /**
  9740. * 配置 tooltip
  9741. * @param {Boolean|Object} enable Boolean 表示是否开启tooltip,Object 则表示配置项
  9742. * @param {Object} cfg 配置项
  9743. * @return {Chart} 返回 Chart 实例
  9744. */
  9745. chart.tooltip = function (enable) {
  9746. var cfg = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  9747. if (Util.isObject(enable)) {
  9748. cfg = enable;
  9749. enable = true;
  9750. }
  9751. tooltipController.enable = enable;
  9752. tooltipController.cfg = cfg;
  9753. return this;
  9754. };
  9755. },
  9756. afterGeomDraw: function afterGeomDraw(chart) {
  9757. var tooltipController = chart.get('tooltipController');
  9758. tooltipController.render();
  9759. /**
  9760. * 根据坐标点显示对应的 tooltip
  9761. * @param {Object} point 画布上的点
  9762. * @return {Chart} 返回 chart 实例
  9763. */
  9764. chart.showTooltip = function (point) {
  9765. tooltipController.showTooltip(point);
  9766. return this;
  9767. };
  9768. /**
  9769. * 隐藏 tooltip
  9770. * @return {Chart} 返回 chart 实例
  9771. */
  9772. chart.hideTooltip = function () {
  9773. tooltipController.hideTooltip();
  9774. return this;
  9775. };
  9776. },
  9777. clearInner: function clearInner(chart) {
  9778. var tooltipController = chart.get('tooltipController');
  9779. tooltipController.clear();
  9780. }
  9781. };
  9782. /***/ }),
  9783. /* 83 */
  9784. /***/ (function(module, exports, __webpack_require__) {
  9785. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  9786. var Util = __webpack_require__(0);
  9787. var Marker = __webpack_require__(66);
  9788. var Container = __webpack_require__(67);
  9789. var GAP = 4;
  9790. var Tooltip = function () {
  9791. Tooltip.prototype.getDefaultCfg = function getDefaultCfg() {
  9792. return {
  9793. /**
  9794. * 是否显示 tooltip 辅助线配置,默认不展示
  9795. * @type {Object}
  9796. */
  9797. showCrosshairs: false,
  9798. /**
  9799. * tooltip 辅助线显示样式
  9800. * @type {Object}
  9801. */
  9802. crosshairsStyle: {
  9803. stroke: 'rgba(0, 0, 0, 0.25)',
  9804. lineWidth: 1
  9805. },
  9806. /**
  9807. * tooltip 容器的样式
  9808. * @type {Object}
  9809. */
  9810. background: null,
  9811. /**
  9812. * 布局方式,horizontal 或者 vertical
  9813. * @type {String}
  9814. */
  9815. layout: 'horizontal',
  9816. offsetX: 0,
  9817. offsetY: 0
  9818. };
  9819. };
  9820. function Tooltip(cfg) {
  9821. _classCallCheck(this, Tooltip);
  9822. Util.deepMix(this, this.getDefaultCfg(), cfg);
  9823. var frontPlot = this.frontPlot;
  9824. var plotRange = this.plotRange;
  9825. if (!this.custom) {
  9826. // custom 表示用户使用自定义 tooltip
  9827. var container = new Container(Util.mix({
  9828. parent: frontPlot,
  9829. zIndex: 3
  9830. }, cfg));
  9831. this.container = container;
  9832. if (!this.fixed) {
  9833. this.tooltipArrow = frontPlot.addShape('Polygon', {
  9834. className: 'tooltip-arrow',
  9835. visible: false,
  9836. zIndex: 2,
  9837. attrs: {
  9838. points: [],
  9839. fill: this.background.fill
  9840. }
  9841. });
  9842. }
  9843. }
  9844. if (this.showCrosshairs) {
  9845. var crosshairsStyle = this.crosshairsStyle;
  9846. var shape = frontPlot.addShape('Line', {
  9847. className: 'tooltip-crosshairs',
  9848. zIndex: 0,
  9849. visible: false,
  9850. attrs: Util.mix({
  9851. x1: 0,
  9852. y1: plotRange.bl.y,
  9853. x2: 0,
  9854. y2: plotRange.tl.y
  9855. }, crosshairsStyle)
  9856. });
  9857. this.crosshairsShape = shape;
  9858. }
  9859. frontPlot.sort();
  9860. }
  9861. Tooltip.prototype.setContent = function setContent(title, items) {
  9862. this.title = title;
  9863. this.items = items;
  9864. var container = this.container;
  9865. container.setTitle(title);
  9866. container.setItems(items);
  9867. };
  9868. Tooltip.prototype.setPosition = function setPosition(items) {
  9869. var container = this.container,
  9870. plotRange = this.plotRange,
  9871. offsetX = this.offsetX,
  9872. offsetY = this.offsetY,
  9873. crosshairsShape = this.crosshairsShape,
  9874. fixed = this.fixed,
  9875. tooltipArrow = this.tooltipArrow;
  9876. crosshairsShape && crosshairsShape.moveTo(items[0].x, 0); // 移动辅助线
  9877. if (!container) {
  9878. return;
  9879. }
  9880. var containerBBox = container.container.getBBox();
  9881. var minX = containerBBox.minX,
  9882. minY = containerBBox.minY,
  9883. width = containerBBox.width,
  9884. height = containerBBox.height;
  9885. var tl = plotRange.tl,
  9886. tr = plotRange.tr;
  9887. var posX = 0;
  9888. var posY = tl.y - height - GAP + offsetY; // 垂直方向贴着图表绘图区域上方边缘
  9889. if (fixed) {
  9890. var x = (tl.x + tr.x) / 2;
  9891. posX = x - width / 2 + offsetX;
  9892. } else {
  9893. var _x = void 0;
  9894. if (items.length > 1) {
  9895. _x = (items[0].x + items[items.length - 1].x) / 2;
  9896. } else {
  9897. _x = items[0].x;
  9898. }
  9899. posX = _x - width / 2 + offsetX;
  9900. // 调整位置,始终位于图表范围内
  9901. if (posX < tl.x) {
  9902. posX = tl.x;
  9903. }
  9904. if (posX + width > tr.x) {
  9905. posX = tr.x - width;
  9906. }
  9907. // if (posY < 0) {
  9908. // posY = 0;
  9909. // }
  9910. if (tooltipArrow) {
  9911. tooltipArrow.attr('points', [{ x: _x - 3, y: tl.y - GAP + offsetY }, { x: _x + 3, y: tl.y - GAP + offsetY }, { x: _x, y: tl.y + offsetY }]);
  9912. var backShape = container.backShape;
  9913. var radius = Util.parsePadding(backShape.attr('radius'));
  9914. if (_x === tl.x) {
  9915. radius[3] = 0;
  9916. tooltipArrow.attr('points', [{ x: tl.x, y: tl.y + offsetY }, { x: tl.x, y: tl.y - GAP + offsetY }, { x: tl.x + GAP, y: tl.y - GAP + offsetY }]);
  9917. } else if (_x === tr.x) {
  9918. radius[2] = 0;
  9919. tooltipArrow.attr('points', [{ x: tr.x, y: tl.y + offsetY }, { x: tr.x - GAP, y: tl.y - GAP + offsetY }, { x: tr.x, y: tl.y - GAP + offsetY }]);
  9920. }
  9921. backShape.attr('radius', radius);
  9922. }
  9923. }
  9924. container.moveTo(posX - minX, posY - minY);
  9925. };
  9926. Tooltip.prototype.setMarkers = function setMarkers() {
  9927. var cfg = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  9928. var self = this;
  9929. var items = cfg.items,
  9930. style = cfg.style,
  9931. type = cfg.type;
  9932. var markerGroup = self._getMarkerGroup(type);
  9933. if (type === 'circle') {
  9934. for (var i = 0, length = items.length; i < length; i++) {
  9935. var item = items[i];
  9936. var marker = new Marker({
  9937. className: 'tooltip-circle-marker',
  9938. attrs: Util.mix({
  9939. x: item.x,
  9940. y: item.y,
  9941. stroke: item.color
  9942. }, style)
  9943. });
  9944. markerGroup.add(marker);
  9945. }
  9946. } else {
  9947. markerGroup.addShape('rect', {
  9948. className: 'tooltip-rect-marker',
  9949. attrs: style
  9950. });
  9951. }
  9952. };
  9953. Tooltip.prototype.clearMarkers = function clearMarkers() {
  9954. var markerGroup = this.markerGroup;
  9955. markerGroup && markerGroup.clear();
  9956. };
  9957. Tooltip.prototype.show = function show() {
  9958. var crosshairsShape = this.crosshairsShape;
  9959. var markerGroup = this.markerGroup;
  9960. var container = this.container;
  9961. var tooltipArrow = this.tooltipArrow;
  9962. var canvas = this.canvas;
  9963. // canvas.sort();
  9964. crosshairsShape && crosshairsShape.show();
  9965. markerGroup && markerGroup.show();
  9966. container && container.show();
  9967. tooltipArrow && tooltipArrow.show();
  9968. canvas.draw();
  9969. };
  9970. Tooltip.prototype.hide = function hide() {
  9971. var crosshairsShape = this.crosshairsShape;
  9972. var markerGroup = this.markerGroup;
  9973. var container = this.container;
  9974. var tooltipArrow = this.tooltipArrow;
  9975. crosshairsShape && crosshairsShape.hide();
  9976. markerGroup && markerGroup.hide();
  9977. container && container.hide();
  9978. tooltipArrow && tooltipArrow.hide();
  9979. };
  9980. Tooltip.prototype.destroy = function destroy() {
  9981. var crosshairsShape = this.crosshairsShape;
  9982. var markerGroup = this.markerGroup;
  9983. var container = this.container;
  9984. var tooltipArrow = this.tooltipArrow;
  9985. crosshairsShape && crosshairsShape.remove(true);
  9986. markerGroup && markerGroup.remove(true);
  9987. container && container.clear();
  9988. tooltipArrow && tooltipArrow.remove(true);
  9989. this.destroyed = true;
  9990. };
  9991. Tooltip.prototype._getMarkerGroup = function _getMarkerGroup(type) {
  9992. var markerGroup = this.markerGroup;
  9993. if (!markerGroup) {
  9994. if (type === 'circle') {
  9995. markerGroup = this.frontPlot.addGroup({
  9996. zIndex: 1
  9997. });
  9998. this.frontPlot.sort();
  9999. } else {
  10000. markerGroup = this.backPlot.addGroup();
  10001. }
  10002. this.markerGroup = markerGroup;
  10003. } else {
  10004. markerGroup.clear();
  10005. }
  10006. return markerGroup;
  10007. };
  10008. return Tooltip;
  10009. }();
  10010. module.exports = Tooltip;
  10011. /***/ }),
  10012. /* 84 */
  10013. /***/ (function(module, exports, __webpack_require__) {
  10014. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  10015. var Util = __webpack_require__(0);
  10016. var Guide = __webpack_require__(9);
  10017. var Global = __webpack_require__(1);
  10018. // register the default configuration for Guide
  10019. Global.guide = Util.deepMix({
  10020. line: {
  10021. style: {
  10022. stroke: '#a3a3a3',
  10023. lineWidth: 1
  10024. },
  10025. top: true
  10026. },
  10027. text: {
  10028. style: {
  10029. fill: '#787878',
  10030. textAlign: 'center',
  10031. textBaseline: 'middle'
  10032. },
  10033. offsetX: 0,
  10034. offsetY: 0,
  10035. top: true
  10036. },
  10037. rect: {
  10038. style: {
  10039. fill: '#fafafa'
  10040. },
  10041. top: false
  10042. },
  10043. arc: {
  10044. style: {
  10045. stroke: '#a3a3a3'
  10046. },
  10047. top: true
  10048. },
  10049. html: {
  10050. offsetX: 0,
  10051. offsetY: 0,
  10052. alignX: 'middle',
  10053. alignY: 'middle'
  10054. },
  10055. tag: {
  10056. top: true,
  10057. offsetX: 0, // X 轴偏移
  10058. offsetY: 0, // Y 轴偏移
  10059. side: 4, // 三角标的边长
  10060. background: {
  10061. padding: 5, // tag 内边距
  10062. radius: 2, // tag 圆角
  10063. fill: '#1890FF' // tag 背景色
  10064. },
  10065. textStyle: {
  10066. fontSize: 12,
  10067. fill: '#fff',
  10068. textAlign: 'center',
  10069. textBaseline: 'middle'
  10070. }
  10071. }
  10072. }, Global.guide || {});
  10073. var GuideController = function () {
  10074. function GuideController(cfg) {
  10075. _classCallCheck(this, GuideController);
  10076. this.guides = [];
  10077. this.xScale = null;
  10078. this.yScales = null;
  10079. this.guideShapes = [];
  10080. Util.mix(this, cfg);
  10081. }
  10082. GuideController.prototype._toString = function _toString(position) {
  10083. if (Util.isFunction(position)) {
  10084. position = position(this.xScale, this.yScales);
  10085. }
  10086. position = position.toString();
  10087. return position;
  10088. };
  10089. GuideController.prototype._getId = function _getId(shape, guide) {
  10090. // 用于标定每一个 guide shape 的 id,主要用于动画
  10091. var id = guide.id;
  10092. if (!id) {
  10093. // 用户未指定
  10094. var type = guide.type;
  10095. if (type === 'arc' || type === 'line' || type === 'rect') {
  10096. id = this._toString(guide.start) + '-' + this._toString(guide.end);
  10097. } else {
  10098. id = this._toString(guide.position);
  10099. }
  10100. }
  10101. return id;
  10102. };
  10103. GuideController.prototype.paint = function paint(coord) {
  10104. var self = this;
  10105. var guides = self.guides;
  10106. var xScale = self.xScale;
  10107. var yScales = self.yScales;
  10108. var guideShapes = [];
  10109. // const ids = [];
  10110. Util.each(guides, function (guide, idx) {
  10111. guide.xScale = xScale;
  10112. guide.yScales = yScales;
  10113. var container = guide.top ? self.frontPlot : self.backPlot;
  10114. var shape = guide.render(coord, container);
  10115. if (shape) {
  10116. var id = self._getId(shape, guide);
  10117. // if (ids.indexOf(id) === -1) { // 防止 ID 重复
  10118. // ids.push(id);
  10119. // } else {
  10120. // id += idx;
  10121. // }
  10122. [].concat(shape).forEach(function (s) {
  10123. s._id = s.get('className') + '-' + id;
  10124. s.set('index', idx);
  10125. guideShapes.push(s);
  10126. });
  10127. }
  10128. });
  10129. self.guideShapes = guideShapes; // TODO: 变量命名
  10130. };
  10131. GuideController.prototype.clear = function clear() {
  10132. this.reset();
  10133. this.guides = [];
  10134. return this;
  10135. };
  10136. GuideController.prototype.reset = function reset() {
  10137. var guides = this.guides;
  10138. Util.each(guides, function (guide) {
  10139. guide.remove();
  10140. });
  10141. };
  10142. GuideController.prototype._createGuide = function _createGuide(type, cfg) {
  10143. var ClassName = Util.upperFirst(type);
  10144. var guide = new Guide[ClassName](Util.deepMix({}, Global.guide[type], cfg));
  10145. this.guides.push(guide);
  10146. return this;
  10147. };
  10148. GuideController.prototype.line = function line() {
  10149. var cfg = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  10150. return this._createGuide('line', cfg);
  10151. };
  10152. GuideController.prototype.text = function text() {
  10153. var cfg = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  10154. return this._createGuide('text', cfg);
  10155. };
  10156. GuideController.prototype.arc = function arc() {
  10157. var cfg = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  10158. return this._createGuide('arc', cfg);
  10159. };
  10160. GuideController.prototype.html = function html() {
  10161. var cfg = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  10162. return this._createGuide('html', cfg);
  10163. };
  10164. GuideController.prototype.rect = function rect() {
  10165. var cfg = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  10166. return this._createGuide('rect', cfg);
  10167. };
  10168. GuideController.prototype.tag = function tag() {
  10169. var cfg = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  10170. return this._createGuide('tag', cfg);
  10171. };
  10172. return GuideController;
  10173. }();
  10174. module.exports = {
  10175. init: function init(chart) {
  10176. var guideController = new GuideController({
  10177. frontPlot: chart.get('frontPlot').addGroup({
  10178. zIndex: 20,
  10179. className: 'guideContainer'
  10180. }),
  10181. backPlot: chart.get('backPlot').addGroup({
  10182. className: 'guideContainer'
  10183. })
  10184. });
  10185. chart.set('guideController', guideController);
  10186. /**
  10187. * 为图表添加 guide
  10188. * @return {GuideController} 返回 guide 控制器
  10189. */
  10190. chart.guide = function () {
  10191. return guideController;
  10192. };
  10193. },
  10194. afterGeomDraw: function afterGeomDraw(chart) {
  10195. var guideController = chart.get('guideController');
  10196. if (!guideController.guides.length) {
  10197. return;
  10198. }
  10199. var xScale = chart.getXScale();
  10200. var yScales = chart.getYScales();
  10201. var coord = chart.get('coord');
  10202. guideController.xScale = xScale;
  10203. guideController.yScales = yScales;
  10204. guideController.paint(coord);
  10205. },
  10206. clear: function clear(chart) {
  10207. chart.get('guideController').clear();
  10208. },
  10209. repaint: function repaint(chart) {
  10210. chart.get('guideController').reset();
  10211. }
  10212. };
  10213. /***/ }),
  10214. /* 85 */
  10215. /***/ (function(module, exports, __webpack_require__) {
  10216. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  10217. var Util = __webpack_require__(0);
  10218. var List = __webpack_require__(67);
  10219. var Global = __webpack_require__(1);
  10220. var LEGEND_GAP = 12;
  10221. var MARKER_SIZE = 3;
  10222. var DEFAULT_CFG = {
  10223. itemMarginBottom: 12,
  10224. itemGap: 10,
  10225. showTitle: false,
  10226. titleStyle: {
  10227. fontSize: 12,
  10228. fill: '#808080',
  10229. textAlign: 'start',
  10230. textBaseline: 'top'
  10231. },
  10232. nameStyle: {
  10233. fill: '#808080',
  10234. fontSize: 12,
  10235. textAlign: 'start',
  10236. textBaseline: 'middle'
  10237. },
  10238. valueStyle: {
  10239. fill: '#000000',
  10240. fontSize: 12,
  10241. textAlign: 'start',
  10242. textBaseline: 'middle'
  10243. },
  10244. unCheckStyle: {
  10245. fill: '#bfbfbf'
  10246. },
  10247. itemWidth: 'auto',
  10248. wordSpace: 6,
  10249. selectedMode: 'multiple' // 'multiple' or 'single'
  10250. };
  10251. // Register the default configuration for Legend
  10252. Global.legend = Util.deepMix({
  10253. right: Util.mix({
  10254. position: 'right',
  10255. layout: 'vertical'
  10256. }, DEFAULT_CFG),
  10257. left: Util.mix({
  10258. position: 'left',
  10259. layout: 'vertical'
  10260. }, DEFAULT_CFG),
  10261. top: Util.mix({
  10262. position: 'top',
  10263. layout: 'horizontal'
  10264. }, DEFAULT_CFG),
  10265. bottom: Util.mix({
  10266. position: 'bottom',
  10267. layout: 'horizontal'
  10268. }, DEFAULT_CFG)
  10269. }, Global.legend || {});
  10270. function getPaddingByPos(pos, appendPadding) {
  10271. var padding = 0;
  10272. appendPadding = Util.parsePadding(appendPadding);
  10273. switch (pos) {
  10274. case 'top':
  10275. padding = appendPadding[0];
  10276. break;
  10277. case 'right':
  10278. padding = appendPadding[1];
  10279. break;
  10280. case 'bottom':
  10281. padding = appendPadding[2];
  10282. break;
  10283. case 'left':
  10284. padding = appendPadding[3];
  10285. break;
  10286. default:
  10287. break;
  10288. }
  10289. return padding;
  10290. }
  10291. var LegendController = function () {
  10292. function LegendController(cfg) {
  10293. _classCallCheck(this, LegendController);
  10294. this.legendCfg = {};
  10295. this.enable = true;
  10296. this.position = 'top';
  10297. Util.mix(this, cfg);
  10298. var chart = this.chart;
  10299. this.canvasDom = chart.get('canvas').get('el');
  10300. this.clear();
  10301. }
  10302. LegendController.prototype.addLegend = function addLegend(scale, items, filterVals) {
  10303. var self = this;
  10304. var legendCfg = self.legendCfg;
  10305. var field = scale.field;
  10306. var fieldCfg = legendCfg[field];
  10307. if (fieldCfg === false) {
  10308. // 如果不显示此图例
  10309. return null;
  10310. }
  10311. if (fieldCfg && fieldCfg.custom) {
  10312. // 自定义图例逻辑
  10313. self.addCustomLegend(field);
  10314. } else {
  10315. var position = legendCfg.position || self.position;
  10316. if (fieldCfg && fieldCfg.position) {
  10317. // 如果对某个图例单独设置 position,则以该 position 为准
  10318. position = fieldCfg.position;
  10319. }
  10320. if (scale.isCategory) {
  10321. // 目前只支持分类
  10322. self._addCategoryLegend(scale, items, position, filterVals);
  10323. }
  10324. }
  10325. };
  10326. LegendController.prototype.addCustomLegend = function addCustomLegend(field) {
  10327. var self = this;
  10328. var legendCfg = self.legendCfg;
  10329. if (field && legendCfg[field]) {
  10330. legendCfg = legendCfg[field];
  10331. }
  10332. var position = legendCfg.position || self.position;
  10333. var legends = self.legends;
  10334. legends[position] = legends[position] || [];
  10335. var items = legendCfg.items;
  10336. if (!items) {
  10337. return null;
  10338. }
  10339. var container = self.container;
  10340. Util.each(items, function (item) {
  10341. if (!Util.isObject(item.marker)) {
  10342. item.marker = {
  10343. symbol: item.marker || 'circle',
  10344. fill: item.fill,
  10345. radius: MARKER_SIZE
  10346. };
  10347. } else {
  10348. item.marker.radius = item.marker.radius || MARKER_SIZE;
  10349. }
  10350. item.checked = Util.isNil(item.checked) ? true : item.checked;
  10351. item.name = item.name || item.value; // 兼容 value 的写法
  10352. });
  10353. var legend = new List(Util.deepMix({}, Global.legend[position], legendCfg, {
  10354. maxLength: self._getMaxLength(position),
  10355. items: items,
  10356. parent: container
  10357. }));
  10358. legends[position].push(legend);
  10359. };
  10360. LegendController.prototype.clear = function clear() {
  10361. var legends = this.legends;
  10362. Util.each(legends, function (legendItems) {
  10363. Util.each(legendItems, function (legend) {
  10364. legend.clear();
  10365. });
  10366. });
  10367. this.legends = {};
  10368. this.unBindEvents();
  10369. };
  10370. LegendController.prototype._isFiltered = function _isFiltered(scale, values, value) {
  10371. var rst = false;
  10372. Util.each(values, function (val) {
  10373. rst = rst || scale.getText(val) === scale.getText(value);
  10374. if (rst) {
  10375. return false;
  10376. }
  10377. });
  10378. return rst;
  10379. };
  10380. LegendController.prototype._getMaxLength = function _getMaxLength(position) {
  10381. var chart = this.chart;
  10382. var appendPadding = Util.parsePadding(chart.get('appendPadding'));
  10383. return position === 'right' || position === 'left' ? chart.get('height') - (appendPadding[0] + appendPadding[2]) : chart.get('width') - (appendPadding[1] + appendPadding[3]);
  10384. };
  10385. LegendController.prototype._addCategoryLegend = function _addCategoryLegend(scale, items, position, filterVals) {
  10386. var self = this;
  10387. var legendCfg = self.legendCfg,
  10388. legends = self.legends,
  10389. container = self.container,
  10390. chart = self.chart;
  10391. var field = scale.field;
  10392. legends[position] = legends[position] || [];
  10393. var symbol = 'circle';
  10394. if (legendCfg[field] && legendCfg[field].marker) {
  10395. // 用户为 field 对应的图例定义了 marker
  10396. symbol = legendCfg[field].marker;
  10397. } else if (legendCfg.marker) {
  10398. symbol = legendCfg.marker;
  10399. }
  10400. Util.each(items, function (item) {
  10401. if (Util.isPlainObject(symbol)) {
  10402. Util.mix(item.marker, symbol);
  10403. } else {
  10404. item.marker.symbol = symbol;
  10405. }
  10406. if (filterVals) {
  10407. item.checked = self._isFiltered(scale, filterVals, item.dataValue);
  10408. }
  10409. });
  10410. // 需要更新图例信息
  10411. var legendItems = chart.get('legendItems');
  10412. legendItems[field] = items;
  10413. var lastCfg = Util.deepMix({}, Global.legend[position], legendCfg[field] || legendCfg, {
  10414. maxLength: self._getMaxLength(position),
  10415. items: items,
  10416. field: field,
  10417. filterVals: filterVals,
  10418. parent: container
  10419. });
  10420. if (lastCfg.showTitle) {
  10421. Util.deepMix(lastCfg, {
  10422. title: scale.alias || scale.field
  10423. });
  10424. }
  10425. var legend = new List(lastCfg);
  10426. legends[position].push(legend);
  10427. return legend;
  10428. };
  10429. LegendController.prototype._alignLegend = function _alignLegend(legend, pre, position) {
  10430. var self = this;
  10431. var _self$plotRange = self.plotRange,
  10432. tl = _self$plotRange.tl,
  10433. bl = _self$plotRange.bl;
  10434. var chart = self.chart;
  10435. var offsetX = legend.offsetX || 0;
  10436. var offsetY = legend.offsetY || 0;
  10437. var chartWidth = chart.get('width');
  10438. var chartHeight = chart.get('height');
  10439. var appendPadding = Util.parsePadding(chart.get('appendPadding'));
  10440. var legendHeight = legend.getHeight();
  10441. var legendWidth = legend.getWidth();
  10442. var x = 0;
  10443. var y = 0;
  10444. if (position === 'left' || position === 'right') {
  10445. // position 为 left、right,默认图例整体居中对齐
  10446. var verticalAlign = legend.verticalAlign || 'middle'; // 图例垂直方向上的对齐方式
  10447. var height = Math.abs(tl.y - bl.y);
  10448. x = position === 'left' ? appendPadding[3] : chartWidth - legendWidth - appendPadding[1];
  10449. y = (height - legendHeight) / 2 + tl.y;
  10450. if (verticalAlign === 'top') {
  10451. y = tl.y;
  10452. } else if (verticalAlign === 'bottom') {
  10453. y = bl.y - legendHeight;
  10454. }
  10455. if (pre) {
  10456. y = pre.get('y') - legendHeight - LEGEND_GAP;
  10457. }
  10458. } else {
  10459. // position 为 top、bottom,图例整体居左对齐
  10460. var align = legend.align || 'left'; // 图例水平方向上的对齐方式
  10461. x = appendPadding[3];
  10462. if (align === 'center') {
  10463. x = chartWidth / 2 - legendWidth / 2;
  10464. } else if (align === 'right') {
  10465. x = chartWidth - (legendWidth + appendPadding[1]);
  10466. }
  10467. y = position === 'top' ? appendPadding[0] + Math.abs(legend.container.getBBox().minY) : chartHeight - legendHeight;
  10468. if (pre) {
  10469. var preWidth = pre.getWidth();
  10470. x = pre.x + preWidth + LEGEND_GAP;
  10471. }
  10472. }
  10473. if (position === 'bottom' && offsetY > 0) {
  10474. offsetY = 0;
  10475. }
  10476. if (position === 'right' && offsetX > 0) {
  10477. offsetX = 0;
  10478. }
  10479. legend.moveTo(x + offsetX, y + offsetY);
  10480. };
  10481. LegendController.prototype.alignLegends = function alignLegends() {
  10482. var self = this;
  10483. var legends = self.legends;
  10484. Util.each(legends, function (legendItems, position) {
  10485. Util.each(legendItems, function (legend, index) {
  10486. var pre = legendItems[index - 1];
  10487. self._alignLegend(legend, pre, position);
  10488. });
  10489. });
  10490. return self;
  10491. };
  10492. LegendController.prototype.handleEvent = function handleEvent(ev) {
  10493. var self = this;
  10494. function findItem(x, y) {
  10495. var result = null;
  10496. var legends = self.legends;
  10497. Util.each(legends, function (legendItems) {
  10498. Util.each(legendItems, function (legend) {
  10499. var itemsGroup = legend.itemsGroup,
  10500. legendHitBoxes = legend.legendHitBoxes;
  10501. var children = itemsGroup.get('children');
  10502. if (children.length) {
  10503. var legendPosX = legend.x;
  10504. var legendPosY = legend.y;
  10505. Util.each(legendHitBoxes, function (box, index) {
  10506. if (x >= box.x + legendPosX && x <= box.x + box.width + legendPosX && y >= box.y + legendPosY && y <= box.height + box.y + legendPosY) {
  10507. // inbox
  10508. result = {
  10509. clickedItem: children[index],
  10510. clickedLegend: legend
  10511. };
  10512. return false;
  10513. }
  10514. });
  10515. }
  10516. });
  10517. });
  10518. return result;
  10519. }
  10520. var chart = self.chart;
  10521. var _Util$createEvent = Util.createEvent(ev, chart),
  10522. x = _Util$createEvent.x,
  10523. y = _Util$createEvent.y;
  10524. var clicked = findItem(x, y);
  10525. if (clicked && clicked.clickedLegend.clickable !== false) {
  10526. var clickedItem = clicked.clickedItem,
  10527. clickedLegend = clicked.clickedLegend;
  10528. if (clickedLegend.onClick) {
  10529. // 用户自定义点击行为
  10530. ev.clickedItem = clickedItem;
  10531. clickedLegend.onClick(ev);
  10532. } else if (!clickedLegend.custom) {
  10533. // 进入组件默认事件处理逻辑
  10534. var checked = clickedItem.get('checked');
  10535. var value = clickedItem.get('dataValue');
  10536. var filterVals = clickedLegend.filterVals,
  10537. field = clickedLegend.field,
  10538. selectedMode = clickedLegend.selectedMode;
  10539. var isSingeSelected = selectedMode === 'single';
  10540. if (isSingeSelected) {
  10541. chart.filter(field, function (val) {
  10542. return val === value;
  10543. });
  10544. } else {
  10545. if (!checked) {
  10546. filterVals.push(value);
  10547. } else {
  10548. Util.Array.remove(filterVals, value);
  10549. }
  10550. chart.filter(field, function (val) {
  10551. return filterVals.indexOf(val) !== -1;
  10552. });
  10553. }
  10554. chart.repaint();
  10555. }
  10556. }
  10557. };
  10558. LegendController.prototype.bindEvents = function bindEvents() {
  10559. var legendCfg = this.legendCfg;
  10560. var triggerOn = legendCfg.triggerOn || 'touchstart';
  10561. var method = Util.wrapBehavior(this, 'handleEvent');
  10562. Util.addEventListener(this.canvasDom, triggerOn, method);
  10563. };
  10564. LegendController.prototype.unBindEvents = function unBindEvents() {
  10565. var legendCfg = this.legendCfg;
  10566. var triggerOn = legendCfg.triggerOn || 'touchstart';
  10567. var method = Util.getWrapBehavior(this, 'handleEvent');
  10568. Util.removeEventListener(this.canvasDom, triggerOn, method);
  10569. };
  10570. return LegendController;
  10571. }();
  10572. module.exports = {
  10573. init: function init(chart) {
  10574. var legendController = new LegendController({
  10575. container: chart.get('backPlot'),
  10576. plotRange: chart.get('plotRange'),
  10577. chart: chart
  10578. });
  10579. chart.set('legendController', legendController);
  10580. /**
  10581. * 设置图例
  10582. * @chainable
  10583. * @param {Boolean|String|Object} field Boolean 表示关闭开启图例,String 表示指定具体的图例,Object 表示为所有的图例设置
  10584. * @param {Object|Boolean} cfg 图例的配置,Object 表示为对应的图例进行配置,Boolean 表示关闭对应的图例
  10585. * @return {Chart} 返回当前 chart 的引用
  10586. */
  10587. chart.legend = function (field, cfg) {
  10588. var legendCfg = legendController.legendCfg;
  10589. legendController.enable = true;
  10590. if (Util.isBoolean(field)) {
  10591. legendController.enable = field;
  10592. legendCfg = cfg || {};
  10593. } else if (Util.isObject(field)) {
  10594. legendCfg = field;
  10595. } else {
  10596. legendCfg[field] = cfg;
  10597. }
  10598. legendController.legendCfg = legendCfg;
  10599. return this;
  10600. };
  10601. },
  10602. beforeGeomDraw: function beforeGeomDraw(chart) {
  10603. var legendController = chart.get('legendController');
  10604. if (!legendController.enable) return null; // legend is not displayed
  10605. var legendCfg = legendController.legendCfg;
  10606. if (legendCfg && legendCfg.custom) {
  10607. // 用户自定义图例
  10608. legendController.addCustomLegend();
  10609. } else {
  10610. var legendItems = chart.getLegendItems();
  10611. var scales = chart.get('scales');
  10612. var filters = chart.get('filters');
  10613. Util.each(legendItems, function (items, field) {
  10614. var scale = scales[field];
  10615. var values = scale.values;
  10616. var filterVals = void 0;
  10617. if (filters && filters[field]) {
  10618. filterVals = values.filter(filters[field]);
  10619. } else {
  10620. filterVals = values.slice(0);
  10621. }
  10622. legendController.addLegend(scale, items, filterVals);
  10623. });
  10624. }
  10625. if (legendCfg && legendCfg.clickable !== false) {
  10626. legendController.bindEvents();
  10627. }
  10628. var legends = legendController.legends;
  10629. var legendRange = {
  10630. top: 0,
  10631. right: 0,
  10632. bottom: 0,
  10633. left: 0
  10634. };
  10635. Util.each(legends, function (legendItems, position) {
  10636. var padding = 0;
  10637. Util.each(legendItems, function (legend) {
  10638. var width = legend.getWidth();
  10639. var height = legend.getHeight();
  10640. if (position === 'top' || position === 'bottom') {
  10641. padding = Math.max(padding, height);
  10642. if (legend.offsetY > 0) {
  10643. padding += legend.offsetY;
  10644. }
  10645. } else {
  10646. padding = Math.max(padding, width);
  10647. if (legend.offsetX > 0) {
  10648. padding += legend.offsetX;
  10649. }
  10650. }
  10651. });
  10652. legendRange[position] = padding + getPaddingByPos(position, chart.get('appendPadding'));
  10653. });
  10654. chart.set('legendRange', legendRange);
  10655. },
  10656. afterGeomDraw: function afterGeomDraw(chart) {
  10657. var legendController = chart.get('legendController');
  10658. legendController.alignLegends();
  10659. },
  10660. clearInner: function clearInner(chart) {
  10661. var legendController = chart.get('legendController');
  10662. legendController.clear();
  10663. chart.set('legendRange', null);
  10664. }
  10665. };
  10666. /***/ }),
  10667. /* 86 */,
  10668. /* 87 */,
  10669. /* 88 */,
  10670. /* 89 */,
  10671. /* 90 */,
  10672. /* 91 */,
  10673. /* 92 */,
  10674. /* 93 */,
  10675. /* 94 */,
  10676. /* 95 */,
  10677. /* 96 */,
  10678. /* 97 */,
  10679. /* 98 */,
  10680. /* 99 */,
  10681. /* 100 */,
  10682. /* 101 */
  10683. /***/ (function(module, exports, __webpack_require__) {
  10684. /**
  10685. * 包含常用的图表类型、图表组件(tooltip、legend 以及 guide)
  10686. */
  10687. var F2 = __webpack_require__(27); // 核心包
  10688. __webpack_require__(70); // 面积图
  10689. __webpack_require__(59); // 折线图
  10690. __webpack_require__(60); // 柱状图
  10691. __webpack_require__(68); // 点图
  10692. __webpack_require__(62); // 数据调整
  10693. __webpack_require__(65); // 极坐标系
  10694. __webpack_require__(72); // 极坐标系下的弧长坐标轴
  10695. __webpack_require__(73); // timeCat 类型的度量
  10696. __webpack_require__(75); // 加载 guide 组件
  10697. F2.Plugin = {
  10698. Tooltip: __webpack_require__(82),
  10699. Guide: __webpack_require__(84),
  10700. Legend: __webpack_require__(85)
  10701. };
  10702. // 注册插件
  10703. var _F2$Plugin = F2.Plugin,
  10704. Tooltip = _F2$Plugin.Tooltip,
  10705. Legend = _F2$Plugin.Legend,
  10706. Guide = _F2$Plugin.Guide;
  10707. F2.Chart.plugins.register([Tooltip, Legend, Guide]);
  10708. module.exports = F2;
  10709. /***/ })
  10710. /******/ ]);
  10711. });