u-charts.js 274 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335
  1. /*
  2. * uCharts (R)
  3. * 高性能跨平台图表库,支持H5、APP、小程序(微信/支付宝/百度/头条/QQ/360/快手)、Vue、Taro等支持canvas的框架平台
  4. * Copyright (C) 2018-2022 QIUN (R) 秋云 https://www.ucharts.cn All rights reserved.
  5. * Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
  6. * 复制使用请保留本段注释,感谢支持开源!
  7. *
  8. * uCharts (R) 官方网站
  9. * https://www.uCharts.cn
  10. *
  11. * 开源地址:
  12. * https://gitee.com/uCharts/uCharts
  13. *
  14. * uni-app插件市场地址:
  15. * http://ext.dcloud.net.cn/plugin?id=271
  16. *
  17. */
  18. 'use strict';
  19. var config = {
  20. version: 'v2.4.4-20221102',
  21. yAxisWidth: 15,
  22. xAxisHeight: 22,
  23. xAxisTextPadding: 3,
  24. padding: [10, 10, 10, 10],
  25. pixelRatio: 1,
  26. rotate: false,
  27. fontSize: 13,
  28. fontColor: '#666666',
  29. dataPointShape: ['circle', 'circle', 'circle', 'circle'],
  30. color: ['#1890FF', '#91CB74', '#FAC858', '#EE6666', '#73C0DE', '#3CA272', '#FC8452', '#9A60B4', '#ea7ccc'],
  31. linearColor: ['#0EE2F8', '#2BDCA8', '#FA7D8D', '#EB88E2', '#2AE3A0', '#0EE2F8', '#EB88E2', '#6773E3', '#F78A85'],
  32. pieChartLinePadding: 15,
  33. pieChartTextPadding: 5,
  34. titleFontSize: 20,
  35. subtitleFontSize: 15,
  36. toolTipPadding: 3,
  37. toolTipBackground: '#000000',
  38. toolTipOpacity: 0.7,
  39. toolTipLineHeight: 20,
  40. radarLabelTextMargin: 13,
  41. };
  42. var assign = function(target, ...varArgs) {
  43. if (target == null) {
  44. throw new TypeError('[uCharts] Cannot convert undefined or null to object');
  45. }
  46. if (!varArgs || varArgs.length <= 0) {
  47. return target;
  48. }
  49. // 深度合并对象
  50. function deepAssign(obj1, obj2) {
  51. for (let key in obj2) {
  52. obj1[key] = obj1[key] && obj1[key].toString() === "[object Object]" ?
  53. deepAssign(obj1[key], obj2[key]) : obj1[key] = obj2[key];
  54. }
  55. return obj1;
  56. }
  57. varArgs.forEach(val => {
  58. target = deepAssign(target, val);
  59. });
  60. return target;
  61. };
  62. var util = {
  63. toFixed: function toFixed(num, limit) {
  64. limit = limit || 2;
  65. if (this.isFloat(num)) {
  66. num = num.toFixed(limit);
  67. }
  68. return num;
  69. },
  70. isFloat: function isFloat(num) {
  71. return num % 1 !== 0;
  72. },
  73. approximatelyEqual: function approximatelyEqual(num1, num2) {
  74. return Math.abs(num1 - num2) < 1e-10;
  75. },
  76. isSameSign: function isSameSign(num1, num2) {
  77. return Math.abs(num1) === num1 && Math.abs(num2) === num2 || Math.abs(num1) !== num1 && Math.abs(num2) !== num2;
  78. },
  79. isSameXCoordinateArea: function isSameXCoordinateArea(p1, p2) {
  80. return this.isSameSign(p1.x, p2.x);
  81. },
  82. isCollision: function isCollision(obj1, obj2) {
  83. obj1.end = {};
  84. obj1.end.x = obj1.start.x + obj1.width;
  85. obj1.end.y = obj1.start.y - obj1.height;
  86. obj2.end = {};
  87. obj2.end.x = obj2.start.x + obj2.width;
  88. obj2.end.y = obj2.start.y - obj2.height;
  89. var flag = obj2.start.x > obj1.end.x || obj2.end.x < obj1.start.x || obj2.end.y > obj1.start.y || obj2.start.y < obj1.end.y;
  90. return !flag;
  91. }
  92. };
  93. //兼容H5点击事件
  94. function getH5Offset(e) {
  95. e.mp = {
  96. changedTouches: []
  97. };
  98. e.mp.changedTouches.push({
  99. x: e.offsetX,
  100. y: e.offsetY
  101. });
  102. return e;
  103. }
  104. // hex 转 rgba
  105. function hexToRgb(hexValue, opc) {
  106. var rgx = /^#?([a-f\d])([a-f\d])([a-f\d])$/i;
  107. var hex = hexValue.replace(rgx, function(m, r, g, b) {
  108. return r + r + g + g + b + b;
  109. });
  110. var rgb = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
  111. var r = parseInt(rgb[1], 16);
  112. var g = parseInt(rgb[2], 16);
  113. var b = parseInt(rgb[3], 16);
  114. return 'rgba(' + r + ',' + g + ',' + b + ',' + opc + ')';
  115. }
  116. function findRange(num, type, limit) {
  117. if (isNaN(num)) {
  118. throw new Error('[uCharts] series数据需为Number格式');
  119. }
  120. limit = limit || 10;
  121. type = type ? type : 'upper';
  122. var multiple = 1;
  123. while (limit < 1) {
  124. limit *= 10;
  125. multiple *= 10;
  126. }
  127. if (type === 'upper') {
  128. num = Math.ceil(num * multiple);
  129. } else {
  130. num = Math.floor(num * multiple);
  131. }
  132. while (num % limit !== 0) {
  133. if (type === 'upper') {
  134. if (num == num + 1) { //修复数据值过大num++无效的bug by 向日葵 @xrk_jy
  135. break;
  136. }
  137. num++;
  138. } else {
  139. num--;
  140. }
  141. }
  142. return num / multiple;
  143. }
  144. function calCandleMA(dayArr, nameArr, colorArr, kdata) {
  145. let seriesTemp = [];
  146. for (let k = 0; k < dayArr.length; k++) {
  147. let seriesItem = {
  148. data: [],
  149. name: nameArr[k],
  150. color: colorArr[k]
  151. };
  152. for (let i = 0, len = kdata.length; i < len; i++) {
  153. if (i < dayArr[k]) {
  154. seriesItem.data.push(null);
  155. continue;
  156. }
  157. let sum = 0;
  158. for (let j = 0; j < dayArr[k]; j++) {
  159. sum += kdata[i - j][1];
  160. }
  161. seriesItem.data.push(+(sum / dayArr[k]).toFixed(3));
  162. }
  163. seriesTemp.push(seriesItem);
  164. }
  165. return seriesTemp;
  166. }
  167. function calValidDistance(self, distance, chartData, config, opts) {
  168. var dataChartAreaWidth = opts.width - opts.area[1] - opts.area[3];
  169. var dataChartWidth = chartData.eachSpacing * (opts.chartData.xAxisData.xAxisPoints.length - 1);
  170. if(opts.type == 'mount' && opts.extra && opts.extra.mount && opts.extra.mount.widthRatio && opts.extra.mount.widthRatio > 1){
  171. if(opts.extra.mount.widthRatio>2) opts.extra.mount.widthRatio = 2
  172. dataChartWidth += (opts.extra.mount.widthRatio - 1)*chartData.eachSpacing;
  173. }
  174. var validDistance = distance;
  175. if (distance >= 0) {
  176. validDistance = 0;
  177. self.uevent.trigger('scrollLeft');
  178. self.scrollOption.position = 'left'
  179. opts.xAxis.scrollPosition = 'left';
  180. } else if (Math.abs(distance) >= dataChartWidth - dataChartAreaWidth) {
  181. validDistance = dataChartAreaWidth - dataChartWidth;
  182. self.uevent.trigger('scrollRight');
  183. self.scrollOption.position = 'right'
  184. opts.xAxis.scrollPosition = 'right';
  185. } else {
  186. self.scrollOption.position = distance
  187. opts.xAxis.scrollPosition = distance;
  188. }
  189. return validDistance;
  190. }
  191. function isInAngleRange(angle, startAngle, endAngle) {
  192. function adjust(angle) {
  193. while (angle < 0) {
  194. angle += 2 * Math.PI;
  195. }
  196. while (angle > 2 * Math.PI) {
  197. angle -= 2 * Math.PI;
  198. }
  199. return angle;
  200. }
  201. angle = adjust(angle);
  202. startAngle = adjust(startAngle);
  203. endAngle = adjust(endAngle);
  204. if (startAngle > endAngle) {
  205. endAngle += 2 * Math.PI;
  206. if (angle < startAngle) {
  207. angle += 2 * Math.PI;
  208. }
  209. }
  210. return angle >= startAngle && angle <= endAngle;
  211. }
  212. function createCurveControlPoints(points, i) {
  213. function isNotMiddlePoint(points, i) {
  214. if (points[i - 1] && points[i + 1]) {
  215. return points[i].y >= Math.max(points[i - 1].y, points[i + 1].y) || points[i].y <= Math.min(points[i - 1].y,
  216. points[i + 1].y);
  217. } else {
  218. return false;
  219. }
  220. }
  221. function isNotMiddlePointX(points, i) {
  222. if (points[i - 1] && points[i + 1]) {
  223. return points[i].x >= Math.max(points[i - 1].x, points[i + 1].x) || points[i].x <= Math.min(points[i - 1].x,
  224. points[i + 1].x);
  225. } else {
  226. return false;
  227. }
  228. }
  229. var a = 0.2;
  230. var b = 0.2;
  231. var pAx = null;
  232. var pAy = null;
  233. var pBx = null;
  234. var pBy = null;
  235. if (i < 1) {
  236. pAx = points[0].x + (points[1].x - points[0].x) * a;
  237. pAy = points[0].y + (points[1].y - points[0].y) * a;
  238. } else {
  239. pAx = points[i].x + (points[i + 1].x - points[i - 1].x) * a;
  240. pAy = points[i].y + (points[i + 1].y - points[i - 1].y) * a;
  241. }
  242. if (i > points.length - 3) {
  243. var last = points.length - 1;
  244. pBx = points[last].x - (points[last].x - points[last - 1].x) * b;
  245. pBy = points[last].y - (points[last].y - points[last - 1].y) * b;
  246. } else {
  247. pBx = points[i + 1].x - (points[i + 2].x - points[i].x) * b;
  248. pBy = points[i + 1].y - (points[i + 2].y - points[i].y) * b;
  249. }
  250. if (isNotMiddlePoint(points, i + 1)) {
  251. pBy = points[i + 1].y;
  252. }
  253. if (isNotMiddlePoint(points, i)) {
  254. pAy = points[i].y;
  255. }
  256. if (isNotMiddlePointX(points, i + 1)) {
  257. pBx = points[i + 1].x;
  258. }
  259. if (isNotMiddlePointX(points, i)) {
  260. pAx = points[i].x;
  261. }
  262. if (pAy >= Math.max(points[i].y, points[i + 1].y) || pAy <= Math.min(points[i].y, points[i + 1].y)) {
  263. pAy = points[i].y;
  264. }
  265. if (pBy >= Math.max(points[i].y, points[i + 1].y) || pBy <= Math.min(points[i].y, points[i + 1].y)) {
  266. pBy = points[i + 1].y;
  267. }
  268. if (pAx >= Math.max(points[i].x, points[i + 1].x) || pAx <= Math.min(points[i].x, points[i + 1].x)) {
  269. pAx = points[i].x;
  270. }
  271. if (pBx >= Math.max(points[i].x, points[i + 1].x) || pBx <= Math.min(points[i].x, points[i + 1].x)) {
  272. pBx = points[i + 1].x;
  273. }
  274. return {
  275. ctrA: {
  276. x: pAx,
  277. y: pAy
  278. },
  279. ctrB: {
  280. x: pBx,
  281. y: pBy
  282. }
  283. };
  284. }
  285. function convertCoordinateOrigin(x, y, center) {
  286. return {
  287. x: center.x + x,
  288. y: center.y - y
  289. };
  290. }
  291. function avoidCollision(obj, target) {
  292. if (target) {
  293. // is collision test
  294. while (util.isCollision(obj, target)) {
  295. if (obj.start.x > 0) {
  296. obj.start.y--;
  297. } else if (obj.start.x < 0) {
  298. obj.start.y++;
  299. } else {
  300. if (obj.start.y > 0) {
  301. obj.start.y++;
  302. } else {
  303. obj.start.y--;
  304. }
  305. }
  306. }
  307. }
  308. return obj;
  309. }
  310. function fixPieSeries(series, opts, config){
  311. let pieSeriesArr = [];
  312. if(series.length>0 && series[0].data.constructor.toString().indexOf('Array') > -1){
  313. opts._pieSeries_ = series;
  314. let oldseries = series[0].data;
  315. for (var i = 0; i < oldseries.length; i++) {
  316. oldseries[i].formatter = series[0].formatter;
  317. oldseries[i].data = oldseries[i].value;
  318. pieSeriesArr.push(oldseries[i]);
  319. }
  320. opts.series = pieSeriesArr;
  321. }else{
  322. pieSeriesArr = series;
  323. }
  324. return pieSeriesArr;
  325. }
  326. function fillSeries(series, opts, config) {
  327. var index = 0;
  328. for (var i = 0; i < series.length; i++) {
  329. let item = series[i];
  330. if (!item.color) {
  331. item.color = config.color[index];
  332. index = (index + 1) % config.color.length;
  333. }
  334. if (!item.linearIndex) {
  335. item.linearIndex = i;
  336. }
  337. if (!item.index) {
  338. item.index = 0;
  339. }
  340. if (!item.type) {
  341. item.type = opts.type;
  342. }
  343. if (typeof item.show == "undefined") {
  344. item.show = true;
  345. }
  346. if (!item.type) {
  347. item.type = opts.type;
  348. }
  349. if (!item.pointShape) {
  350. item.pointShape = "circle";
  351. }
  352. if (!item.legendShape) {
  353. switch (item.type) {
  354. case 'line':
  355. item.legendShape = "line";
  356. break;
  357. case 'column':
  358. case 'bar':
  359. item.legendShape = "rect";
  360. break;
  361. case 'area':
  362. case 'mount':
  363. item.legendShape = "triangle";
  364. break;
  365. default:
  366. item.legendShape = "circle";
  367. }
  368. }
  369. }
  370. return series;
  371. }
  372. function fillCustomColor(linearType, customColor, series, config) {
  373. var newcolor = customColor || [];
  374. if (linearType == 'custom' && newcolor.length == 0 ) {
  375. newcolor = config.linearColor;
  376. }
  377. if (linearType == 'custom' && newcolor.length < series.length) {
  378. let chazhi = series.length - newcolor.length;
  379. for (var i = 0; i < chazhi; i++) {
  380. newcolor.push(config.linearColor[(i + 1) % config.linearColor.length]);
  381. }
  382. }
  383. return newcolor;
  384. }
  385. function getDataRange(minData, maxData) {
  386. var limit = 0;
  387. var range = maxData - minData;
  388. if (range >= 10000) {
  389. limit = 1000;
  390. } else if (range >= 1000) {
  391. limit = 100;
  392. } else if (range >= 100) {
  393. limit = 10;
  394. } else if (range >= 10) {
  395. limit = 5;
  396. } else if (range >= 1) {
  397. limit = 1;
  398. } else if (range >= 0.1) {
  399. limit = 0.1;
  400. } else if (range >= 0.01) {
  401. limit = 0.01;
  402. } else if (range >= 0.001) {
  403. limit = 0.001;
  404. } else if (range >= 0.0001) {
  405. limit = 0.0001;
  406. } else if (range >= 0.00001) {
  407. limit = 0.00001;
  408. } else {
  409. limit = 0.000001;
  410. }
  411. return {
  412. minRange: findRange(minData, 'lower', limit),
  413. maxRange: findRange(maxData, 'upper', limit)
  414. };
  415. }
  416. function measureText(text, fontSize, context) {
  417. var width = 0;
  418. text = String(text);
  419. // #ifdef MP-ALIPAY || MP-BAIDU || APP-NVUE
  420. context = false;
  421. // #endif
  422. if (context !== false && context !== undefined && context.setFontSize && context.measureText) {
  423. context.setFontSize(fontSize);
  424. return context.measureText(text).width;
  425. } else {
  426. var text = text.split('');
  427. for (let i = 0; i < text.length; i++) {
  428. let item = text[i];
  429. if (/[a-zA-Z]/.test(item)) {
  430. width += 7;
  431. } else if (/[0-9]/.test(item)) {
  432. width += 5.5;
  433. } else if (/\./.test(item)) {
  434. width += 2.7;
  435. } else if (/-/.test(item)) {
  436. width += 3.25;
  437. } else if (/:/.test(item)) {
  438. width += 2.5;
  439. } else if (/[\u4e00-\u9fa5]/.test(item)) {
  440. width += 10;
  441. } else if (/\(|\)/.test(item)) {
  442. width += 3.73;
  443. } else if (/\s/.test(item)) {
  444. width += 2.5;
  445. } else if (/%/.test(item)) {
  446. width += 8;
  447. } else {
  448. width += 10;
  449. }
  450. }
  451. return width * fontSize / 10;
  452. }
  453. }
  454. function dataCombine(series) {
  455. return series.reduce(function(a, b) {
  456. return (a.data ? a.data : a).concat(b.data);
  457. }, []);
  458. }
  459. function dataCombineStack(series, len) {
  460. var sum = new Array(len);
  461. for (var j = 0; j < sum.length; j++) {
  462. sum[j] = 0;
  463. }
  464. for (var i = 0; i < series.length; i++) {
  465. for (var j = 0; j < sum.length; j++) {
  466. sum[j] += series[i].data[j];
  467. }
  468. }
  469. return series.reduce(function(a, b) {
  470. return (a.data ? a.data : a).concat(b.data).concat(sum);
  471. }, []);
  472. }
  473. function getTouches(touches, opts, e) {
  474. let x, y;
  475. if (touches.clientX) {
  476. if (opts.rotate) {
  477. y = opts.height - touches.clientX * opts.pix;
  478. x = (touches.pageY - e.currentTarget.offsetTop - (opts.height / opts.pix / 2) * (opts.pix - 1)) * opts.pix;
  479. } else {
  480. x = touches.clientX * opts.pix;
  481. y = (touches.pageY - e.currentTarget.offsetTop - (opts.height / opts.pix / 2) * (opts.pix - 1)) * opts.pix;
  482. }
  483. } else {
  484. if (opts.rotate) {
  485. y = opts.height - touches.x * opts.pix;
  486. x = touches.y * opts.pix;
  487. } else {
  488. x = touches.x * opts.pix;
  489. y = touches.y * opts.pix;
  490. }
  491. }
  492. return {
  493. x: x,
  494. y: y
  495. }
  496. }
  497. function getSeriesDataItem(series, index, group) {
  498. var data = [];
  499. var newSeries = [];
  500. var indexIsArr = index.constructor.toString().indexOf('Array') > -1;
  501. if(indexIsArr){
  502. let tempSeries = filterSeries(series);
  503. for (var i = 0; i < group.length; i++) {
  504. newSeries.push(tempSeries[group[i]]);
  505. }
  506. }else{
  507. newSeries = series;
  508. };
  509. for (let i = 0; i < newSeries.length; i++) {
  510. let item = newSeries[i];
  511. let tmpindex = -1;
  512. if(indexIsArr){
  513. tmpindex = index[i];
  514. }else{
  515. tmpindex = index;
  516. }
  517. if (item.data[tmpindex] !== null && typeof item.data[tmpindex] !== 'undefined' && item.show) {
  518. let seriesItem = {};
  519. seriesItem.color = item.color;
  520. seriesItem.type = item.type;
  521. seriesItem.style = item.style;
  522. seriesItem.pointShape = item.pointShape;
  523. seriesItem.disableLegend = item.disableLegend;
  524. seriesItem.name = item.name;
  525. seriesItem.show = item.show;
  526. seriesItem.data = item.formatter ? item.formatter(item.data[tmpindex]) : item.data[tmpindex];
  527. data.push(seriesItem);
  528. }
  529. }
  530. return data;
  531. }
  532. function getMaxTextListLength(list, fontSize, context) {
  533. var lengthList = list.map(function(item) {
  534. return measureText(item, fontSize, context);
  535. });
  536. return Math.max.apply(null, lengthList);
  537. }
  538. function getRadarCoordinateSeries(length) {
  539. var eachAngle = 2 * Math.PI / length;
  540. var CoordinateSeries = [];
  541. for (var i = 0; i < length; i++) {
  542. CoordinateSeries.push(eachAngle * i);
  543. }
  544. return CoordinateSeries.map(function(item) {
  545. return -1 * item + Math.PI / 2;
  546. });
  547. }
  548. function getToolTipData(seriesData, opts, index, group, categories) {
  549. var option = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : {};
  550. var calPoints = opts.chartData.calPoints?opts.chartData.calPoints:[];
  551. let points = {};
  552. if(group.length > 0){
  553. let filterPoints = [];
  554. for (let i = 0; i < group.length; i++) {
  555. filterPoints.push(calPoints[group[i]])
  556. }
  557. points = filterPoints[0][index[0]];
  558. }else{
  559. for (let i = 0; i < calPoints.length; i++) {
  560. if(calPoints[i][index]){
  561. points = calPoints[i][index];
  562. break;
  563. }
  564. }
  565. };
  566. var textList = seriesData.map(function(item) {
  567. let titleText = null;
  568. if (opts.categories && opts.categories.length>0) {
  569. titleText = categories[index];
  570. };
  571. return {
  572. text: option.formatter ? option.formatter(item, titleText, index, opts) : item.name + ': ' + item.data,
  573. color: item.color
  574. };
  575. });
  576. var offset = {
  577. x: Math.round(points.x),
  578. y: Math.round(points.y)
  579. };
  580. return {
  581. textList: textList,
  582. offset: offset
  583. };
  584. }
  585. function getMixToolTipData(seriesData, opts, index, categories) {
  586. var option = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : {};
  587. var points = opts.chartData.xAxisPoints[index] + opts.chartData.eachSpacing / 2;
  588. var textList = seriesData.map(function(item) {
  589. return {
  590. text: option.formatter ? option.formatter(item, categories[index], index, opts) : item.name + ': ' + item.data,
  591. color: item.color,
  592. disableLegend: item.disableLegend ? true : false
  593. };
  594. });
  595. textList = textList.filter(function(item) {
  596. if (item.disableLegend !== true) {
  597. return item;
  598. }
  599. });
  600. var offset = {
  601. x: Math.round(points),
  602. y: 0
  603. };
  604. return {
  605. textList: textList,
  606. offset: offset
  607. };
  608. }
  609. function getCandleToolTipData(series, seriesData, opts, index, categories, extra) {
  610. var option = arguments.length > 6 && arguments[6] !== undefined ? arguments[6] : {};
  611. var calPoints = opts.chartData.calPoints;
  612. let upColor = extra.color.upFill;
  613. let downColor = extra.color.downFill;
  614. //颜色顺序为开盘,收盘,最低,最高
  615. let color = [upColor, upColor, downColor, upColor];
  616. var textList = [];
  617. seriesData.map(function(item) {
  618. if (index == 0) {
  619. if (item.data[1] - item.data[0] < 0) {
  620. color[1] = downColor;
  621. } else {
  622. color[1] = upColor;
  623. }
  624. } else {
  625. if (item.data[0] < series[index - 1][1]) {
  626. color[0] = downColor;
  627. }
  628. if (item.data[1] < item.data[0]) {
  629. color[1] = downColor;
  630. }
  631. if (item.data[2] > series[index - 1][1]) {
  632. color[2] = upColor;
  633. }
  634. if (item.data[3] < series[index - 1][1]) {
  635. color[3] = downColor;
  636. }
  637. }
  638. let text1 = {
  639. text: '开盘:' + item.data[0],
  640. color: color[0]
  641. };
  642. let text2 = {
  643. text: '收盘:' + item.data[1],
  644. color: color[1]
  645. };
  646. let text3 = {
  647. text: '最低:' + item.data[2],
  648. color: color[2]
  649. };
  650. let text4 = {
  651. text: '最高:' + item.data[3],
  652. color: color[3]
  653. };
  654. textList.push(text1, text2, text3, text4);
  655. });
  656. var validCalPoints = [];
  657. var offset = {
  658. x: 0,
  659. y: 0
  660. };
  661. for (let i = 0; i < calPoints.length; i++) {
  662. let points = calPoints[i];
  663. if (typeof points[index] !== 'undefined' && points[index] !== null) {
  664. validCalPoints.push(points[index]);
  665. }
  666. }
  667. offset.x = Math.round(validCalPoints[0][0].x);
  668. return {
  669. textList: textList,
  670. offset: offset
  671. };
  672. }
  673. function filterSeries(series) {
  674. let tempSeries = [];
  675. for (let i = 0; i < series.length; i++) {
  676. if (series[i].show == true) {
  677. tempSeries.push(series[i])
  678. }
  679. }
  680. return tempSeries;
  681. }
  682. function findCurrentIndex(currentPoints, calPoints, opts, config) {
  683. var offset = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : 0;
  684. var current={ index:-1, group:[] };
  685. var spacing = opts.chartData.eachSpacing / 2;
  686. let xAxisPoints = [];
  687. if (calPoints && calPoints.length > 0) {
  688. if (!opts.categories) {
  689. spacing = 0;
  690. }else{
  691. for (let i = 1; i < opts.chartData.xAxisPoints.length; i++) {
  692. xAxisPoints.push(opts.chartData.xAxisPoints[i] - spacing);
  693. }
  694. if ((opts.type == 'line' || opts.type == 'area') && opts.xAxis.boundaryGap == 'justify') {
  695. xAxisPoints = opts.chartData.xAxisPoints;
  696. }
  697. }
  698. if (isInExactChartArea(currentPoints, opts, config)) {
  699. if (!opts.categories) {
  700. let timePoints = Array(calPoints.length);
  701. for (let i = 0; i < calPoints.length; i++) {
  702. timePoints[i] = Array(calPoints[i].length)
  703. for (let j = 0; j < calPoints[i].length; j++) {
  704. timePoints[i][j] = (Math.abs(calPoints[i][j].x - currentPoints.x));
  705. }
  706. };
  707. let pointValue = Array(timePoints.length);
  708. let pointIndex = Array(timePoints.length);
  709. for (let i = 0; i < timePoints.length; i++) {
  710. pointValue[i] = Math.min.apply(null, timePoints[i]);
  711. pointIndex[i] = timePoints[i].indexOf(pointValue[i]);
  712. }
  713. let minValue = Math.min.apply(null, pointValue);
  714. current.index = [];
  715. for (let i = 0; i < pointValue.length; i++) {
  716. if(pointValue[i] == minValue){
  717. current.group.push(i);
  718. current.index.push(pointIndex[i]);
  719. }
  720. };
  721. }else{
  722. xAxisPoints.forEach(function(item, index) {
  723. if (currentPoints.x + offset + spacing > item) {
  724. current.index = index;
  725. }
  726. });
  727. }
  728. }
  729. }
  730. return current;
  731. }
  732. function findBarChartCurrentIndex(currentPoints, calPoints, opts, config) {
  733. var offset = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : 0;
  734. var current={ index:-1, group:[] };
  735. var spacing = opts.chartData.eachSpacing / 2;
  736. let yAxisPoints = opts.chartData.yAxisPoints;
  737. if (calPoints && calPoints.length > 0) {
  738. if (isInExactChartArea(currentPoints, opts, config)) {
  739. yAxisPoints.forEach(function(item, index) {
  740. if (currentPoints.y + offset + spacing > item) {
  741. current.index = index;
  742. }
  743. });
  744. }
  745. }
  746. return current;
  747. }
  748. function findLegendIndex(currentPoints, legendData, opts) {
  749. let currentIndex = -1;
  750. let gap = 0;
  751. if (isInExactLegendArea(currentPoints, legendData.area)) {
  752. let points = legendData.points;
  753. let index = -1;
  754. for (let i = 0, len = points.length; i < len; i++) {
  755. let item = points[i];
  756. for (let j = 0; j < item.length; j++) {
  757. index += 1;
  758. let area = item[j]['area'];
  759. if (area && currentPoints.x > area[0] - gap && currentPoints.x < area[2] + gap && currentPoints.y > area[1] - gap && currentPoints.y < area[3] + gap) {
  760. currentIndex = index;
  761. break;
  762. }
  763. }
  764. }
  765. return currentIndex;
  766. }
  767. return currentIndex;
  768. }
  769. function isInExactLegendArea(currentPoints, area) {
  770. return currentPoints.x > area.start.x && currentPoints.x < area.end.x && currentPoints.y > area.start.y && currentPoints.y < area.end.y;
  771. }
  772. function isInExactChartArea(currentPoints, opts, config) {
  773. return currentPoints.x <= opts.width - opts.area[1] + 10 && currentPoints.x >= opts.area[3] - 10 && currentPoints.y >= opts.area[0] && currentPoints.y <= opts.height - opts.area[2];
  774. }
  775. function findRadarChartCurrentIndex(currentPoints, radarData, count) {
  776. var eachAngleArea = 2 * Math.PI / count;
  777. var currentIndex = -1;
  778. if (isInExactPieChartArea(currentPoints, radarData.center, radarData.radius)) {
  779. var fixAngle = function fixAngle(angle) {
  780. if (angle < 0) {
  781. angle += 2 * Math.PI;
  782. }
  783. if (angle > 2 * Math.PI) {
  784. angle -= 2 * Math.PI;
  785. }
  786. return angle;
  787. };
  788. var angle = Math.atan2(radarData.center.y - currentPoints.y, currentPoints.x - radarData.center.x);
  789. angle = -1 * angle;
  790. if (angle < 0) {
  791. angle += 2 * Math.PI;
  792. }
  793. var angleList = radarData.angleList.map(function(item) {
  794. item = fixAngle(-1 * item);
  795. return item;
  796. });
  797. angleList.forEach(function(item, index) {
  798. var rangeStart = fixAngle(item - eachAngleArea / 2);
  799. var rangeEnd = fixAngle(item + eachAngleArea / 2);
  800. if (rangeEnd < rangeStart) {
  801. rangeEnd += 2 * Math.PI;
  802. }
  803. if (angle >= rangeStart && angle <= rangeEnd || angle + 2 * Math.PI >= rangeStart && angle + 2 * Math.PI <= rangeEnd) {
  804. currentIndex = index;
  805. }
  806. });
  807. }
  808. return currentIndex;
  809. }
  810. function findFunnelChartCurrentIndex(currentPoints, funnelData) {
  811. var currentIndex = -1;
  812. for (var i = 0, len = funnelData.series.length; i < len; i++) {
  813. var item = funnelData.series[i];
  814. if (currentPoints.x > item.funnelArea[0] && currentPoints.x < item.funnelArea[2] && currentPoints.y > item.funnelArea[1] && currentPoints.y < item.funnelArea[3]) {
  815. currentIndex = i;
  816. break;
  817. }
  818. }
  819. return currentIndex;
  820. }
  821. function findWordChartCurrentIndex(currentPoints, wordData) {
  822. var currentIndex = -1;
  823. for (var i = 0, len = wordData.length; i < len; i++) {
  824. var item = wordData[i];
  825. if (currentPoints.x > item.area[0] && currentPoints.x < item.area[2] && currentPoints.y > item.area[1] && currentPoints.y < item.area[3]) {
  826. currentIndex = i;
  827. break;
  828. }
  829. }
  830. return currentIndex;
  831. }
  832. function findMapChartCurrentIndex(currentPoints, opts) {
  833. var currentIndex = -1;
  834. var cData = opts.chartData.mapData;
  835. var data = opts.series;
  836. var tmp = pointToCoordinate(currentPoints.y, currentPoints.x, cData.bounds, cData.scale, cData.xoffset, cData.yoffset);
  837. var poi = [tmp.x, tmp.y];
  838. for (var i = 0, len = data.length; i < len; i++) {
  839. var item = data[i].geometry.coordinates;
  840. if (isPoiWithinPoly(poi, item, opts.chartData.mapData.mercator)) {
  841. currentIndex = i;
  842. break;
  843. }
  844. }
  845. return currentIndex;
  846. }
  847. function findRoseChartCurrentIndex(currentPoints, pieData, opts) {
  848. var currentIndex = -1;
  849. var series = getRoseDataPoints(opts._series_, opts.extra.rose.type, pieData.radius, pieData.radius);
  850. if (pieData && pieData.center && isInExactPieChartArea(currentPoints, pieData.center, pieData.radius)) {
  851. var angle = Math.atan2(pieData.center.y - currentPoints.y, currentPoints.x - pieData.center.x);
  852. angle = -angle;
  853. if(opts.extra.rose && opts.extra.rose.offsetAngle){
  854. angle = angle - opts.extra.rose.offsetAngle * Math.PI / 180;
  855. }
  856. for (var i = 0, len = series.length; i < len; i++) {
  857. if (isInAngleRange(angle, series[i]._start_, series[i]._start_ + series[i]._rose_proportion_ * 2 * Math.PI)) {
  858. currentIndex = i;
  859. break;
  860. }
  861. }
  862. }
  863. return currentIndex;
  864. }
  865. function findPieChartCurrentIndex(currentPoints, pieData, opts) {
  866. var currentIndex = -1;
  867. var series = getPieDataPoints(pieData.series);
  868. if (pieData && pieData.center && isInExactPieChartArea(currentPoints, pieData.center, pieData.radius)) {
  869. var angle = Math.atan2(pieData.center.y - currentPoints.y, currentPoints.x - pieData.center.x);
  870. angle = -angle;
  871. if(opts.extra.pie && opts.extra.pie.offsetAngle){
  872. angle = angle - opts.extra.pie.offsetAngle * Math.PI / 180;
  873. }
  874. if(opts.extra.ring && opts.extra.ring.offsetAngle){
  875. angle = angle - opts.extra.ring.offsetAngle * Math.PI / 180;
  876. }
  877. for (var i = 0, len = series.length; i < len; i++) {
  878. if (isInAngleRange(angle, series[i]._start_, series[i]._start_ + series[i]._proportion_ * 2 * Math.PI)) {
  879. currentIndex = i;
  880. break;
  881. }
  882. }
  883. }
  884. return currentIndex;
  885. }
  886. function isInExactPieChartArea(currentPoints, center, radius) {
  887. return Math.pow(currentPoints.x - center.x, 2) + Math.pow(currentPoints.y - center.y, 2) <= Math.pow(radius, 2);
  888. }
  889. function splitPoints(points,eachSeries) {
  890. var newPoints = [];
  891. var items = [];
  892. points.forEach(function(item, index) {
  893. if(eachSeries.connectNulls){
  894. if (item !== null) {
  895. items.push(item);
  896. }
  897. }else{
  898. if (item !== null) {
  899. items.push(item);
  900. } else {
  901. if (items.length) {
  902. newPoints.push(items);
  903. }
  904. items = [];
  905. }
  906. }
  907. });
  908. if (items.length) {
  909. newPoints.push(items);
  910. }
  911. return newPoints;
  912. }
  913. function calLegendData(series, opts, config, chartData, context) {
  914. let legendData = {
  915. area: {
  916. start: {
  917. x: 0,
  918. y: 0
  919. },
  920. end: {
  921. x: 0,
  922. y: 0
  923. },
  924. width: 0,
  925. height: 0,
  926. wholeWidth: 0,
  927. wholeHeight: 0
  928. },
  929. points: [],
  930. widthArr: [],
  931. heightArr: []
  932. };
  933. if (opts.legend.show === false) {
  934. chartData.legendData = legendData;
  935. return legendData;
  936. }
  937. let padding = opts.legend.padding * opts.pix;
  938. let margin = opts.legend.margin * opts.pix;
  939. let fontSize = opts.legend.fontSize ? opts.legend.fontSize * opts.pix : config.fontSize;
  940. let shapeWidth = 15 * opts.pix;
  941. let shapeRight = 5 * opts.pix;
  942. let lineHeight = Math.max(opts.legend.lineHeight * opts.pix, fontSize);
  943. if (opts.legend.position == 'top' || opts.legend.position == 'bottom') {
  944. let legendList = [];
  945. let widthCount = 0;
  946. let widthCountArr = [];
  947. let currentRow = [];
  948. for (let i = 0; i < series.length; i++) {
  949. let item = series[i];
  950. const legendText = item.legendText ? item.legendText : item.name;
  951. let itemWidth = shapeWidth + shapeRight + measureText(legendText || 'undefined', fontSize, context) + opts.legend.itemGap * opts.pix;
  952. if (widthCount + itemWidth > opts.width - opts.area[1] - opts.area[3]) {
  953. legendList.push(currentRow);
  954. widthCountArr.push(widthCount - opts.legend.itemGap * opts.pix);
  955. widthCount = itemWidth;
  956. currentRow = [item];
  957. } else {
  958. widthCount += itemWidth;
  959. currentRow.push(item);
  960. }
  961. }
  962. if (currentRow.length) {
  963. legendList.push(currentRow);
  964. widthCountArr.push(widthCount - opts.legend.itemGap * opts.pix);
  965. legendData.widthArr = widthCountArr;
  966. let legendWidth = Math.max.apply(null, widthCountArr);
  967. switch (opts.legend.float) {
  968. case 'left':
  969. legendData.area.start.x = opts.area[3];
  970. legendData.area.end.x = opts.area[3] + legendWidth + 2 * padding;
  971. break;
  972. case 'right':
  973. legendData.area.start.x = opts.width - opts.area[1] - legendWidth - 2 * padding;
  974. legendData.area.end.x = opts.width - opts.area[1];
  975. break;
  976. default:
  977. legendData.area.start.x = (opts.width - legendWidth) / 2 - padding;
  978. legendData.area.end.x = (opts.width + legendWidth) / 2 + padding;
  979. }
  980. legendData.area.width = legendWidth + 2 * padding;
  981. legendData.area.wholeWidth = legendWidth + 2 * padding;
  982. legendData.area.height = legendList.length * lineHeight + 2 * padding;
  983. legendData.area.wholeHeight = legendList.length * lineHeight + 2 * padding + 2 * margin;
  984. legendData.points = legendList;
  985. }
  986. } else {
  987. let len = series.length;
  988. let maxHeight = opts.height - opts.area[0] - opts.area[2] - 2 * margin - 2 * padding;
  989. let maxLength = Math.min(Math.floor(maxHeight / lineHeight), len);
  990. legendData.area.height = maxLength * lineHeight + padding * 2;
  991. legendData.area.wholeHeight = maxLength * lineHeight + padding * 2;
  992. switch (opts.legend.float) {
  993. case 'top':
  994. legendData.area.start.y = opts.area[0] + margin;
  995. legendData.area.end.y = opts.area[0] + margin + legendData.area.height;
  996. break;
  997. case 'bottom':
  998. legendData.area.start.y = opts.height - opts.area[2] - margin - legendData.area.height;
  999. legendData.area.end.y = opts.height - opts.area[2] - margin;
  1000. break;
  1001. default:
  1002. legendData.area.start.y = (opts.height - legendData.area.height) / 2;
  1003. legendData.area.end.y = (opts.height + legendData.area.height) / 2;
  1004. }
  1005. let lineNum = len % maxLength === 0 ? len / maxLength : Math.floor((len / maxLength) + 1);
  1006. let currentRow = [];
  1007. for (let i = 0; i < lineNum; i++) {
  1008. let temp = series.slice(i * maxLength, i * maxLength + maxLength);
  1009. currentRow.push(temp);
  1010. }
  1011. legendData.points = currentRow;
  1012. if (currentRow.length) {
  1013. for (let i = 0; i < currentRow.length; i++) {
  1014. let item = currentRow[i];
  1015. let maxWidth = 0;
  1016. for (let j = 0; j < item.length; j++) {
  1017. let itemWidth = shapeWidth + shapeRight + measureText(item[j].name || 'undefined', fontSize, context) + opts.legend.itemGap * opts.pix;
  1018. if (itemWidth > maxWidth) {
  1019. maxWidth = itemWidth;
  1020. }
  1021. }
  1022. legendData.widthArr.push(maxWidth);
  1023. legendData.heightArr.push(item.length * lineHeight + padding * 2);
  1024. }
  1025. let legendWidth = 0
  1026. for (let i = 0; i < legendData.widthArr.length; i++) {
  1027. legendWidth += legendData.widthArr[i];
  1028. }
  1029. legendData.area.width = legendWidth - opts.legend.itemGap * opts.pix + 2 * padding;
  1030. legendData.area.wholeWidth = legendData.area.width + padding;
  1031. }
  1032. }
  1033. switch (opts.legend.position) {
  1034. case 'top':
  1035. legendData.area.start.y = opts.area[0] + margin;
  1036. legendData.area.end.y = opts.area[0] + margin + legendData.area.height;
  1037. break;
  1038. case 'bottom':
  1039. legendData.area.start.y = opts.height - opts.area[2] - legendData.area.height - margin;
  1040. legendData.area.end.y = opts.height - opts.area[2] - margin;
  1041. break;
  1042. case 'left':
  1043. legendData.area.start.x = opts.area[3];
  1044. legendData.area.end.x = opts.area[3] + legendData.area.width;
  1045. break;
  1046. case 'right':
  1047. legendData.area.start.x = opts.width - opts.area[1] - legendData.area.width;
  1048. legendData.area.end.x = opts.width - opts.area[1];
  1049. break;
  1050. }
  1051. chartData.legendData = legendData;
  1052. return legendData;
  1053. }
  1054. function calCategoriesData(categories, opts, config, eachSpacing, context) {
  1055. var result = {
  1056. angle: 0,
  1057. xAxisHeight: config.xAxisHeight
  1058. };
  1059. var fontSize = opts.xAxis.fontSize * opts.pix || config.fontSize;
  1060. var categoriesTextLenth = categories.map(function(item,index) {
  1061. var xitem = opts.xAxis.formatter ? opts.xAxis.formatter(item,index,opts) : item;
  1062. return measureText(String(xitem), fontSize, context);
  1063. });
  1064. var maxTextLength = Math.max.apply(this, categoriesTextLenth);
  1065. if (opts.xAxis.rotateLabel == true) {
  1066. result.angle = opts.xAxis.rotateAngle * Math.PI / 180;
  1067. let tempHeight = 2 * config.xAxisTextPadding + Math.abs(maxTextLength * Math.sin(result.angle))
  1068. tempHeight = tempHeight < fontSize + 2 * config.xAxisTextPadding ? tempHeight + 2 * config.xAxisTextPadding : tempHeight;
  1069. if(opts.enableScroll == true && opts.xAxis.scrollShow == true){
  1070. tempHeight += 12 * opts.pix;
  1071. }
  1072. result.xAxisHeight = tempHeight;
  1073. }
  1074. if (opts.xAxis.disabled){
  1075. result.xAxisHeight = 0;
  1076. }
  1077. return result;
  1078. }
  1079. function getXAxisTextList(series, opts, config, stack) {
  1080. var index = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : -1;
  1081. var data;
  1082. if (stack == 'stack') {
  1083. data = dataCombineStack(series, opts.categories.length);
  1084. } else {
  1085. data = dataCombine(series);
  1086. }
  1087. var sorted = [];
  1088. // remove null from data
  1089. data = data.filter(function(item) {
  1090. //return item !== null;
  1091. if (typeof item === 'object' && item !== null) {
  1092. if (item.constructor.toString().indexOf('Array') > -1) {
  1093. return item !== null;
  1094. } else {
  1095. return item.value !== null;
  1096. }
  1097. } else {
  1098. return item !== null;
  1099. }
  1100. });
  1101. data.map(function(item) {
  1102. if (typeof item === 'object') {
  1103. if (item.constructor.toString().indexOf('Array') > -1) {
  1104. if (opts.type == 'candle') {
  1105. item.map(function(subitem) {
  1106. sorted.push(subitem);
  1107. })
  1108. } else {
  1109. sorted.push(item[0]);
  1110. }
  1111. } else {
  1112. sorted.push(item.value);
  1113. }
  1114. } else {
  1115. sorted.push(item);
  1116. }
  1117. })
  1118. var minData = 0;
  1119. var maxData = 0;
  1120. if (sorted.length > 0) {
  1121. minData = Math.min.apply(this, sorted);
  1122. maxData = Math.max.apply(this, sorted);
  1123. }
  1124. //为了兼容v1.9.0之前的项目
  1125. if (index > -1) {
  1126. if (typeof opts.xAxis.data[index].min === 'number') {
  1127. minData = Math.min(opts.xAxis.data[index].min, minData);
  1128. }
  1129. if (typeof opts.xAxis.data[index].max === 'number') {
  1130. maxData = Math.max(opts.xAxis.data[index].max, maxData);
  1131. }
  1132. } else {
  1133. if (typeof opts.xAxis.min === 'number') {
  1134. minData = Math.min(opts.xAxis.min, minData);
  1135. }
  1136. if (typeof opts.xAxis.max === 'number') {
  1137. maxData = Math.max(opts.xAxis.max, maxData);
  1138. }
  1139. }
  1140. if (minData === maxData) {
  1141. var rangeSpan = maxData || 10;
  1142. maxData += rangeSpan;
  1143. }
  1144. //var dataRange = getDataRange(minData, maxData);
  1145. var minRange = minData;
  1146. var maxRange = maxData;
  1147. var range = [];
  1148. var eachRange = (maxRange - minRange) / opts.xAxis.splitNumber;
  1149. for (var i = 0; i <= opts.xAxis.splitNumber; i++) {
  1150. range.push(minRange + eachRange * i);
  1151. }
  1152. return range;
  1153. }
  1154. function calXAxisData(series, opts, config, context) {
  1155. //堆叠图重算Y轴
  1156. var columnstyle = assign({}, {
  1157. type: ""
  1158. }, opts.extra.bar);
  1159. var result = {
  1160. angle: 0,
  1161. xAxisHeight: config.xAxisHeight
  1162. };
  1163. result.ranges = getXAxisTextList(series, opts, config, columnstyle.type);
  1164. result.rangesFormat = result.ranges.map(function(item) {
  1165. //item = opts.xAxis.formatter ? opts.xAxis.formatter(item) : util.toFixed(item, 2);
  1166. item = util.toFixed(item, 2);
  1167. return item;
  1168. });
  1169. var xAxisScaleValues = result.ranges.map(function(item) {
  1170. // 如果刻度值是浮点数,则保留两位小数
  1171. item = util.toFixed(item, 2);
  1172. // 若有自定义格式则调用自定义的格式化函数
  1173. //item = opts.xAxis.formatter ? opts.xAxis.formatter(Number(item)) : item;
  1174. return item;
  1175. });
  1176. result = Object.assign(result, getXAxisPoints(xAxisScaleValues, opts, config));
  1177. // 计算X轴刻度的属性譬如每个刻度的间隔,刻度的起始点\结束点以及总长
  1178. var eachSpacing = result.eachSpacing;
  1179. var textLength = xAxisScaleValues.map(function(item) {
  1180. return measureText(item, opts.xAxis.fontSize * opts.pix || config.fontSize, context);
  1181. });
  1182. // get max length of categories text
  1183. var maxTextLength = Math.max.apply(this, textLength);
  1184. // 如果刻度值文本内容过长,则将其逆时针旋转45°
  1185. if (maxTextLength + 2 * config.xAxisTextPadding > eachSpacing) {
  1186. result.angle = 45 * Math.PI / 180;
  1187. result.xAxisHeight = 2 * config.xAxisTextPadding + maxTextLength * Math.sin(result.angle);
  1188. }
  1189. if (opts.xAxis.disabled === true) {
  1190. result.xAxisHeight = 0;
  1191. }
  1192. return result;
  1193. }
  1194. function getRadarDataPoints(angleList, center, radius, series, opts) {
  1195. var process = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : 1;
  1196. var radarOption = opts.extra.radar || {};
  1197. radarOption.max = radarOption.max || 0;
  1198. var maxData = Math.max(radarOption.max, Math.max.apply(null, dataCombine(series)));
  1199. var data = [];
  1200. for (let i = 0; i < series.length; i++) {
  1201. let each = series[i];
  1202. let listItem = {};
  1203. listItem.color = each.color;
  1204. listItem.legendShape = each.legendShape;
  1205. listItem.pointShape = each.pointShape;
  1206. listItem.data = [];
  1207. each.data.forEach(function(item, index) {
  1208. let tmp = {};
  1209. tmp.angle = angleList[index];
  1210. tmp.proportion = item / maxData;
  1211. tmp.value = item;
  1212. tmp.position = convertCoordinateOrigin(radius * tmp.proportion * process * Math.cos(tmp.angle), radius * tmp.proportion * process * Math.sin(tmp.angle), center);
  1213. listItem.data.push(tmp);
  1214. });
  1215. data.push(listItem);
  1216. }
  1217. return data;
  1218. }
  1219. function getPieDataPoints(series, radius) {
  1220. var process = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 1;
  1221. var count = 0;
  1222. var _start_ = 0;
  1223. for (let i = 0; i < series.length; i++) {
  1224. let item = series[i];
  1225. item.data = item.data === null ? 0 : item.data;
  1226. count += item.data;
  1227. }
  1228. for (let i = 0; i < series.length; i++) {
  1229. let item = series[i];
  1230. item.data = item.data === null ? 0 : item.data;
  1231. if (count === 0) {
  1232. item._proportion_ = 1 / series.length * process;
  1233. } else {
  1234. item._proportion_ = item.data / count * process;
  1235. }
  1236. item._radius_ = radius;
  1237. }
  1238. for (let i = 0; i < series.length; i++) {
  1239. let item = series[i];
  1240. item._start_ = _start_;
  1241. _start_ += 2 * item._proportion_ * Math.PI;
  1242. }
  1243. return series;
  1244. }
  1245. function getFunnelDataPoints(series, radius, option, eachSpacing) {
  1246. var process = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : 1;
  1247. for (let i = 0; i < series.length; i++) {
  1248. if(option.type == 'funnel'){
  1249. series[i].radius = series[i].data / series[0].data * radius * process;
  1250. }else{
  1251. series[i].radius = (eachSpacing * (series.length - i)) / (eachSpacing * series.length) * radius * process;
  1252. }
  1253. series[i]._proportion_ = series[i].data / series[0].data;
  1254. }
  1255. // if(option.type !== 'pyramid'){
  1256. // series.reverse();
  1257. // }
  1258. return series;
  1259. }
  1260. function getRoseDataPoints(series, type, minRadius, radius) {
  1261. var process = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : 1;
  1262. var count = 0;
  1263. var _start_ = 0;
  1264. var dataArr = [];
  1265. for (let i = 0; i < series.length; i++) {
  1266. let item = series[i];
  1267. item.data = item.data === null ? 0 : item.data;
  1268. count += item.data;
  1269. dataArr.push(item.data);
  1270. }
  1271. var minData = Math.min.apply(null, dataArr);
  1272. var maxData = Math.max.apply(null, dataArr);
  1273. var radiusLength = radius - minRadius;
  1274. for (let i = 0; i < series.length; i++) {
  1275. let item = series[i];
  1276. item.data = item.data === null ? 0 : item.data;
  1277. if (count === 0) {
  1278. item._proportion_ = 1 / series.length * process;
  1279. item._rose_proportion_ = 1 / series.length * process;
  1280. } else {
  1281. item._proportion_ = item.data / count * process;
  1282. if(type == 'area'){
  1283. item._rose_proportion_ = 1 / series.length * process;
  1284. }else{
  1285. item._rose_proportion_ = item.data / count * process;
  1286. }
  1287. }
  1288. item._radius_ = minRadius + radiusLength * ((item.data - minData) / (maxData - minData)) || radius;
  1289. }
  1290. for (let i = 0; i < series.length; i++) {
  1291. let item = series[i];
  1292. item._start_ = _start_;
  1293. _start_ += 2 * item._rose_proportion_ * Math.PI;
  1294. }
  1295. return series;
  1296. }
  1297. function getArcbarDataPoints(series, arcbarOption) {
  1298. var process = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 1;
  1299. if (process == 1) {
  1300. process = 0.999999;
  1301. }
  1302. for (let i = 0; i < series.length; i++) {
  1303. let item = series[i];
  1304. item.data = item.data === null ? 0 : item.data;
  1305. let totalAngle;
  1306. if (arcbarOption.type == 'circle') {
  1307. totalAngle = 2;
  1308. } else {
  1309. if(arcbarOption.direction == 'ccw'){
  1310. if (arcbarOption.startAngle < arcbarOption.endAngle) {
  1311. totalAngle = 2 + arcbarOption.startAngle - arcbarOption.endAngle;
  1312. } else {
  1313. totalAngle = arcbarOption.startAngle - arcbarOption.endAngle;
  1314. }
  1315. }else{
  1316. if (arcbarOption.endAngle < arcbarOption.startAngle) {
  1317. totalAngle = 2 + arcbarOption.endAngle - arcbarOption.startAngle;
  1318. } else {
  1319. totalAngle = arcbarOption.startAngle - arcbarOption.endAngle;
  1320. }
  1321. }
  1322. }
  1323. item._proportion_ = totalAngle * item.data * process + arcbarOption.startAngle;
  1324. if(arcbarOption.direction == 'ccw'){
  1325. item._proportion_ = arcbarOption.startAngle - totalAngle * item.data * process ;
  1326. }
  1327. if (item._proportion_ >= 2) {
  1328. item._proportion_ = item._proportion_ % 2;
  1329. }
  1330. }
  1331. return series;
  1332. }
  1333. function getGaugeArcbarDataPoints(series, arcbarOption) {
  1334. var process = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 1;
  1335. if (process == 1) {
  1336. process = 0.999999;
  1337. }
  1338. for (let i = 0; i < series.length; i++) {
  1339. let item = series[i];
  1340. item.data = item.data === null ? 0 : item.data;
  1341. let totalAngle;
  1342. if (arcbarOption.type == 'circle') {
  1343. totalAngle = 2;
  1344. } else {
  1345. if (arcbarOption.endAngle < arcbarOption.startAngle) {
  1346. totalAngle = 2 + arcbarOption.endAngle - arcbarOption.startAngle;
  1347. } else {
  1348. totalAngle = arcbarOption.startAngle - arcbarOption.endAngle;
  1349. }
  1350. }
  1351. item._proportion_ = totalAngle * item.data * process + arcbarOption.startAngle;
  1352. if (item._proportion_ >= 2) {
  1353. item._proportion_ = item._proportion_ % 2;
  1354. }
  1355. }
  1356. return series;
  1357. }
  1358. function getGaugeAxisPoints(categories, startAngle, endAngle) {
  1359. let totalAngle = startAngle - endAngle + 1;
  1360. let tempStartAngle = startAngle;
  1361. for (let i = 0; i < categories.length; i++) {
  1362. categories[i].value = categories[i].value === null ? 0 : categories[i].value;
  1363. categories[i]._startAngle_ = tempStartAngle;
  1364. categories[i]._endAngle_ = totalAngle * categories[i].value + startAngle;
  1365. if (categories[i]._endAngle_ >= 2) {
  1366. categories[i]._endAngle_ = categories[i]._endAngle_ % 2;
  1367. }
  1368. tempStartAngle = categories[i]._endAngle_;
  1369. }
  1370. return categories;
  1371. }
  1372. function getGaugeDataPoints(series, categories, gaugeOption) {
  1373. let process = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 1;
  1374. for (let i = 0; i < series.length; i++) {
  1375. let item = series[i];
  1376. item.data = item.data === null ? 0 : item.data;
  1377. if (gaugeOption.pointer.color == 'auto') {
  1378. for (let i = 0; i < categories.length; i++) {
  1379. if (item.data <= categories[i].value) {
  1380. item.color = categories[i].color;
  1381. break;
  1382. }
  1383. }
  1384. } else {
  1385. item.color = gaugeOption.pointer.color;
  1386. }
  1387. let totalAngle = gaugeOption.startAngle - gaugeOption.endAngle + 1;
  1388. item._endAngle_ = totalAngle * item.data + gaugeOption.startAngle;
  1389. item._oldAngle_ = gaugeOption.oldAngle;
  1390. if (gaugeOption.oldAngle < gaugeOption.endAngle) {
  1391. item._oldAngle_ += 2;
  1392. }
  1393. if (item.data >= gaugeOption.oldData) {
  1394. item._proportion_ = (item._endAngle_ - item._oldAngle_) * process + gaugeOption.oldAngle;
  1395. } else {
  1396. item._proportion_ = item._oldAngle_ - (item._oldAngle_ - item._endAngle_) * process;
  1397. }
  1398. if (item._proportion_ >= 2) {
  1399. item._proportion_ = item._proportion_ % 2;
  1400. }
  1401. }
  1402. return series;
  1403. }
  1404. function getPieTextMaxLength(series, config, context, opts) {
  1405. series = getPieDataPoints(series);
  1406. let maxLength = 0;
  1407. for (let i = 0; i < series.length; i++) {
  1408. let item = series[i];
  1409. let text = item.formatter ? item.formatter(+item._proportion_.toFixed(2)) : util.toFixed(item._proportion_ * 100) + '%';
  1410. maxLength = Math.max(maxLength, measureText(text, item.textSize * opts.pix || config.fontSize, context));
  1411. }
  1412. return maxLength;
  1413. }
  1414. function fixColumeData(points, eachSpacing, columnLen, index, config, opts) {
  1415. return points.map(function(item) {
  1416. if (item === null) {
  1417. return null;
  1418. }
  1419. var seriesGap = 0;
  1420. var categoryGap = 0;
  1421. if (opts.type == 'mix') {
  1422. seriesGap = opts.extra.mix.column.seriesGap * opts.pix || 0;
  1423. categoryGap = opts.extra.mix.column.categoryGap * opts.pix || 0;
  1424. } else {
  1425. seriesGap = opts.extra.column.seriesGap * opts.pix || 0;
  1426. categoryGap = opts.extra.column.categoryGap * opts.pix || 0;
  1427. }
  1428. seriesGap = Math.min(seriesGap, eachSpacing / columnLen)
  1429. categoryGap = Math.min(categoryGap, eachSpacing / columnLen)
  1430. item.width = Math.ceil((eachSpacing - 2 * categoryGap - seriesGap * (columnLen - 1)) / columnLen);
  1431. if (opts.extra.mix && opts.extra.mix.column.width && +opts.extra.mix.column.width > 0) {
  1432. item.width = Math.min(item.width, +opts.extra.mix.column.width * opts.pix);
  1433. }
  1434. if (opts.extra.column && opts.extra.column.width && +opts.extra.column.width > 0) {
  1435. item.width = Math.min(item.width, +opts.extra.column.width * opts.pix);
  1436. }
  1437. if (item.width <= 0) {
  1438. item.width = 1;
  1439. }
  1440. item.x += (index + 0.5 - columnLen / 2) * (item.width + seriesGap);
  1441. return item;
  1442. });
  1443. }
  1444. function fixBarData(points, eachSpacing, columnLen, index, config, opts) {
  1445. return points.map(function(item) {
  1446. if (item === null) {
  1447. return null;
  1448. }
  1449. var seriesGap = 0;
  1450. var categoryGap = 0;
  1451. seriesGap = opts.extra.bar.seriesGap * opts.pix || 0;
  1452. categoryGap = opts.extra.bar.categoryGap * opts.pix || 0;
  1453. seriesGap = Math.min(seriesGap, eachSpacing / columnLen)
  1454. categoryGap = Math.min(categoryGap, eachSpacing / columnLen)
  1455. item.width = Math.ceil((eachSpacing - 2 * categoryGap - seriesGap * (columnLen - 1)) / columnLen);
  1456. if (opts.extra.bar && opts.extra.bar.width && +opts.extra.bar.width > 0) {
  1457. item.width = Math.min(item.width, +opts.extra.bar.width * opts.pix);
  1458. }
  1459. if (item.width <= 0) {
  1460. item.width = 1;
  1461. }
  1462. item.y += (index + 0.5 - columnLen / 2) * (item.width + seriesGap);
  1463. return item;
  1464. });
  1465. }
  1466. function fixColumeMeterData(points, eachSpacing, columnLen, index, config, opts, border) {
  1467. var categoryGap = opts.extra.column.categoryGap * opts.pix || 0;
  1468. return points.map(function(item) {
  1469. if (item === null) {
  1470. return null;
  1471. }
  1472. item.width = eachSpacing - 2 * categoryGap;
  1473. if (opts.extra.column && opts.extra.column.width && +opts.extra.column.width > 0) {
  1474. item.width = Math.min(item.width, +opts.extra.column.width * opts.pix);
  1475. }
  1476. if (index > 0) {
  1477. item.width -= border;
  1478. }
  1479. return item;
  1480. });
  1481. }
  1482. function fixColumeStackData(points, eachSpacing, columnLen, index, config, opts, series) {
  1483. var categoryGap = opts.extra.column.categoryGap * opts.pix || 0;
  1484. return points.map(function(item, indexn) {
  1485. if (item === null) {
  1486. return null;
  1487. }
  1488. item.width = Math.ceil(eachSpacing - 2 * categoryGap);
  1489. if (opts.extra.column && opts.extra.column.width && +opts.extra.column.width > 0) {
  1490. item.width = Math.min(item.width, +opts.extra.column.width * opts.pix);
  1491. }
  1492. if (item.width <= 0) {
  1493. item.width = 1;
  1494. }
  1495. return item;
  1496. });
  1497. }
  1498. function fixBarStackData(points, eachSpacing, columnLen, index, config, opts, series) {
  1499. var categoryGap = opts.extra.bar.categoryGap * opts.pix || 0;
  1500. return points.map(function(item, indexn) {
  1501. if (item === null) {
  1502. return null;
  1503. }
  1504. item.width = Math.ceil(eachSpacing - 2 * categoryGap);
  1505. if (opts.extra.bar && opts.extra.bar.width && +opts.extra.bar.width > 0) {
  1506. item.width = Math.min(item.width, +opts.extra.bar.width * opts.pix);
  1507. }
  1508. if (item.width <= 0) {
  1509. item.width = 1;
  1510. }
  1511. return item;
  1512. });
  1513. }
  1514. function getXAxisPoints(categories, opts, config) {
  1515. var spacingValid = opts.width - opts.area[1] - opts.area[3];
  1516. var dataCount = opts.enableScroll ? Math.min(opts.xAxis.itemCount, categories.length) : categories.length;
  1517. if ((opts.type == 'line' || opts.type == 'area' || opts.type == 'scatter' || opts.type == 'bubble' || opts.type == 'bar') && dataCount > 1 && opts.xAxis.boundaryGap == 'justify') {
  1518. dataCount -= 1;
  1519. }
  1520. var widthRatio = 0;
  1521. if(opts.type == 'mount' && opts.extra && opts.extra.mount && opts.extra.mount.widthRatio && opts.extra.mount.widthRatio > 1){
  1522. if(opts.extra.mount.widthRatio>2) opts.extra.mount.widthRatio = 2
  1523. widthRatio = opts.extra.mount.widthRatio - 1;
  1524. dataCount += widthRatio;
  1525. }
  1526. var eachSpacing = spacingValid / dataCount;
  1527. var xAxisPoints = [];
  1528. var startX = opts.area[3];
  1529. var endX = opts.width - opts.area[1];
  1530. categories.forEach(function(item, index) {
  1531. xAxisPoints.push(startX + widthRatio / 2 * eachSpacing + index * eachSpacing);
  1532. });
  1533. if (opts.xAxis.boundaryGap !== 'justify') {
  1534. if (opts.enableScroll === true) {
  1535. xAxisPoints.push(startX + widthRatio * eachSpacing + categories.length * eachSpacing);
  1536. } else {
  1537. xAxisPoints.push(endX);
  1538. }
  1539. }
  1540. return {
  1541. xAxisPoints: xAxisPoints,
  1542. startX: startX,
  1543. endX: endX,
  1544. eachSpacing: eachSpacing
  1545. };
  1546. }
  1547. function getCandleDataPoints(data, minRange, maxRange, xAxisPoints, eachSpacing, opts, config) {
  1548. var process = arguments.length > 7 && arguments[7] !== undefined ? arguments[7] : 1;
  1549. var points = [];
  1550. var validHeight = opts.height - opts.area[0] - opts.area[2];
  1551. data.forEach(function(item, index) {
  1552. if (item === null) {
  1553. points.push(null);
  1554. } else {
  1555. var cPoints = [];
  1556. item.forEach(function(items, indexs) {
  1557. var point = {};
  1558. point.x = xAxisPoints[index] + Math.round(eachSpacing / 2);
  1559. var value = items.value || items;
  1560. var height = validHeight * (value - minRange) / (maxRange - minRange);
  1561. height *= process;
  1562. point.y = opts.height - Math.round(height) - opts.area[2];
  1563. cPoints.push(point);
  1564. });
  1565. points.push(cPoints);
  1566. }
  1567. });
  1568. return points;
  1569. }
  1570. function getDataPoints(data, minRange, maxRange, xAxisPoints, eachSpacing, opts, config) {
  1571. var process = arguments.length > 7 && arguments[7] !== undefined ? arguments[7] : 1;
  1572. var boundaryGap = 'center';
  1573. if (opts.type == 'line' || opts.type == 'area' || opts.type == 'scatter' || opts.type == 'bubble' ) {
  1574. boundaryGap = opts.xAxis.boundaryGap;
  1575. }
  1576. var points = [];
  1577. var validHeight = opts.height - opts.area[0] - opts.area[2];
  1578. var validWidth = opts.width - opts.area[1] - opts.area[3];
  1579. data.forEach(function(item, index) {
  1580. if (item === null) {
  1581. points.push(null);
  1582. } else {
  1583. var point = {};
  1584. point.color = item.color;
  1585. point.x = xAxisPoints[index];
  1586. var value = item;
  1587. if (typeof item === 'object' && item !== null) {
  1588. if (item.constructor.toString().indexOf('Array') > -1) {
  1589. let xranges, xminRange, xmaxRange;
  1590. xranges = [].concat(opts.chartData.xAxisData.ranges);
  1591. xminRange = xranges.shift();
  1592. xmaxRange = xranges.pop();
  1593. value = item[1];
  1594. point.x = opts.area[3] + validWidth * (item[0] - xminRange) / (xmaxRange - xminRange);
  1595. if(opts.type == 'bubble'){
  1596. point.r = item[2];
  1597. point.t = item[3];
  1598. }
  1599. } else {
  1600. value = item.value;
  1601. }
  1602. }
  1603. if (boundaryGap == 'center') {
  1604. point.x += eachSpacing / 2;
  1605. }
  1606. var height = validHeight * (value - minRange) / (maxRange - minRange);
  1607. height *= process;
  1608. point.y = opts.height - height - opts.area[2];
  1609. points.push(point);
  1610. }
  1611. });
  1612. return points;
  1613. }
  1614. function getMountDataPoints(series, minRange, maxRange, xAxisPoints, eachSpacing, opts, mountOption) {
  1615. var process = arguments.length > 7 && arguments[7] !== undefined ? arguments[7] : 1;
  1616. var points = [];
  1617. var validHeight = opts.height - opts.area[0] - opts.area[2];
  1618. var validWidth = opts.width - opts.area[1] - opts.area[3];
  1619. var mountWidth = eachSpacing * mountOption.widthRatio;
  1620. series.forEach(function(item, index) {
  1621. if (item === null) {
  1622. points.push(null);
  1623. } else {
  1624. var point = {};
  1625. point.color = item.color;
  1626. point.x = xAxisPoints[index];
  1627. point.x += eachSpacing / 2;
  1628. var value = item.data;
  1629. var height = validHeight * (value - minRange) / (maxRange - minRange);
  1630. height *= process;
  1631. point.y = opts.height - height - opts.area[2];
  1632. point.value = value;
  1633. point.width = mountWidth;
  1634. points.push(point);
  1635. }
  1636. });
  1637. return points;
  1638. }
  1639. function getBarDataPoints(data, minRange, maxRange, yAxisPoints, eachSpacing, opts, config) {
  1640. var process = arguments.length > 7 && arguments[7] !== undefined ? arguments[7] : 1;
  1641. var points = [];
  1642. var validHeight = opts.height - opts.area[0] - opts.area[2];
  1643. var validWidth = opts.width - opts.area[1] - opts.area[3];
  1644. data.forEach(function(item, index) {
  1645. if (item === null) {
  1646. points.push(null);
  1647. } else {
  1648. var point = {};
  1649. point.color = item.color;
  1650. point.y = yAxisPoints[index];
  1651. var value = item;
  1652. if (typeof item === 'object' && item !== null) {
  1653. value = item.value;
  1654. }
  1655. var height = validWidth * (value - minRange) / (maxRange - minRange);
  1656. height *= process;
  1657. point.height = height;
  1658. point.value = value;
  1659. point.x = height + opts.area[3];
  1660. points.push(point);
  1661. }
  1662. });
  1663. return points;
  1664. }
  1665. function getStackDataPoints(data, minRange, maxRange, xAxisPoints, eachSpacing, opts, config, seriesIndex, stackSeries) {
  1666. var process = arguments.length > 9 && arguments[9] !== undefined ? arguments[9] : 1;
  1667. var points = [];
  1668. var validHeight = opts.height - opts.area[0] - opts.area[2];
  1669. data.forEach(function(item, index) {
  1670. if (item === null) {
  1671. points.push(null);
  1672. } else {
  1673. var point = {};
  1674. point.color = item.color;
  1675. point.x = xAxisPoints[index] + Math.round(eachSpacing / 2);
  1676. if (seriesIndex > 0) {
  1677. var value = 0;
  1678. for (let i = 0; i <= seriesIndex; i++) {
  1679. value += stackSeries[i].data[index];
  1680. }
  1681. var value0 = value - item;
  1682. var height = validHeight * (value - minRange) / (maxRange - minRange);
  1683. var height0 = validHeight * (value0 - minRange) / (maxRange - minRange);
  1684. } else {
  1685. var value = item;
  1686. if (typeof item === 'object' && item !== null) {
  1687. value = item.value;
  1688. }
  1689. var height = validHeight * (value - minRange) / (maxRange - minRange);
  1690. var height0 = 0;
  1691. }
  1692. var heightc = height0;
  1693. height *= process;
  1694. heightc *= process;
  1695. point.y = opts.height - Math.round(height) - opts.area[2];
  1696. point.y0 = opts.height - Math.round(heightc) - opts.area[2];
  1697. points.push(point);
  1698. }
  1699. });
  1700. return points;
  1701. }
  1702. function getBarStackDataPoints(data, minRange, maxRange, yAxisPoints, eachSpacing, opts, config, seriesIndex, stackSeries) {
  1703. var process = arguments.length > 9 && arguments[9] !== undefined ? arguments[9] : 1;
  1704. var points = [];
  1705. var validHeight = opts.width - opts.area[1] - opts.area[3];
  1706. data.forEach(function(item, index) {
  1707. if (item === null) {
  1708. points.push(null);
  1709. } else {
  1710. var point = {};
  1711. point.color = item.color;
  1712. point.y = yAxisPoints[index];
  1713. if (seriesIndex > 0) {
  1714. var value = 0;
  1715. for (let i = 0; i <= seriesIndex; i++) {
  1716. value += stackSeries[i].data[index];
  1717. }
  1718. var value0 = value - item;
  1719. var height = validHeight * (value - minRange) / (maxRange - minRange);
  1720. var height0 = validHeight * (value0 - minRange) / (maxRange - minRange);
  1721. } else {
  1722. var value = item;
  1723. if (typeof item === 'object' && item !== null) {
  1724. value = item.value;
  1725. }
  1726. var height = validHeight * (value - minRange) / (maxRange - minRange);
  1727. var height0 = 0;
  1728. }
  1729. var heightc = height0;
  1730. height *= process;
  1731. heightc *= process;
  1732. point.height = height - heightc;
  1733. point.x = opts.area[3] + height;
  1734. point.x0 = opts.area[3] + heightc;
  1735. points.push(point);
  1736. }
  1737. });
  1738. return points;
  1739. }
  1740. function getYAxisTextList(series, opts, config, stack, yData) {
  1741. var index = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : -1;
  1742. var data;
  1743. if (stack == 'stack') {
  1744. data = dataCombineStack(series, opts.categories.length);
  1745. } else {
  1746. data = dataCombine(series);
  1747. }
  1748. var sorted = [];
  1749. // remove null from data
  1750. data = data.filter(function(item) {
  1751. //return item !== null;
  1752. if (typeof item === 'object' && item !== null) {
  1753. if (item.constructor.toString().indexOf('Array') > -1) {
  1754. return item !== null;
  1755. } else {
  1756. return item.value !== null;
  1757. }
  1758. } else {
  1759. return item !== null;
  1760. }
  1761. });
  1762. data.map(function(item) {
  1763. if (typeof item === 'object') {
  1764. if (item.constructor.toString().indexOf('Array') > -1) {
  1765. if (opts.type == 'candle') {
  1766. item.map(function(subitem) {
  1767. sorted.push(subitem);
  1768. })
  1769. } else {
  1770. sorted.push(item[1]);
  1771. }
  1772. } else {
  1773. sorted.push(item.value);
  1774. }
  1775. } else {
  1776. sorted.push(item);
  1777. }
  1778. })
  1779. var minData = yData.min || 0;
  1780. var maxData = yData.max || 0;
  1781. if (sorted.length > 0) {
  1782. minData = Math.min.apply(this, sorted);
  1783. maxData = Math.max.apply(this, sorted);
  1784. }
  1785. if (minData === maxData) {
  1786. if(maxData == 0){
  1787. maxData = 10;
  1788. }else{
  1789. minData = 0;
  1790. }
  1791. }
  1792. var dataRange = getDataRange(minData, maxData);
  1793. var minRange = (yData.min === undefined || yData.min === null) ? dataRange.minRange : yData.min;
  1794. var maxRange = (yData.max === undefined || yData.max === null) ? dataRange.maxRange : yData.max;
  1795. var eachRange = (maxRange - minRange) / opts.yAxis.splitNumber;
  1796. var range = [];
  1797. for (var i = 0; i <= opts.yAxis.splitNumber; i++) {
  1798. range.push(minRange + eachRange * i);
  1799. }
  1800. return range.reverse();
  1801. }
  1802. function calYAxisData(series, opts, config, context) {
  1803. //堆叠图重算Y轴
  1804. var columnstyle = assign({}, {
  1805. type: ""
  1806. }, opts.extra.column);
  1807. //如果是多Y轴,重新计算
  1808. var YLength = opts.yAxis.data.length;
  1809. var newSeries = new Array(YLength);
  1810. if (YLength > 0) {
  1811. for (let i = 0; i < YLength; i++) {
  1812. newSeries[i] = [];
  1813. for (let j = 0; j < series.length; j++) {
  1814. if (series[j].index == i) {
  1815. newSeries[i].push(series[j]);
  1816. }
  1817. }
  1818. }
  1819. var rangesArr = new Array(YLength);
  1820. var rangesFormatArr = new Array(YLength);
  1821. var yAxisWidthArr = new Array(YLength);
  1822. for (let i = 0; i < YLength; i++) {
  1823. let yData = opts.yAxis.data[i];
  1824. //如果总开关不显示,强制每个Y轴为不显示
  1825. if (opts.yAxis.disabled == true) {
  1826. yData.disabled = true;
  1827. }
  1828. if(yData.type === 'categories'){
  1829. if(!yData.formatter){
  1830. yData.formatter = (val,index,opts) => {return val + (yData.unit || '')};
  1831. }
  1832. yData.categories = yData.categories || opts.categories;
  1833. rangesArr[i] = yData.categories;
  1834. }else{
  1835. if(!yData.formatter){
  1836. yData.formatter = (val,index,opts) => {return util.toFixed(val, yData.tofix || 0) + (yData.unit || '')};
  1837. }
  1838. rangesArr[i] = getYAxisTextList(newSeries[i], opts, config, columnstyle.type, yData, i);
  1839. }
  1840. let yAxisFontSizes = yData.fontSize * opts.pix || config.fontSize;
  1841. yAxisWidthArr[i] = {
  1842. position: yData.position ? yData.position : 'left',
  1843. width: 0
  1844. };
  1845. rangesFormatArr[i] = rangesArr[i].map(function(items,index) {
  1846. items = yData.formatter(items,index,opts);
  1847. yAxisWidthArr[i].width = Math.max(yAxisWidthArr[i].width, measureText(items, yAxisFontSizes, context) + 5);
  1848. return items;
  1849. });
  1850. let calibration = yData.calibration ? 4 * opts.pix : 0;
  1851. yAxisWidthArr[i].width += calibration + 3 * opts.pix;
  1852. if (yData.disabled === true) {
  1853. yAxisWidthArr[i].width = 0;
  1854. }
  1855. }
  1856. } else {
  1857. var rangesArr = new Array(1);
  1858. var rangesFormatArr = new Array(1);
  1859. var yAxisWidthArr = new Array(1);
  1860. if(opts.type === 'bar'){
  1861. rangesArr[0] = opts.categories;
  1862. }else{
  1863. rangesArr[0] = getYAxisTextList(series, opts, config, columnstyle.type, {});
  1864. }
  1865. yAxisWidthArr[0] = {
  1866. position: 'left',
  1867. width: 0
  1868. };
  1869. if (opts.yAxis.disabled === true) {
  1870. yAxisWidthArr[0] = {
  1871. position: 'left',
  1872. width: 0
  1873. };
  1874. opts.yAxis.data[0] = {
  1875. disabled: true
  1876. };
  1877. } else {
  1878. opts.yAxis.data[0] = {
  1879. disabled: false,
  1880. position: 'left',
  1881. max: opts.yAxis.max,
  1882. min: opts.yAxis.min,
  1883. formatter: (val,index,opts) => {return val}
  1884. };
  1885. if(opts.type === 'bar'){
  1886. opts.yAxis.data[0].categories = opts.categories;
  1887. opts.yAxis.data[0].type = 'categories';
  1888. }
  1889. }
  1890. var yAxisFontSize = opts.yAxis.fontSize * opts.pix || config.fontSize;
  1891. rangesFormatArr[0] = rangesArr[0].map(function(item,index) {
  1892. item = opts.yAxis.data[0].formatter(item,index,opts);
  1893. yAxisWidthArr[0].width = Math.max(yAxisWidthArr[0].width, measureText(item, yAxisFontSize, context) + 5);
  1894. return item;
  1895. });
  1896. yAxisWidthArr[0].width += 3 * opts.pix;
  1897. }
  1898. return {
  1899. rangesFormat: rangesFormatArr,
  1900. ranges: rangesArr,
  1901. yAxisWidth: yAxisWidthArr
  1902. };
  1903. }
  1904. function calTooltipYAxisData(point, series, opts, config, eachSpacing) {
  1905. let ranges = [].concat(opts.chartData.yAxisData.ranges);
  1906. let spacingValid = opts.height - opts.area[0] - opts.area[2];
  1907. let minAxis = opts.area[0];
  1908. let items = [];
  1909. for (let i = 0; i < ranges.length; i++) {
  1910. let maxVal = Math.max.apply(this, ranges[i]);
  1911. let minVal = Math.min.apply(this, ranges[i]);
  1912. let item = maxVal - (maxVal - minVal) * (point - minAxis) / spacingValid;
  1913. item = opts.yAxis.data && opts.yAxis.data[i].formatter ? opts.yAxis.data[i].formatter(item, i, opts) : item.toFixed(0);
  1914. items.push(String(item))
  1915. }
  1916. return items;
  1917. }
  1918. function calMarkLineData(points, opts) {
  1919. let minRange, maxRange;
  1920. let spacingValid = opts.height - opts.area[0] - opts.area[2];
  1921. for (let i = 0; i < points.length; i++) {
  1922. points[i].yAxisIndex = points[i].yAxisIndex ? points[i].yAxisIndex : 0;
  1923. let range = [].concat(opts.chartData.yAxisData.ranges[points[i].yAxisIndex]);
  1924. minRange = range.pop();
  1925. maxRange = range.shift();
  1926. let height = spacingValid * (points[i].value - minRange) / (maxRange - minRange);
  1927. points[i].y = opts.height - Math.round(height) - opts.area[2];
  1928. }
  1929. return points;
  1930. }
  1931. function contextRotate(context, opts) {
  1932. if (opts.rotateLock !== true) {
  1933. context.translate(opts.height, 0);
  1934. context.rotate(90 * Math.PI / 180);
  1935. } else if (opts._rotate_ !== true) {
  1936. context.translate(opts.height, 0);
  1937. context.rotate(90 * Math.PI / 180);
  1938. opts._rotate_ = true;
  1939. }
  1940. }
  1941. function drawPointShape(points, color, shape, context, opts) {
  1942. context.beginPath();
  1943. if (opts.dataPointShapeType == 'hollow') {
  1944. context.setStrokeStyle(color);
  1945. context.setFillStyle(opts.background);
  1946. context.setLineWidth(2 * opts.pix);
  1947. } else {
  1948. context.setStrokeStyle("#ffffff");
  1949. context.setFillStyle(color);
  1950. context.setLineWidth(1 * opts.pix);
  1951. }
  1952. if (shape === 'diamond') {
  1953. points.forEach(function(item, index) {
  1954. if (item !== null) {
  1955. context.moveTo(item.x, item.y - 4.5);
  1956. context.lineTo(item.x - 4.5, item.y);
  1957. context.lineTo(item.x, item.y + 4.5);
  1958. context.lineTo(item.x + 4.5, item.y);
  1959. context.lineTo(item.x, item.y - 4.5);
  1960. }
  1961. });
  1962. } else if (shape === 'circle') {
  1963. points.forEach(function(item, index) {
  1964. if (item !== null) {
  1965. context.moveTo(item.x + 2.5 * opts.pix, item.y);
  1966. context.arc(item.x, item.y, 3 * opts.pix, 0, 2 * Math.PI, false);
  1967. }
  1968. });
  1969. } else if (shape === 'square') {
  1970. points.forEach(function(item, index) {
  1971. if (item !== null) {
  1972. context.moveTo(item.x - 3.5, item.y - 3.5);
  1973. context.rect(item.x - 3.5, item.y - 3.5, 7, 7);
  1974. }
  1975. });
  1976. } else if (shape === 'triangle') {
  1977. points.forEach(function(item, index) {
  1978. if (item !== null) {
  1979. context.moveTo(item.x, item.y - 4.5);
  1980. context.lineTo(item.x - 4.5, item.y + 4.5);
  1981. context.lineTo(item.x + 4.5, item.y + 4.5);
  1982. context.lineTo(item.x, item.y - 4.5);
  1983. }
  1984. });
  1985. } else if (shape === 'none') {
  1986. return;
  1987. }
  1988. context.closePath();
  1989. context.fill();
  1990. context.stroke();
  1991. }
  1992. function drawRingTitle(opts, config, context, center) {
  1993. var titlefontSize = opts.title.fontSize || config.titleFontSize;
  1994. var subtitlefontSize = opts.subtitle.fontSize || config.subtitleFontSize;
  1995. var title = opts.title.name || '';
  1996. var subtitle = opts.subtitle.name || '';
  1997. var titleFontColor = opts.title.color || opts.fontColor;
  1998. var subtitleFontColor = opts.subtitle.color || opts.fontColor;
  1999. var titleHeight = title ? titlefontSize : 0;
  2000. var subtitleHeight = subtitle ? subtitlefontSize : 0;
  2001. var margin = 5;
  2002. if (subtitle) {
  2003. var textWidth = measureText(subtitle, subtitlefontSize * opts.pix, context);
  2004. var startX = center.x - textWidth / 2 + (opts.subtitle.offsetX|| 0) * opts.pix ;
  2005. var startY = center.y + subtitlefontSize * opts.pix / 2 + (opts.subtitle.offsetY || 0) * opts.pix;
  2006. if (title) {
  2007. startY += (titleHeight * opts.pix + margin) / 2;
  2008. }
  2009. context.beginPath();
  2010. context.setFontSize(subtitlefontSize * opts.pix);
  2011. context.setFillStyle(subtitleFontColor);
  2012. context.fillText(subtitle, startX, startY);
  2013. context.closePath();
  2014. context.stroke();
  2015. }
  2016. if (title) {
  2017. var _textWidth = measureText(title, titlefontSize * opts.pix, context);
  2018. var _startX = center.x - _textWidth / 2 + (opts.title.offsetX || 0);
  2019. var _startY = center.y + titlefontSize * opts.pix / 2 + (opts.title.offsetY || 0) * opts.pix;
  2020. if (subtitle) {
  2021. _startY -= (subtitleHeight * opts.pix + margin) / 2;
  2022. }
  2023. context.beginPath();
  2024. context.setFontSize(titlefontSize * opts.pix);
  2025. context.setFillStyle(titleFontColor);
  2026. context.fillText(title, _startX, _startY);
  2027. context.closePath();
  2028. context.stroke();
  2029. }
  2030. }
  2031. function drawPointText(points, series, config, context, opts) {
  2032. // 绘制数据文案
  2033. var data = series.data;
  2034. var textOffset = series.textOffset ? series.textOffset : 0;
  2035. points.forEach(function(item, index) {
  2036. if (item !== null) {
  2037. context.beginPath();
  2038. var fontSize = series.textSize ? series.textSize * opts.pix : config.fontSize;
  2039. context.setFontSize(fontSize);
  2040. context.setFillStyle(series.textColor || opts.fontColor);
  2041. var value = data[index]
  2042. if (typeof data[index] === 'object' && data[index] !== null) {
  2043. if (data[index].constructor.toString().indexOf('Array')>-1) {
  2044. value = data[index][1];
  2045. } else {
  2046. value = data[index].value
  2047. }
  2048. }
  2049. var formatVal = series.formatter ? series.formatter(value,index,series,opts) : value;
  2050. context.setTextAlign('center');
  2051. context.fillText(String(formatVal), item.x, item.y - 4 + textOffset * opts.pix);
  2052. context.closePath();
  2053. context.stroke();
  2054. context.setTextAlign('left');
  2055. }
  2056. });
  2057. }
  2058. function drawMountPointText(points, series, config, context, opts) {
  2059. // 绘制数据文案
  2060. var data = series.data;
  2061. var textOffset = series.textOffset ? series.textOffset : 0;
  2062. points.forEach(function(item, index) {
  2063. if (item !== null) {
  2064. context.beginPath();
  2065. var fontSize = series[index].textSize ? series[index].textSize * opts.pix : config.fontSize;
  2066. context.setFontSize(fontSize);
  2067. context.setFillStyle(series[index].textColor || opts.fontColor);
  2068. var value = item.value
  2069. var formatVal = series[index].formatter ? series[index].formatter(value,index,series,opts) : value;
  2070. context.setTextAlign('center');
  2071. context.fillText(String(formatVal), item.x, item.y - 4 + textOffset * opts.pix);
  2072. context.closePath();
  2073. context.stroke();
  2074. context.setTextAlign('left');
  2075. }
  2076. });
  2077. }
  2078. function drawBarPointText(points, series, config, context, opts) {
  2079. // 绘制数据文案
  2080. var data = series.data;
  2081. var textOffset = series.textOffset ? series.textOffset : 0;
  2082. points.forEach(function(item, index) {
  2083. if (item !== null) {
  2084. context.beginPath();
  2085. var fontSize = series.textSize ? series.textSize * opts.pix : config.fontSize;
  2086. context.setFontSize(fontSize);
  2087. context.setFillStyle(series.textColor || opts.fontColor);
  2088. var value = data[index]
  2089. if (typeof data[index] === 'object' && data[index] !== null) {
  2090. value = data[index].value ;
  2091. }
  2092. var formatVal = series.formatter ? series.formatter(value,index,series,opts) : value;
  2093. context.setTextAlign('left');
  2094. context.fillText(String(formatVal), item.x + 4 * opts.pix , item.y + fontSize / 2 - 3 );
  2095. context.closePath();
  2096. context.stroke();
  2097. }
  2098. });
  2099. }
  2100. function drawGaugeLabel(gaugeOption, radius, centerPosition, opts, config, context) {
  2101. radius -= gaugeOption.width / 2 + gaugeOption.labelOffset * opts.pix;
  2102. radius = radius < 10 ? 10 : radius;
  2103. let totalAngle = gaugeOption.startAngle - gaugeOption.endAngle + 1;
  2104. let splitAngle = totalAngle / gaugeOption.splitLine.splitNumber;
  2105. let totalNumber = gaugeOption.endNumber - gaugeOption.startNumber;
  2106. let splitNumber = totalNumber / gaugeOption.splitLine.splitNumber;
  2107. let nowAngle = gaugeOption.startAngle;
  2108. let nowNumber = gaugeOption.startNumber;
  2109. for (let i = 0; i < gaugeOption.splitLine.splitNumber + 1; i++) {
  2110. var pos = {
  2111. x: radius * Math.cos(nowAngle * Math.PI),
  2112. y: radius * Math.sin(nowAngle * Math.PI)
  2113. };
  2114. var labelText = gaugeOption.formatter ? gaugeOption.formatter(nowNumber,i,opts) : nowNumber;
  2115. pos.x += centerPosition.x - measureText(labelText, config.fontSize, context) / 2;
  2116. pos.y += centerPosition.y;
  2117. var startX = pos.x;
  2118. var startY = pos.y;
  2119. context.beginPath();
  2120. context.setFontSize(config.fontSize);
  2121. context.setFillStyle(gaugeOption.labelColor || opts.fontColor);
  2122. context.fillText(labelText, startX, startY + config.fontSize / 2);
  2123. context.closePath();
  2124. context.stroke();
  2125. nowAngle += splitAngle;
  2126. if (nowAngle >= 2) {
  2127. nowAngle = nowAngle % 2;
  2128. }
  2129. nowNumber += splitNumber;
  2130. }
  2131. }
  2132. function drawRadarLabel(angleList, radius, centerPosition, opts, config, context) {
  2133. var radarOption = opts.extra.radar || {};
  2134. angleList.forEach(function(angle, index) {
  2135. if(radarOption.labelPointShow === true && opts.categories[index] !== ''){
  2136. var posPoint = {
  2137. x: radius * Math.cos(angle),
  2138. y: radius * Math.sin(angle)
  2139. };
  2140. var posPointAxis = convertCoordinateOrigin(posPoint.x, posPoint.y, centerPosition);
  2141. context.setFillStyle(radarOption.labelPointColor);
  2142. context.beginPath();
  2143. context.arc(posPointAxis.x, posPointAxis.y, radarOption.labelPointRadius * opts.pix, 0, 2 * Math.PI, false);
  2144. context.closePath();
  2145. context.fill();
  2146. }
  2147. var pos = {
  2148. x: (radius + config.radarLabelTextMargin * opts.pix) * Math.cos(angle),
  2149. y: (radius + config.radarLabelTextMargin * opts.pix) * Math.sin(angle)
  2150. };
  2151. var posRelativeCanvas = convertCoordinateOrigin(pos.x, pos.y, centerPosition);
  2152. var startX = posRelativeCanvas.x;
  2153. var startY = posRelativeCanvas.y;
  2154. if (util.approximatelyEqual(pos.x, 0)) {
  2155. startX -= measureText(opts.categories[index] || '', config.fontSize, context) / 2;
  2156. } else if (pos.x < 0) {
  2157. startX -= measureText(opts.categories[index] || '', config.fontSize, context);
  2158. }
  2159. context.beginPath();
  2160. context.setFontSize(config.fontSize);
  2161. context.setFillStyle(radarOption.labelColor || opts.fontColor);
  2162. context.fillText(opts.categories[index] || '', startX, startY + config.fontSize / 2);
  2163. context.closePath();
  2164. context.stroke();
  2165. });
  2166. }
  2167. function drawPieText(series, opts, config, context, radius, center) {
  2168. var lineRadius = config.pieChartLinePadding;
  2169. var textObjectCollection = [];
  2170. var lastTextObject = null;
  2171. var seriesConvert = series.map(function(item,index) {
  2172. var text = item.formatter ? item.formatter(item,index,series,opts) : util.toFixed(item._proportion_.toFixed(4) * 100) + '%';
  2173. text = item.labelText ? item.labelText : text;
  2174. var arc = 2 * Math.PI - (item._start_ + 2 * Math.PI * item._proportion_ / 2);
  2175. if (item._rose_proportion_) {
  2176. arc = 2 * Math.PI - (item._start_ + 2 * Math.PI * item._rose_proportion_ / 2);
  2177. }
  2178. var color = item.color;
  2179. var radius = item._radius_;
  2180. return {
  2181. arc: arc,
  2182. text: text,
  2183. color: color,
  2184. radius: radius,
  2185. textColor: item.textColor,
  2186. textSize: item.textSize,
  2187. labelShow: item.labelShow
  2188. };
  2189. });
  2190. for (let i = 0; i < seriesConvert.length; i++) {
  2191. let item = seriesConvert[i];
  2192. // line end
  2193. let orginX1 = Math.cos(item.arc) * (item.radius + lineRadius);
  2194. let orginY1 = Math.sin(item.arc) * (item.radius + lineRadius);
  2195. // line start
  2196. let orginX2 = Math.cos(item.arc) * item.radius;
  2197. let orginY2 = Math.sin(item.arc) * item.radius;
  2198. // text start
  2199. let orginX3 = orginX1 >= 0 ? orginX1 + config.pieChartTextPadding : orginX1 - config.pieChartTextPadding;
  2200. let orginY3 = orginY1;
  2201. let textWidth = measureText(item.text, item.textSize * opts.pix || config.fontSize, context);
  2202. let startY = orginY3;
  2203. if (lastTextObject && util.isSameXCoordinateArea(lastTextObject.start, {
  2204. x: orginX3
  2205. })) {
  2206. if (orginX3 > 0) {
  2207. startY = Math.min(orginY3, lastTextObject.start.y);
  2208. } else if (orginX1 < 0) {
  2209. startY = Math.max(orginY3, lastTextObject.start.y);
  2210. } else {
  2211. if (orginY3 > 0) {
  2212. startY = Math.max(orginY3, lastTextObject.start.y);
  2213. } else {
  2214. startY = Math.min(orginY3, lastTextObject.start.y);
  2215. }
  2216. }
  2217. }
  2218. if (orginX3 < 0) {
  2219. orginX3 -= textWidth;
  2220. }
  2221. let textObject = {
  2222. lineStart: {
  2223. x: orginX2,
  2224. y: orginY2
  2225. },
  2226. lineEnd: {
  2227. x: orginX1,
  2228. y: orginY1
  2229. },
  2230. start: {
  2231. x: orginX3,
  2232. y: startY
  2233. },
  2234. width: textWidth,
  2235. height: config.fontSize,
  2236. text: item.text,
  2237. color: item.color,
  2238. textColor: item.textColor,
  2239. textSize: item.textSize
  2240. };
  2241. lastTextObject = avoidCollision(textObject, lastTextObject);
  2242. textObjectCollection.push(lastTextObject);
  2243. }
  2244. for (let i = 0; i < textObjectCollection.length; i++) {
  2245. if(seriesConvert[i].labelShow === false){
  2246. continue;
  2247. }
  2248. let item = textObjectCollection[i];
  2249. let lineStartPoistion = convertCoordinateOrigin(item.lineStart.x, item.lineStart.y, center);
  2250. let lineEndPoistion = convertCoordinateOrigin(item.lineEnd.x, item.lineEnd.y, center);
  2251. let textPosition = convertCoordinateOrigin(item.start.x, item.start.y, center);
  2252. context.setLineWidth(1 * opts.pix);
  2253. context.setFontSize(item.textSize * opts.pix || config.fontSize);
  2254. context.beginPath();
  2255. context.setStrokeStyle(item.color);
  2256. context.setFillStyle(item.color);
  2257. context.moveTo(lineStartPoistion.x, lineStartPoistion.y);
  2258. let curveStartX = item.start.x < 0 ? textPosition.x + item.width : textPosition.x;
  2259. let textStartX = item.start.x < 0 ? textPosition.x - 5 : textPosition.x + 5;
  2260. context.quadraticCurveTo(lineEndPoistion.x, lineEndPoistion.y, curveStartX, textPosition.y);
  2261. context.moveTo(lineStartPoistion.x, lineStartPoistion.y);
  2262. context.stroke();
  2263. context.closePath();
  2264. context.beginPath();
  2265. context.moveTo(textPosition.x + item.width, textPosition.y);
  2266. context.arc(curveStartX, textPosition.y, 2 * opts.pix, 0, 2 * Math.PI);
  2267. context.closePath();
  2268. context.fill();
  2269. context.beginPath();
  2270. context.setFontSize(item.textSize * opts.pix || config.fontSize);
  2271. context.setFillStyle(item.textColor || opts.fontColor);
  2272. context.fillText(item.text, textStartX, textPosition.y + 3);
  2273. context.closePath();
  2274. context.stroke();
  2275. context.closePath();
  2276. }
  2277. }
  2278. function drawToolTipSplitLine(offsetX, opts, config, context) {
  2279. var toolTipOption = opts.extra.tooltip || {};
  2280. toolTipOption.gridType = toolTipOption.gridType == undefined ? 'solid' : toolTipOption.gridType;
  2281. toolTipOption.dashLength = toolTipOption.dashLength == undefined ? 4 : toolTipOption.dashLength;
  2282. var startY = opts.area[0];
  2283. var endY = opts.height - opts.area[2];
  2284. if (toolTipOption.gridType == 'dash') {
  2285. context.setLineDash([toolTipOption.dashLength, toolTipOption.dashLength]);
  2286. }
  2287. context.setStrokeStyle(toolTipOption.gridColor || '#cccccc');
  2288. context.setLineWidth(1 * opts.pix);
  2289. context.beginPath();
  2290. context.moveTo(offsetX, startY);
  2291. context.lineTo(offsetX, endY);
  2292. context.stroke();
  2293. context.setLineDash([]);
  2294. if (toolTipOption.xAxisLabel) {
  2295. let labelText = opts.categories[opts.tooltip.index];
  2296. context.setFontSize(config.fontSize);
  2297. let textWidth = measureText(labelText, config.fontSize, context);
  2298. let textX = offsetX - 0.5 * textWidth;
  2299. let textY = endY + 2 * opts.pix;
  2300. context.beginPath();
  2301. context.setFillStyle(hexToRgb(toolTipOption.labelBgColor || config.toolTipBackground, toolTipOption.labelBgOpacity || config.toolTipOpacity));
  2302. context.setStrokeStyle(toolTipOption.labelBgColor || config.toolTipBackground);
  2303. context.setLineWidth(1 * opts.pix);
  2304. context.rect(textX - config.toolTipPadding, textY, textWidth + 2 * config.toolTipPadding, config.fontSize + 2 * config.toolTipPadding);
  2305. context.closePath();
  2306. context.stroke();
  2307. context.fill();
  2308. context.beginPath();
  2309. context.setFontSize(config.fontSize);
  2310. context.setFillStyle(toolTipOption.labelFontColor || opts.fontColor);
  2311. context.fillText(String(labelText), textX, textY + config.toolTipPadding + config.fontSize);
  2312. context.closePath();
  2313. context.stroke();
  2314. }
  2315. }
  2316. function drawMarkLine(opts, config, context) {
  2317. let markLineOption = assign({}, {
  2318. type: 'solid',
  2319. dashLength: 4,
  2320. data: []
  2321. }, opts.extra.markLine);
  2322. let startX = opts.area[3];
  2323. let endX = opts.width - opts.area[1];
  2324. let points = calMarkLineData(markLineOption.data, opts);
  2325. for (let i = 0; i < points.length; i++) {
  2326. let item = assign({}, {
  2327. lineColor: '#DE4A42',
  2328. showLabel: false,
  2329. labelFontColor: '#666666',
  2330. labelBgColor: '#DFE8FF',
  2331. labelBgOpacity: 0.8,
  2332. labelAlign: 'left',
  2333. labelOffsetX: 0,
  2334. labelOffsetY: 0,
  2335. }, points[i]);
  2336. if (markLineOption.type == 'dash') {
  2337. context.setLineDash([markLineOption.dashLength, markLineOption.dashLength]);
  2338. }
  2339. context.setStrokeStyle(item.lineColor);
  2340. context.setLineWidth(1 * opts.pix);
  2341. context.beginPath();
  2342. context.moveTo(startX, item.y);
  2343. context.lineTo(endX, item.y);
  2344. context.stroke();
  2345. context.setLineDash([]);
  2346. if (item.showLabel) {
  2347. let labelText = item.labelText ? item.labelText : item.value;
  2348. context.setFontSize(config.fontSize);
  2349. let textWidth = measureText(labelText, config.fontSize, context);
  2350. let bgWidth = textWidth + config.toolTipPadding * 2;
  2351. let bgStartX = item.labelAlign == 'left' ? opts.area[3] - bgWidth : opts.width - opts.area[1];
  2352. bgStartX += item.labelOffsetX;
  2353. let bgStartY = item.y - 0.5 * config.fontSize - config.toolTipPadding;
  2354. bgStartY += item.labelOffsetY;
  2355. let textX = bgStartX + config.toolTipPadding;
  2356. let textY = item.y;
  2357. context.setFillStyle(hexToRgb(item.labelBgColor, item.labelBgOpacity));
  2358. context.setStrokeStyle(item.labelBgColor);
  2359. context.setLineWidth(1 * opts.pix);
  2360. context.beginPath();
  2361. context.rect(bgStartX, bgStartY, bgWidth, config.fontSize + 2 * config.toolTipPadding);
  2362. context.closePath();
  2363. context.stroke();
  2364. context.fill();
  2365. context.setFontSize(config.fontSize);
  2366. context.setTextAlign('left');
  2367. context.setFillStyle(item.labelFontColor);
  2368. context.fillText(String(labelText), textX, bgStartY + config.fontSize + config.toolTipPadding/2);
  2369. context.stroke();
  2370. context.setTextAlign('left');
  2371. }
  2372. }
  2373. }
  2374. function drawToolTipHorizentalLine(opts, config, context, eachSpacing, xAxisPoints) {
  2375. var toolTipOption = assign({}, {
  2376. gridType: 'solid',
  2377. dashLength: 4
  2378. }, opts.extra.tooltip);
  2379. var startX = opts.area[3];
  2380. var endX = opts.width - opts.area[1];
  2381. if (toolTipOption.gridType == 'dash') {
  2382. context.setLineDash([toolTipOption.dashLength, toolTipOption.dashLength]);
  2383. }
  2384. context.setStrokeStyle(toolTipOption.gridColor || '#cccccc');
  2385. context.setLineWidth(1 * opts.pix);
  2386. context.beginPath();
  2387. context.moveTo(startX, opts.tooltip.offset.y);
  2388. context.lineTo(endX, opts.tooltip.offset.y);
  2389. context.stroke();
  2390. context.setLineDash([]);
  2391. if (toolTipOption.yAxisLabel) {
  2392. let labelText = calTooltipYAxisData(opts.tooltip.offset.y, opts.series, opts, config, eachSpacing);
  2393. let widthArr = opts.chartData.yAxisData.yAxisWidth;
  2394. let tStartLeft = opts.area[3];
  2395. let tStartRight = opts.width - opts.area[1];
  2396. for (let i = 0; i < labelText.length; i++) {
  2397. context.setFontSize(config.fontSize);
  2398. let textWidth = measureText(labelText[i], config.fontSize, context);
  2399. let bgStartX, bgEndX, bgWidth;
  2400. if (widthArr[i].position == 'left') {
  2401. bgStartX = tStartLeft - (textWidth + config.toolTipPadding * 2) - 2 * opts.pix;
  2402. bgEndX = Math.max(bgStartX, bgStartX + textWidth + config.toolTipPadding * 2);
  2403. } else {
  2404. bgStartX = tStartRight + 2 * opts.pix;
  2405. bgEndX = Math.max(bgStartX + widthArr[i].width, bgStartX + textWidth + config.toolTipPadding * 2);
  2406. }
  2407. bgWidth = bgEndX - bgStartX;
  2408. let textX = bgStartX + (bgWidth - textWidth) / 2;
  2409. let textY = opts.tooltip.offset.y;
  2410. context.beginPath();
  2411. context.setFillStyle(hexToRgb(toolTipOption.labelBgColor || config.toolTipBackground, toolTipOption.labelBgOpacity || config.toolTipOpacity));
  2412. context.setStrokeStyle(toolTipOption.labelBgColor || config.toolTipBackground);
  2413. context.setLineWidth(1 * opts.pix);
  2414. context.rect(bgStartX, textY - 0.5 * config.fontSize - config.toolTipPadding, bgWidth, config.fontSize + 2 * config.toolTipPadding);
  2415. context.closePath();
  2416. context.stroke();
  2417. context.fill();
  2418. context.beginPath();
  2419. context.setFontSize(config.fontSize);
  2420. context.setFillStyle(toolTipOption.labelFontColor || opts.fontColor);
  2421. context.fillText(labelText[i], textX, textY + 0.5 * config.fontSize);
  2422. context.closePath();
  2423. context.stroke();
  2424. if (widthArr[i].position == 'left') {
  2425. tStartLeft -= (widthArr[i].width + opts.yAxis.padding * opts.pix);
  2426. } else {
  2427. tStartRight += widthArr[i].width + opts.yAxis.padding * opts.pix;
  2428. }
  2429. }
  2430. }
  2431. }
  2432. function drawToolTipSplitArea(offsetX, opts, config, context, eachSpacing) {
  2433. var toolTipOption = assign({}, {
  2434. activeBgColor: '#000000',
  2435. activeBgOpacity: 0.08,
  2436. activeWidth: eachSpacing
  2437. }, opts.extra.column);
  2438. toolTipOption.activeWidth = toolTipOption.activeWidth > eachSpacing ? eachSpacing : toolTipOption.activeWidth;
  2439. var startY = opts.area[0];
  2440. var endY = opts.height - opts.area[2];
  2441. context.beginPath();
  2442. context.setFillStyle(hexToRgb(toolTipOption.activeBgColor, toolTipOption.activeBgOpacity));
  2443. context.rect(offsetX - toolTipOption.activeWidth / 2, startY, toolTipOption.activeWidth, endY - startY);
  2444. context.closePath();
  2445. context.fill();
  2446. context.setFillStyle("#FFFFFF");
  2447. }
  2448. function drawBarToolTipSplitArea(offsetX, opts, config, context, eachSpacing) {
  2449. var toolTipOption = assign({}, {
  2450. activeBgColor: '#000000',
  2451. activeBgOpacity: 0.08
  2452. }, opts.extra.bar);
  2453. var startX = opts.area[3];
  2454. var endX = opts.width - opts.area[1];
  2455. context.beginPath();
  2456. context.setFillStyle(hexToRgb(toolTipOption.activeBgColor, toolTipOption.activeBgOpacity));
  2457. context.rect( startX ,offsetX - eachSpacing / 2 , endX - startX,eachSpacing);
  2458. context.closePath();
  2459. context.fill();
  2460. context.setFillStyle("#FFFFFF");
  2461. }
  2462. function drawToolTip(textList, offset, opts, config, context, eachSpacing, xAxisPoints) {
  2463. var toolTipOption = assign({}, {
  2464. showBox: true,
  2465. showArrow: true,
  2466. showCategory: false,
  2467. bgColor: '#000000',
  2468. bgOpacity: 0.7,
  2469. borderColor: '#000000',
  2470. borderWidth: 0,
  2471. borderRadius: 0,
  2472. borderOpacity: 0.7,
  2473. fontColor: '#FFFFFF',
  2474. splitLine: true,
  2475. }, opts.extra.tooltip);
  2476. if(toolTipOption.showCategory==true && opts.categories){
  2477. textList.unshift({text:opts.categories[opts.tooltip.index],color:null})
  2478. }
  2479. var legendWidth = 4 * opts.pix;
  2480. var legendMarginRight = 5 * opts.pix;
  2481. var arrowWidth = toolTipOption.showArrow ? 8 * opts.pix : 0;
  2482. var isOverRightBorder = false;
  2483. if (opts.type == 'line' || opts.type == 'mount' || opts.type == 'area' || opts.type == 'candle' || opts.type == 'mix') {
  2484. if (toolTipOption.splitLine == true) {
  2485. drawToolTipSplitLine(opts.tooltip.offset.x, opts, config, context);
  2486. }
  2487. }
  2488. offset = assign({
  2489. x: 0,
  2490. y: 0
  2491. }, offset);
  2492. offset.y -= 8 * opts.pix;
  2493. var textWidth = textList.map(function(item) {
  2494. return measureText(item.text, config.fontSize, context);
  2495. });
  2496. var toolTipWidth = legendWidth + legendMarginRight + 4 * config.toolTipPadding + Math.max.apply(null, textWidth);
  2497. var toolTipHeight = 2 * config.toolTipPadding + textList.length * config.toolTipLineHeight;
  2498. if (toolTipOption.showBox == false) {
  2499. return
  2500. }
  2501. // if beyond the right border
  2502. if (offset.x - Math.abs(opts._scrollDistance_ || 0) + arrowWidth + toolTipWidth > opts.width) {
  2503. isOverRightBorder = true;
  2504. }
  2505. if (toolTipHeight + offset.y > opts.height) {
  2506. offset.y = opts.height - toolTipHeight;
  2507. }
  2508. // draw background rect
  2509. context.beginPath();
  2510. context.setFillStyle(hexToRgb(toolTipOption.bgColor || config.toolTipBackground, toolTipOption.bgOpacity || config.toolTipOpacity));
  2511. context.setLineWidth(toolTipOption.borderWidth * opts.pix);
  2512. context.setStrokeStyle(hexToRgb(toolTipOption.borderColor, toolTipOption.borderOpacity));
  2513. var radius = toolTipOption.borderRadius;
  2514. if (isOverRightBorder) {
  2515. // 增加左侧仍然超出的判断
  2516. if(toolTipWidth + arrowWidth > opts.width){
  2517. offset.x = opts.width + Math.abs(opts._scrollDistance_ || 0) + arrowWidth + (toolTipWidth - opts.width)
  2518. }
  2519. if (toolTipOption.showArrow) {
  2520. context.moveTo(offset.x, offset.y + 10 * opts.pix);
  2521. context.lineTo(offset.x - arrowWidth, offset.y + 10 * opts.pix + 5 * opts.pix);
  2522. }
  2523. context.arc(offset.x - arrowWidth - radius, offset.y + toolTipHeight - radius, radius, 0, Math.PI / 2, false);
  2524. context.arc(offset.x - arrowWidth - Math.round(toolTipWidth) + radius, offset.y + toolTipHeight - radius, radius,
  2525. Math.PI / 2, Math.PI, false);
  2526. context.arc(offset.x - arrowWidth - Math.round(toolTipWidth) + radius, offset.y + radius, radius, -Math.PI, -Math.PI / 2, false);
  2527. context.arc(offset.x - arrowWidth - radius, offset.y + radius, radius, -Math.PI / 2, 0, false);
  2528. if (toolTipOption.showArrow) {
  2529. context.lineTo(offset.x - arrowWidth, offset.y + 10 * opts.pix - 5 * opts.pix);
  2530. context.lineTo(offset.x, offset.y + 10 * opts.pix);
  2531. }
  2532. } else {
  2533. if (toolTipOption.showArrow) {
  2534. context.moveTo(offset.x, offset.y + 10 * opts.pix);
  2535. context.lineTo(offset.x + arrowWidth, offset.y + 10 * opts.pix - 5 * opts.pix);
  2536. }
  2537. context.arc(offset.x + arrowWidth + radius, offset.y + radius, radius, -Math.PI, -Math.PI / 2, false);
  2538. context.arc(offset.x + arrowWidth + Math.round(toolTipWidth) - radius, offset.y + radius, radius, -Math.PI / 2, 0,
  2539. false);
  2540. context.arc(offset.x + arrowWidth + Math.round(toolTipWidth) - radius, offset.y + toolTipHeight - radius, radius, 0,
  2541. Math.PI / 2, false);
  2542. context.arc(offset.x + arrowWidth + radius, offset.y + toolTipHeight - radius, radius, Math.PI / 2, Math.PI, false);
  2543. if (toolTipOption.showArrow) {
  2544. context.lineTo(offset.x + arrowWidth, offset.y + 10 * opts.pix + 5 * opts.pix);
  2545. context.lineTo(offset.x, offset.y + 10 * opts.pix);
  2546. }
  2547. }
  2548. context.closePath();
  2549. context.fill();
  2550. if (toolTipOption.borderWidth > 0) {
  2551. context.stroke();
  2552. }
  2553. // draw legend
  2554. textList.forEach(function(item, index) {
  2555. if (item.color !== null) {
  2556. context.beginPath();
  2557. context.setFillStyle(item.color);
  2558. var startX = offset.x + arrowWidth + 2 * config.toolTipPadding;
  2559. var startY = offset.y + (config.toolTipLineHeight - config.fontSize) / 2 + config.toolTipLineHeight * index + config.toolTipPadding + 1;
  2560. if (isOverRightBorder) {
  2561. startX = offset.x - toolTipWidth - arrowWidth + 2 * config.toolTipPadding;
  2562. }
  2563. context.fillRect(startX, startY, legendWidth, config.fontSize);
  2564. // 圆形图例请注释上行,并把下行取消注释
  2565. // context.arc(startX + legendWidth / 2 , startY + opts.fontSize / 2, 4 * opts.pix, 0, 2 * Math.PI);
  2566. context.closePath();
  2567. context.fill();
  2568. }
  2569. });
  2570. // draw text list
  2571. textList.forEach(function(item, index) {
  2572. var startX = offset.x + arrowWidth + 2 * config.toolTipPadding + legendWidth + legendMarginRight;
  2573. if (isOverRightBorder) {
  2574. startX = offset.x - toolTipWidth - arrowWidth + 2 * config.toolTipPadding + +legendWidth + legendMarginRight;
  2575. }
  2576. var startY = offset.y + (config.toolTipLineHeight - config.fontSize) / 2 + config.toolTipLineHeight * index + config.toolTipPadding;
  2577. context.beginPath();
  2578. context.setFontSize(config.fontSize);
  2579. context.setFillStyle(toolTipOption.fontColor);
  2580. context.fillText(item.text, startX, startY + config.fontSize);
  2581. context.closePath();
  2582. context.stroke();
  2583. });
  2584. }
  2585. function drawColumnDataPoints(series, opts, config, context) {
  2586. let process = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : 1;
  2587. let xAxisData = opts.chartData.xAxisData,
  2588. xAxisPoints = xAxisData.xAxisPoints,
  2589. eachSpacing = xAxisData.eachSpacing;
  2590. let columnOption = assign({}, {
  2591. type: 'group',
  2592. width: eachSpacing / 2,
  2593. meterBorder: 4,
  2594. meterFillColor: '#FFFFFF',
  2595. barBorderCircle: false,
  2596. barBorderRadius: [],
  2597. seriesGap: 2,
  2598. linearType: 'none',
  2599. linearOpacity: 1,
  2600. customColor: [],
  2601. colorStop: 0,
  2602. }, opts.extra.column);
  2603. let calPoints = [];
  2604. context.save();
  2605. let leftNum = -2;
  2606. let rightNum = xAxisPoints.length + 2;
  2607. if (opts._scrollDistance_ && opts._scrollDistance_ !== 0 && opts.enableScroll === true) {
  2608. context.translate(opts._scrollDistance_, 0);
  2609. leftNum = Math.floor(-opts._scrollDistance_ / eachSpacing) - 2;
  2610. rightNum = leftNum + opts.xAxis.itemCount + 4;
  2611. }
  2612. if (opts.tooltip && opts.tooltip.textList && opts.tooltip.textList.length && process === 1) {
  2613. drawToolTipSplitArea(opts.tooltip.offset.x, opts, config, context, eachSpacing);
  2614. }
  2615. columnOption.customColor = fillCustomColor(columnOption.linearType, columnOption.customColor, series, config);
  2616. series.forEach(function(eachSeries, seriesIndex) {
  2617. let ranges, minRange, maxRange;
  2618. ranges = [].concat(opts.chartData.yAxisData.ranges[eachSeries.index]);
  2619. minRange = ranges.pop();
  2620. maxRange = ranges.shift();
  2621. var data = eachSeries.data;
  2622. switch (columnOption.type) {
  2623. case 'group':
  2624. var points = getDataPoints(data, minRange, maxRange, xAxisPoints, eachSpacing, opts, config, process);
  2625. var tooltipPoints = getStackDataPoints(data, minRange, maxRange, xAxisPoints, eachSpacing, opts, config, seriesIndex, series, process);
  2626. calPoints.push(tooltipPoints);
  2627. points = fixColumeData(points, eachSpacing, series.length, seriesIndex, config, opts);
  2628. for (let i = 0; i < points.length; i++) {
  2629. let item = points[i];
  2630. //fix issues/I27B1N yyoinge & Joeshu
  2631. if (item !== null && i > leftNum && i < rightNum) {
  2632. var startX = item.x - item.width / 2;
  2633. var height = opts.height - item.y - opts.area[2];
  2634. context.beginPath();
  2635. var fillColor = item.color || eachSeries.color
  2636. var strokeColor = item.color || eachSeries.color
  2637. if (columnOption.linearType !== 'none') {
  2638. var grd = context.createLinearGradient(startX, item.y, startX, opts.height - opts.area[2]);
  2639. //透明渐变
  2640. if (columnOption.linearType == 'opacity') {
  2641. grd.addColorStop(0, hexToRgb(fillColor, columnOption.linearOpacity));
  2642. grd.addColorStop(1, hexToRgb(fillColor, 1));
  2643. } else {
  2644. grd.addColorStop(0, hexToRgb(columnOption.customColor[eachSeries.linearIndex], columnOption.linearOpacity));
  2645. grd.addColorStop(columnOption.colorStop, hexToRgb(columnOption.customColor[eachSeries.linearIndex],columnOption.linearOpacity));
  2646. grd.addColorStop(1, hexToRgb(fillColor, 1));
  2647. }
  2648. fillColor = grd
  2649. }
  2650. // 圆角边框
  2651. if ((columnOption.barBorderRadius && columnOption.barBorderRadius.length === 4) || columnOption.barBorderCircle === true) {
  2652. const left = startX;
  2653. const top = item.y;
  2654. const width = item.width;
  2655. const height = opts.height - opts.area[2] - item.y;
  2656. if (columnOption.barBorderCircle) {
  2657. columnOption.barBorderRadius = [width / 2, width / 2, 0, 0];
  2658. }
  2659. let [r0, r1, r2, r3] = columnOption.barBorderRadius;
  2660. let minRadius = Math.min(width/2,height/2);
  2661. r0 = r0 > minRadius ? minRadius : r0;
  2662. r1 = r1 > minRadius ? minRadius : r1;
  2663. r2 = r2 > minRadius ? minRadius : r2;
  2664. r3 = r3 > minRadius ? minRadius : r3;
  2665. r0 = r0 < 0 ? 0 : r0;
  2666. r1 = r1 < 0 ? 0 : r1;
  2667. r2 = r2 < 0 ? 0 : r2;
  2668. r3 = r3 < 0 ? 0 : r3;
  2669. context.arc(left + r0, top + r0, r0, -Math.PI, -Math.PI / 2);
  2670. context.arc(left + width - r1, top + r1, r1, -Math.PI / 2, 0);
  2671. context.arc(left + width - r2, top + height - r2, r2, 0, Math.PI / 2);
  2672. context.arc(left + r3, top + height - r3, r3, Math.PI / 2, Math.PI);
  2673. } else {
  2674. context.moveTo(startX, item.y);
  2675. context.lineTo(startX + item.width, item.y);
  2676. context.lineTo(startX + item.width, opts.height - opts.area[2]);
  2677. context.lineTo(startX, opts.height - opts.area[2]);
  2678. context.lineTo(startX, item.y);
  2679. context.setLineWidth(1)
  2680. context.setStrokeStyle(strokeColor);
  2681. }
  2682. context.setFillStyle(fillColor);
  2683. context.closePath();
  2684. //context.stroke();
  2685. context.fill();
  2686. }
  2687. };
  2688. break;
  2689. case 'stack':
  2690. // 绘制堆叠数据图
  2691. var points = getStackDataPoints(data, minRange, maxRange, xAxisPoints, eachSpacing, opts, config, seriesIndex, series, process);
  2692. calPoints.push(points);
  2693. points = fixColumeStackData(points, eachSpacing, series.length, seriesIndex, config, opts, series);
  2694. for (let i = 0; i < points.length; i++) {
  2695. let item = points[i];
  2696. if (item !== null && i > leftNum && i < rightNum) {
  2697. context.beginPath();
  2698. var fillColor = item.color || eachSeries.color;
  2699. var startX = item.x - item.width / 2 + 1;
  2700. var height = opts.height - item.y - opts.area[2];
  2701. var height0 = opts.height - item.y0 - opts.area[2];
  2702. if (seriesIndex > 0) {
  2703. height -= height0;
  2704. }
  2705. context.setFillStyle(fillColor);
  2706. context.moveTo(startX, item.y);
  2707. context.fillRect(startX, item.y, item.width, height);
  2708. context.closePath();
  2709. context.fill();
  2710. }
  2711. };
  2712. break;
  2713. case 'meter':
  2714. // 绘制温度计数据图
  2715. var points = getDataPoints(data, minRange, maxRange, xAxisPoints, eachSpacing, opts, config, process);
  2716. calPoints.push(points);
  2717. points = fixColumeMeterData(points, eachSpacing, series.length, seriesIndex, config, opts, columnOption.meterBorder);
  2718. for (let i = 0; i < points.length; i++) {
  2719. let item = points[i];
  2720. if (item !== null && i > leftNum && i < rightNum) {
  2721. //画背景颜色
  2722. context.beginPath();
  2723. if (seriesIndex == 0 && columnOption.meterBorder > 0) {
  2724. context.setStrokeStyle(eachSeries.color);
  2725. context.setLineWidth(columnOption.meterBorder * opts.pix);
  2726. }
  2727. if(seriesIndex == 0){
  2728. context.setFillStyle(columnOption.meterFillColor);
  2729. }else{
  2730. context.setFillStyle(item.color || eachSeries.color);
  2731. }
  2732. var startX = item.x - item.width / 2;
  2733. var height = opts.height - item.y - opts.area[2];
  2734. if ((columnOption.barBorderRadius && columnOption.barBorderRadius.length === 4) || columnOption.barBorderCircle === true) {
  2735. const left = startX;
  2736. const top = item.y;
  2737. const width = item.width;
  2738. const height = opts.height - opts.area[2] - item.y;
  2739. if (columnOption.barBorderCircle) {
  2740. columnOption.barBorderRadius = [width / 2, width / 2, 0, 0];
  2741. }
  2742. let [r0, r1, r2, r3] = columnOption.barBorderRadius;
  2743. let minRadius = Math.min(width/2,height/2);
  2744. r0 = r0 > minRadius ? minRadius : r0;
  2745. r1 = r1 > minRadius ? minRadius : r1;
  2746. r2 = r2 > minRadius ? minRadius : r2;
  2747. r3 = r3 > minRadius ? minRadius : r3;
  2748. r0 = r0 < 0 ? 0 : r0;
  2749. r1 = r1 < 0 ? 0 : r1;
  2750. r2 = r2 < 0 ? 0 : r2;
  2751. r3 = r3 < 0 ? 0 : r3;
  2752. context.arc(left + r0, top + r0, r0, -Math.PI, -Math.PI / 2);
  2753. context.arc(left + width - r1, top + r1, r1, -Math.PI / 2, 0);
  2754. context.arc(left + width - r2, top + height - r2, r2, 0, Math.PI / 2);
  2755. context.arc(left + r3, top + height - r3, r3, Math.PI / 2, Math.PI);
  2756. context.fill();
  2757. }else{
  2758. context.moveTo(startX, item.y);
  2759. context.lineTo(startX + item.width, item.y);
  2760. context.lineTo(startX + item.width, opts.height - opts.area[2]);
  2761. context.lineTo(startX, opts.height - opts.area[2]);
  2762. context.lineTo(startX, item.y);
  2763. context.fill();
  2764. }
  2765. if (seriesIndex == 0 && columnOption.meterBorder > 0) {
  2766. context.closePath();
  2767. context.stroke();
  2768. }
  2769. }
  2770. }
  2771. break;
  2772. }
  2773. });
  2774. if (opts.dataLabel !== false && process === 1) {
  2775. series.forEach(function(eachSeries, seriesIndex) {
  2776. let ranges, minRange, maxRange;
  2777. ranges = [].concat(opts.chartData.yAxisData.ranges[eachSeries.index]);
  2778. minRange = ranges.pop();
  2779. maxRange = ranges.shift();
  2780. var data = eachSeries.data;
  2781. switch (columnOption.type) {
  2782. case 'group':
  2783. var points = getDataPoints(data, minRange, maxRange, xAxisPoints, eachSpacing, opts, config, process);
  2784. points = fixColumeData(points, eachSpacing, series.length, seriesIndex, config, opts);
  2785. drawPointText(points, eachSeries, config, context, opts);
  2786. break;
  2787. case 'stack':
  2788. var points = getStackDataPoints(data, minRange, maxRange, xAxisPoints, eachSpacing, opts, config, seriesIndex, series, process);
  2789. drawPointText(points, eachSeries, config, context, opts);
  2790. break;
  2791. case 'meter':
  2792. var points = getDataPoints(data, minRange, maxRange, xAxisPoints, eachSpacing, opts, config, process);
  2793. drawPointText(points, eachSeries, config, context, opts);
  2794. break;
  2795. }
  2796. });
  2797. }
  2798. context.restore();
  2799. return {
  2800. xAxisPoints: xAxisPoints,
  2801. calPoints: calPoints,
  2802. eachSpacing: eachSpacing
  2803. };
  2804. }
  2805. function drawMountDataPoints(series, opts, config, context) {
  2806. let process = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : 1;
  2807. let xAxisData = opts.chartData.xAxisData,
  2808. xAxisPoints = xAxisData.xAxisPoints,
  2809. eachSpacing = xAxisData.eachSpacing;
  2810. let mountOption = assign({}, {
  2811. type: 'mount',
  2812. widthRatio: 1,
  2813. borderWidth: 1,
  2814. barBorderCircle: false,
  2815. barBorderRadius: [],
  2816. linearType: 'none',
  2817. linearOpacity: 1,
  2818. customColor: [],
  2819. colorStop: 0,
  2820. }, opts.extra.mount);
  2821. mountOption.widthRatio = mountOption.widthRatio <= 0 ? 0 : mountOption.widthRatio;
  2822. mountOption.widthRatio = mountOption.widthRatio >= 2 ? 2 : mountOption.widthRatio;
  2823. let calPoints = [];
  2824. context.save();
  2825. let leftNum = -2;
  2826. let rightNum = xAxisPoints.length + 2;
  2827. if (opts._scrollDistance_ && opts._scrollDistance_ !== 0 && opts.enableScroll === true) {
  2828. context.translate(opts._scrollDistance_, 0);
  2829. leftNum = Math.floor(-opts._scrollDistance_ / eachSpacing) - 2;
  2830. rightNum = leftNum + opts.xAxis.itemCount + 4;
  2831. }
  2832. mountOption.customColor = fillCustomColor(mountOption.linearType, mountOption.customColor, series, config);
  2833. let ranges, minRange, maxRange;
  2834. ranges = [].concat(opts.chartData.yAxisData.ranges[0]);
  2835. minRange = ranges.pop();
  2836. maxRange = ranges.shift();
  2837. var points = getMountDataPoints(series, minRange, maxRange, xAxisPoints, eachSpacing, opts, mountOption, process);
  2838. switch (mountOption.type) {
  2839. case 'bar':
  2840. for (let i = 0; i < points.length; i++) {
  2841. let item = points[i];
  2842. if (item !== null && i > leftNum && i < rightNum) {
  2843. var startX = item.x - eachSpacing*mountOption.widthRatio/2;
  2844. var height = opts.height - item.y - opts.area[2];
  2845. context.beginPath();
  2846. var fillColor = item.color || series[i].color
  2847. var strokeColor = item.color || series[i].color
  2848. if (mountOption.linearType !== 'none') {
  2849. var grd = context.createLinearGradient(startX, item.y, startX, opts.height - opts.area[2]);
  2850. //透明渐变
  2851. if (mountOption.linearType == 'opacity') {
  2852. grd.addColorStop(0, hexToRgb(fillColor, mountOption.linearOpacity));
  2853. grd.addColorStop(1, hexToRgb(fillColor, 1));
  2854. } else {
  2855. grd.addColorStop(0, hexToRgb(mountOption.customColor[series[i].linearIndex], mountOption.linearOpacity));
  2856. grd.addColorStop(mountOption.colorStop, hexToRgb(mountOption.customColor[series[i].linearIndex],mountOption.linearOpacity));
  2857. grd.addColorStop(1, hexToRgb(fillColor, 1));
  2858. }
  2859. fillColor = grd
  2860. }
  2861. // 圆角边框
  2862. if ((mountOption.barBorderRadius && mountOption.barBorderRadius.length === 4) || mountOption.barBorderCircle === true) {
  2863. const left = startX;
  2864. const top = item.y;
  2865. const width = item.width;
  2866. const height = opts.height - opts.area[2] - item.y - mountOption.borderWidth * opts.pix / 2;
  2867. if (mountOption.barBorderCircle) {
  2868. mountOption.barBorderRadius = [width / 2, width / 2, 0, 0];
  2869. }
  2870. let [r0, r1, r2, r3] = mountOption.barBorderRadius;
  2871. let minRadius = Math.min(width/2,height/2);
  2872. r0 = r0 > minRadius ? minRadius : r0;
  2873. r1 = r1 > minRadius ? minRadius : r1;
  2874. r2 = r2 > minRadius ? minRadius : r2;
  2875. r3 = r3 > minRadius ? minRadius : r3;
  2876. r0 = r0 < 0 ? 0 : r0;
  2877. r1 = r1 < 0 ? 0 : r1;
  2878. r2 = r2 < 0 ? 0 : r2;
  2879. r3 = r3 < 0 ? 0 : r3;
  2880. context.arc(left + r0, top + r0, r0, -Math.PI, -Math.PI / 2);
  2881. context.arc(left + width - r1, top + r1, r1, -Math.PI / 2, 0);
  2882. context.arc(left + width - r2, top + height - r2, r2, 0, Math.PI / 2);
  2883. context.arc(left + r3, top + height - r3, r3, Math.PI / 2, Math.PI);
  2884. } else {
  2885. context.moveTo(startX, item.y);
  2886. context.lineTo(startX + item.width, item.y);
  2887. context.lineTo(startX + item.width, opts.height - opts.area[2]);
  2888. context.lineTo(startX, opts.height - opts.area[2]);
  2889. context.lineTo(startX, item.y);
  2890. }
  2891. context.setStrokeStyle(strokeColor);
  2892. context.setFillStyle(fillColor);
  2893. if(mountOption.borderWidth > 0){
  2894. context.setLineWidth(mountOption.borderWidth * opts.pix);
  2895. context.closePath();
  2896. context.stroke();
  2897. }
  2898. context.fill();
  2899. }
  2900. };
  2901. break;
  2902. case 'triangle':
  2903. for (let i = 0; i < points.length; i++) {
  2904. let item = points[i];
  2905. if (item !== null && i > leftNum && i < rightNum) {
  2906. var startX = item.x - eachSpacing*mountOption.widthRatio/2;
  2907. var height = opts.height - item.y - opts.area[2];
  2908. context.beginPath();
  2909. var fillColor = item.color || series[i].color
  2910. var strokeColor = item.color || series[i].color
  2911. if (mountOption.linearType !== 'none') {
  2912. var grd = context.createLinearGradient(startX, item.y, startX, opts.height - opts.area[2]);
  2913. //透明渐变
  2914. if (mountOption.linearType == 'opacity') {
  2915. grd.addColorStop(0, hexToRgb(fillColor, mountOption.linearOpacity));
  2916. grd.addColorStop(1, hexToRgb(fillColor, 1));
  2917. } else {
  2918. grd.addColorStop(0, hexToRgb(mountOption.customColor[series[i].linearIndex], mountOption.linearOpacity));
  2919. grd.addColorStop(mountOption.colorStop, hexToRgb(mountOption.customColor[series[i].linearIndex],mountOption.linearOpacity));
  2920. grd.addColorStop(1, hexToRgb(fillColor, 1));
  2921. }
  2922. fillColor = grd
  2923. }
  2924. context.moveTo(startX, opts.height - opts.area[2]);
  2925. context.lineTo(item.x, item.y);
  2926. context.lineTo(startX + item.width, opts.height - opts.area[2]);
  2927. context.setStrokeStyle(strokeColor);
  2928. context.setFillStyle(fillColor);
  2929. if(mountOption.borderWidth > 0){
  2930. context.setLineWidth(mountOption.borderWidth * opts.pix);
  2931. context.stroke();
  2932. }
  2933. context.fill();
  2934. }
  2935. };
  2936. break;
  2937. case 'mount':
  2938. for (let i = 0; i < points.length; i++) {
  2939. let item = points[i];
  2940. if (item !== null && i > leftNum && i < rightNum) {
  2941. var startX = item.x - eachSpacing*mountOption.widthRatio/2;
  2942. var height = opts.height - item.y - opts.area[2];
  2943. context.beginPath();
  2944. var fillColor = item.color || series[i].color
  2945. var strokeColor = item.color || series[i].color
  2946. if (mountOption.linearType !== 'none') {
  2947. var grd = context.createLinearGradient(startX, item.y, startX, opts.height - opts.area[2]);
  2948. //透明渐变
  2949. if (mountOption.linearType == 'opacity') {
  2950. grd.addColorStop(0, hexToRgb(fillColor, mountOption.linearOpacity));
  2951. grd.addColorStop(1, hexToRgb(fillColor, 1));
  2952. } else {
  2953. grd.addColorStop(0, hexToRgb(mountOption.customColor[series[i].linearIndex], mountOption.linearOpacity));
  2954. grd.addColorStop(mountOption.colorStop, hexToRgb(mountOption.customColor[series[i].linearIndex],mountOption.linearOpacity));
  2955. grd.addColorStop(1, hexToRgb(fillColor, 1));
  2956. }
  2957. fillColor = grd
  2958. }
  2959. context.moveTo(startX, opts.height - opts.area[2]);
  2960. context.bezierCurveTo(item.x - item.width/4, opts.height - opts.area[2], item.x - item.width/4, item.y, item.x, item.y);
  2961. context.bezierCurveTo(item.x + item.width/4, item.y, item.x + item.width/4, opts.height - opts.area[2], startX + item.width, opts.height - opts.area[2]);
  2962. context.setStrokeStyle(strokeColor);
  2963. context.setFillStyle(fillColor);
  2964. if(mountOption.borderWidth > 0){
  2965. context.setLineWidth(mountOption.borderWidth * opts.pix);
  2966. context.stroke();
  2967. }
  2968. context.fill();
  2969. }
  2970. };
  2971. break;
  2972. case 'sharp':
  2973. for (let i = 0; i < points.length; i++) {
  2974. let item = points[i];
  2975. if (item !== null && i > leftNum && i < rightNum) {
  2976. var startX = item.x - eachSpacing*mountOption.widthRatio/2;
  2977. var height = opts.height - item.y - opts.area[2];
  2978. context.beginPath();
  2979. var fillColor = item.color || series[i].color
  2980. var strokeColor = item.color || series[i].color
  2981. if (mountOption.linearType !== 'none') {
  2982. var grd = context.createLinearGradient(startX, item.y, startX, opts.height - opts.area[2]);
  2983. //透明渐变
  2984. if (mountOption.linearType == 'opacity') {
  2985. grd.addColorStop(0, hexToRgb(fillColor, mountOption.linearOpacity));
  2986. grd.addColorStop(1, hexToRgb(fillColor, 1));
  2987. } else {
  2988. grd.addColorStop(0, hexToRgb(mountOption.customColor[series[i].linearIndex], mountOption.linearOpacity));
  2989. grd.addColorStop(mountOption.colorStop, hexToRgb(mountOption.customColor[series[i].linearIndex],mountOption.linearOpacity));
  2990. grd.addColorStop(1, hexToRgb(fillColor, 1));
  2991. }
  2992. fillColor = grd
  2993. }
  2994. context.moveTo(startX, opts.height - opts.area[2]);
  2995. context.quadraticCurveTo(item.x - 0, opts.height - opts.area[2] - height/4, item.x, item.y);
  2996. context.quadraticCurveTo(item.x + 0, opts.height - opts.area[2] - height/4, startX + item.width, opts.height - opts.area[2])
  2997. context.setStrokeStyle(strokeColor);
  2998. context.setFillStyle(fillColor);
  2999. if(mountOption.borderWidth > 0){
  3000. context.setLineWidth(mountOption.borderWidth * opts.pix);
  3001. context.stroke();
  3002. }
  3003. context.fill();
  3004. }
  3005. };
  3006. break;
  3007. }
  3008. if (opts.dataLabel !== false && process === 1) {
  3009. let ranges, minRange, maxRange;
  3010. ranges = [].concat(opts.chartData.yAxisData.ranges[0]);
  3011. minRange = ranges.pop();
  3012. maxRange = ranges.shift();
  3013. var points = getMountDataPoints(series, minRange, maxRange, xAxisPoints, eachSpacing, opts, mountOption, process);
  3014. drawMountPointText(points, series, config, context, opts);
  3015. }
  3016. context.restore();
  3017. return {
  3018. xAxisPoints: xAxisPoints,
  3019. calPoints: points,
  3020. eachSpacing: eachSpacing
  3021. };
  3022. }
  3023. function drawBarDataPoints(series, opts, config, context) {
  3024. let process = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : 1;
  3025. let yAxisPoints = [];
  3026. let eachSpacing = (opts.height - opts.area[0] - opts.area[2])/opts.categories.length;
  3027. for (let i = 0; i < opts.categories.length; i++) {
  3028. yAxisPoints.push(opts.area[0] + eachSpacing / 2 + eachSpacing * i);
  3029. }
  3030. let columnOption = assign({}, {
  3031. type: 'group',
  3032. width: eachSpacing / 2,
  3033. meterBorder: 4,
  3034. meterFillColor: '#FFFFFF',
  3035. barBorderCircle: false,
  3036. barBorderRadius: [],
  3037. seriesGap: 2,
  3038. linearType: 'none',
  3039. linearOpacity: 1,
  3040. customColor: [],
  3041. colorStop: 0,
  3042. }, opts.extra.bar);
  3043. let calPoints = [];
  3044. context.save();
  3045. let leftNum = -2;
  3046. let rightNum = yAxisPoints.length + 2;
  3047. if (opts.tooltip && opts.tooltip.textList && opts.tooltip.textList.length && process === 1) {
  3048. drawBarToolTipSplitArea(opts.tooltip.offset.y, opts, config, context, eachSpacing);
  3049. }
  3050. columnOption.customColor = fillCustomColor(columnOption.linearType, columnOption.customColor, series, config);
  3051. series.forEach(function(eachSeries, seriesIndex) {
  3052. let ranges, minRange, maxRange;
  3053. ranges = [].concat(opts.chartData.xAxisData.ranges);
  3054. maxRange = ranges.pop();
  3055. minRange = ranges.shift();
  3056. var data = eachSeries.data;
  3057. switch (columnOption.type) {
  3058. case 'group':
  3059. var points = getBarDataPoints(data, minRange, maxRange, yAxisPoints, eachSpacing, opts, config, process);
  3060. var tooltipPoints = getBarStackDataPoints(data, minRange, maxRange, yAxisPoints, eachSpacing, opts, config, seriesIndex, series, process);
  3061. calPoints.push(tooltipPoints);
  3062. points = fixBarData(points, eachSpacing, series.length, seriesIndex, config, opts);
  3063. for (let i = 0; i < points.length; i++) {
  3064. let item = points[i];
  3065. //fix issues/I27B1N yyoinge & Joeshu
  3066. if (item !== null && i > leftNum && i < rightNum) {
  3067. //var startX = item.x - item.width / 2;
  3068. var startX = opts.area[3];
  3069. var startY = item.y - item.width / 2;
  3070. var height = item.height;
  3071. context.beginPath();
  3072. var fillColor = item.color || eachSeries.color
  3073. var strokeColor = item.color || eachSeries.color
  3074. if (columnOption.linearType !== 'none') {
  3075. var grd = context.createLinearGradient(startX, item.y, item.x, item.y);
  3076. //透明渐变
  3077. if (columnOption.linearType == 'opacity') {
  3078. grd.addColorStop(0, hexToRgb(fillColor, columnOption.linearOpacity));
  3079. grd.addColorStop(1, hexToRgb(fillColor, 1));
  3080. } else {
  3081. grd.addColorStop(0, hexToRgb(columnOption.customColor[eachSeries.linearIndex], columnOption.linearOpacity));
  3082. grd.addColorStop(columnOption.colorStop, hexToRgb(columnOption.customColor[eachSeries.linearIndex],columnOption.linearOpacity));
  3083. grd.addColorStop(1, hexToRgb(fillColor, 1));
  3084. }
  3085. fillColor = grd
  3086. }
  3087. // 圆角边框
  3088. if ((columnOption.barBorderRadius && columnOption.barBorderRadius.length === 4) || columnOption.barBorderCircle === true) {
  3089. const left = startX;
  3090. const width = item.width;
  3091. const top = item.y - item.width / 2;
  3092. const height = item.height;
  3093. if (columnOption.barBorderCircle) {
  3094. columnOption.barBorderRadius = [width / 2, width / 2, 0, 0];
  3095. }
  3096. let [r0, r1, r2, r3] = columnOption.barBorderRadius;
  3097. let minRadius = Math.min(width/2,height/2);
  3098. r0 = r0 > minRadius ? minRadius : r0;
  3099. r1 = r1 > minRadius ? minRadius : r1;
  3100. r2 = r2 > minRadius ? minRadius : r2;
  3101. r3 = r3 > minRadius ? minRadius : r3;
  3102. r0 = r0 < 0 ? 0 : r0;
  3103. r1 = r1 < 0 ? 0 : r1;
  3104. r2 = r2 < 0 ? 0 : r2;
  3105. r3 = r3 < 0 ? 0 : r3;
  3106. context.arc(left + r3, top + r3, r3, -Math.PI, -Math.PI / 2);
  3107. context.arc(item.x - r0, top + r0, r0, -Math.PI / 2, 0);
  3108. context.arc(item.x - r1, top + width - r1, r1, 0, Math.PI / 2);
  3109. context.arc(left + r2, top + width - r2, r2, Math.PI / 2, Math.PI);
  3110. } else {
  3111. context.moveTo(startX, startY);
  3112. context.lineTo(item.x, startY);
  3113. context.lineTo(item.x, startY + item.width);
  3114. context.lineTo(startX, startY + item.width);
  3115. context.lineTo(startX, startY);
  3116. context.setLineWidth(1)
  3117. context.setStrokeStyle(strokeColor);
  3118. }
  3119. context.setFillStyle(fillColor);
  3120. context.closePath();
  3121. //context.stroke();
  3122. context.fill();
  3123. }
  3124. };
  3125. break;
  3126. case 'stack':
  3127. // 绘制堆叠数据图
  3128. var points = getBarStackDataPoints(data, minRange, maxRange, yAxisPoints, eachSpacing, opts, config, seriesIndex, series, process);
  3129. calPoints.push(points);
  3130. points = fixBarStackData(points, eachSpacing, series.length, seriesIndex, config, opts, series);
  3131. for (let i = 0; i < points.length; i++) {
  3132. let item = points[i];
  3133. if (item !== null && i > leftNum && i < rightNum) {
  3134. context.beginPath();
  3135. var fillColor = item.color || eachSeries.color;
  3136. var startX = item.x0;
  3137. context.setFillStyle(fillColor);
  3138. context.moveTo(startX, item.y - item.width/2);
  3139. context.fillRect(startX, item.y - item.width/2, item.height , item.width);
  3140. context.closePath();
  3141. context.fill();
  3142. }
  3143. };
  3144. break;
  3145. }
  3146. });
  3147. if (opts.dataLabel !== false && process === 1) {
  3148. series.forEach(function(eachSeries, seriesIndex) {
  3149. let ranges, minRange, maxRange;
  3150. ranges = [].concat(opts.chartData.xAxisData.ranges);
  3151. maxRange = ranges.pop();
  3152. minRange = ranges.shift();
  3153. var data = eachSeries.data;
  3154. switch (columnOption.type) {
  3155. case 'group':
  3156. var points = getBarDataPoints(data, minRange, maxRange, yAxisPoints, eachSpacing, opts, config, process);
  3157. points = fixBarData(points, eachSpacing, series.length, seriesIndex, config, opts);
  3158. drawBarPointText(points, eachSeries, config, context, opts);
  3159. break;
  3160. case 'stack':
  3161. var points = getBarStackDataPoints(data, minRange, maxRange, yAxisPoints, eachSpacing, opts, config, seriesIndex, series, process);
  3162. drawBarPointText(points, eachSeries, config, context, opts);
  3163. break;
  3164. }
  3165. });
  3166. }
  3167. return {
  3168. yAxisPoints: yAxisPoints,
  3169. calPoints: calPoints,
  3170. eachSpacing: eachSpacing
  3171. };
  3172. }
  3173. function drawCandleDataPoints(series, seriesMA, opts, config, context) {
  3174. var process = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : 1;
  3175. var candleOption = assign({}, {
  3176. color: {},
  3177. average: {}
  3178. }, opts.extra.candle);
  3179. candleOption.color = assign({}, {
  3180. upLine: '#f04864',
  3181. upFill: '#f04864',
  3182. downLine: '#2fc25b',
  3183. downFill: '#2fc25b'
  3184. }, candleOption.color);
  3185. candleOption.average = assign({}, {
  3186. show: false,
  3187. name: [],
  3188. day: [],
  3189. color: config.color
  3190. }, candleOption.average);
  3191. opts.extra.candle = candleOption;
  3192. let xAxisData = opts.chartData.xAxisData,
  3193. xAxisPoints = xAxisData.xAxisPoints,
  3194. eachSpacing = xAxisData.eachSpacing;
  3195. let calPoints = [];
  3196. context.save();
  3197. let leftNum = -2;
  3198. let rightNum = xAxisPoints.length + 2;
  3199. let leftSpace = 0;
  3200. let rightSpace = opts.width + eachSpacing;
  3201. if (opts._scrollDistance_ && opts._scrollDistance_ !== 0 && opts.enableScroll === true) {
  3202. context.translate(opts._scrollDistance_, 0);
  3203. leftNum = Math.floor(-opts._scrollDistance_ / eachSpacing) - 2;
  3204. rightNum = leftNum + opts.xAxis.itemCount + 4;
  3205. leftSpace = -opts._scrollDistance_ - eachSpacing * 2 + opts.area[3];
  3206. rightSpace = leftSpace + (opts.xAxis.itemCount + 4) * eachSpacing;
  3207. }
  3208. //画均线
  3209. if (candleOption.average.show || seriesMA) { //Merge pull request !12 from 邱贵翔
  3210. seriesMA.forEach(function(eachSeries, seriesIndex) {
  3211. let ranges, minRange, maxRange;
  3212. ranges = [].concat(opts.chartData.yAxisData.ranges[eachSeries.index]);
  3213. minRange = ranges.pop();
  3214. maxRange = ranges.shift();
  3215. var data = eachSeries.data;
  3216. var points = getDataPoints(data, minRange, maxRange, xAxisPoints, eachSpacing, opts, config, process);
  3217. var splitPointList = splitPoints(points,eachSeries);
  3218. for (let i = 0; i < splitPointList.length; i++) {
  3219. let points = splitPointList[i];
  3220. context.beginPath();
  3221. context.setStrokeStyle(eachSeries.color);
  3222. context.setLineWidth(1);
  3223. if (points.length === 1) {
  3224. context.moveTo(points[0].x, points[0].y);
  3225. context.arc(points[0].x, points[0].y, 1, 0, 2 * Math.PI);
  3226. } else {
  3227. context.moveTo(points[0].x, points[0].y);
  3228. let startPoint = 0;
  3229. for (let j = 0; j < points.length; j++) {
  3230. let item = points[j];
  3231. if (startPoint == 0 && item.x > leftSpace) {
  3232. context.moveTo(item.x, item.y);
  3233. startPoint = 1;
  3234. }
  3235. if (j > 0 && item.x > leftSpace && item.x < rightSpace) {
  3236. var ctrlPoint = createCurveControlPoints(points, j - 1);
  3237. context.bezierCurveTo(ctrlPoint.ctrA.x, ctrlPoint.ctrA.y, ctrlPoint.ctrB.x, ctrlPoint.ctrB.y, item.x,
  3238. item.y);
  3239. }
  3240. }
  3241. context.moveTo(points[0].x, points[0].y);
  3242. }
  3243. context.closePath();
  3244. context.stroke();
  3245. }
  3246. });
  3247. }
  3248. //画K线
  3249. series.forEach(function(eachSeries, seriesIndex) {
  3250. let ranges, minRange, maxRange;
  3251. ranges = [].concat(opts.chartData.yAxisData.ranges[eachSeries.index]);
  3252. minRange = ranges.pop();
  3253. maxRange = ranges.shift();
  3254. var data = eachSeries.data;
  3255. var points = getCandleDataPoints(data, minRange, maxRange, xAxisPoints, eachSpacing, opts, config, process);
  3256. calPoints.push(points);
  3257. var splitPointList = splitPoints(points,eachSeries);
  3258. for (let i = 0; i < splitPointList[0].length; i++) {
  3259. if (i > leftNum && i < rightNum) {
  3260. let item = splitPointList[0][i];
  3261. context.beginPath();
  3262. //如果上涨
  3263. if (data[i][1] - data[i][0] > 0) {
  3264. context.setStrokeStyle(candleOption.color.upLine);
  3265. context.setFillStyle(candleOption.color.upFill);
  3266. context.setLineWidth(1 * opts.pix);
  3267. context.moveTo(item[3].x, item[3].y); //顶点
  3268. context.lineTo(item[1].x, item[1].y); //收盘中间点
  3269. context.lineTo(item[1].x - eachSpacing / 4, item[1].y); //收盘左侧点
  3270. context.lineTo(item[0].x - eachSpacing / 4, item[0].y); //开盘左侧点
  3271. context.lineTo(item[0].x, item[0].y); //开盘中间点
  3272. context.lineTo(item[2].x, item[2].y); //底点
  3273. context.lineTo(item[0].x, item[0].y); //开盘中间点
  3274. context.lineTo(item[0].x + eachSpacing / 4, item[0].y); //开盘右侧点
  3275. context.lineTo(item[1].x + eachSpacing / 4, item[1].y); //收盘右侧点
  3276. context.lineTo(item[1].x, item[1].y); //收盘中间点
  3277. context.moveTo(item[3].x, item[3].y); //顶点
  3278. } else {
  3279. context.setStrokeStyle(candleOption.color.downLine);
  3280. context.setFillStyle(candleOption.color.downFill);
  3281. context.setLineWidth(1 * opts.pix);
  3282. context.moveTo(item[3].x, item[3].y); //顶点
  3283. context.lineTo(item[0].x, item[0].y); //开盘中间点
  3284. context.lineTo(item[0].x - eachSpacing / 4, item[0].y); //开盘左侧点
  3285. context.lineTo(item[1].x - eachSpacing / 4, item[1].y); //收盘左侧点
  3286. context.lineTo(item[1].x, item[1].y); //收盘中间点
  3287. context.lineTo(item[2].x, item[2].y); //底点
  3288. context.lineTo(item[1].x, item[1].y); //收盘中间点
  3289. context.lineTo(item[1].x + eachSpacing / 4, item[1].y); //收盘右侧点
  3290. context.lineTo(item[0].x + eachSpacing / 4, item[0].y); //开盘右侧点
  3291. context.lineTo(item[0].x, item[0].y); //开盘中间点
  3292. context.moveTo(item[3].x, item[3].y); //顶点
  3293. }
  3294. context.closePath();
  3295. context.fill();
  3296. context.stroke();
  3297. }
  3298. }
  3299. });
  3300. context.restore();
  3301. return {
  3302. xAxisPoints: xAxisPoints,
  3303. calPoints: calPoints,
  3304. eachSpacing: eachSpacing
  3305. };
  3306. }
  3307. function drawAreaDataPoints(series, opts, config, context) {
  3308. var process = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : 1;
  3309. var areaOption = assign({}, {
  3310. type: 'straight',
  3311. opacity: 0.2,
  3312. addLine: false,
  3313. width: 2,
  3314. gradient: false
  3315. }, opts.extra.area);
  3316. let xAxisData = opts.chartData.xAxisData,
  3317. xAxisPoints = xAxisData.xAxisPoints,
  3318. eachSpacing = xAxisData.eachSpacing;
  3319. let endY = opts.height - opts.area[2];
  3320. let calPoints = [];
  3321. context.save();
  3322. let leftSpace = 0;
  3323. let rightSpace = opts.width + eachSpacing;
  3324. if (opts._scrollDistance_ && opts._scrollDistance_ !== 0 && opts.enableScroll === true) {
  3325. context.translate(opts._scrollDistance_, 0);
  3326. leftSpace = -opts._scrollDistance_ - eachSpacing * 2 + opts.area[3];
  3327. rightSpace = leftSpace + (opts.xAxis.itemCount + 4) * eachSpacing;
  3328. }
  3329. series.forEach(function(eachSeries, seriesIndex) {
  3330. let ranges, minRange, maxRange;
  3331. ranges = [].concat(opts.chartData.yAxisData.ranges[eachSeries.index]);
  3332. minRange = ranges.pop();
  3333. maxRange = ranges.shift();
  3334. let data = eachSeries.data;
  3335. let points = getDataPoints(data, minRange, maxRange, xAxisPoints, eachSpacing, opts, config, process);
  3336. calPoints.push(points);
  3337. let splitPointList = splitPoints(points,eachSeries);
  3338. for (let i = 0; i < splitPointList.length; i++) {
  3339. let points = splitPointList[i];
  3340. // 绘制区域数
  3341. context.beginPath();
  3342. context.setStrokeStyle(hexToRgb(eachSeries.color, areaOption.opacity));
  3343. if (areaOption.gradient) {
  3344. let gradient = context.createLinearGradient(0, opts.area[0], 0, opts.height - opts.area[2]);
  3345. gradient.addColorStop('0', hexToRgb(eachSeries.color, areaOption.opacity));
  3346. gradient.addColorStop('1.0', hexToRgb("#FFFFFF", 0.1));
  3347. context.setFillStyle(gradient);
  3348. } else {
  3349. context.setFillStyle(hexToRgb(eachSeries.color, areaOption.opacity));
  3350. }
  3351. context.setLineWidth(areaOption.width * opts.pix);
  3352. if (points.length > 1) {
  3353. let firstPoint = points[0];
  3354. let lastPoint = points[points.length - 1];
  3355. context.moveTo(firstPoint.x, firstPoint.y);
  3356. let startPoint = 0;
  3357. if (areaOption.type === 'curve') {
  3358. for (let j = 0; j < points.length; j++) {
  3359. let item = points[j];
  3360. if (startPoint == 0 && item.x > leftSpace) {
  3361. context.moveTo(item.x, item.y);
  3362. startPoint = 1;
  3363. }
  3364. if (j > 0 && item.x > leftSpace && item.x < rightSpace) {
  3365. let ctrlPoint = createCurveControlPoints(points, j - 1);
  3366. context.bezierCurveTo(ctrlPoint.ctrA.x, ctrlPoint.ctrA.y, ctrlPoint.ctrB.x, ctrlPoint.ctrB.y, item.x, item.y);
  3367. }
  3368. };
  3369. }
  3370. if (areaOption.type === 'straight') {
  3371. for (let j = 0; j < points.length; j++) {
  3372. let item = points[j];
  3373. if (startPoint == 0 && item.x > leftSpace) {
  3374. context.moveTo(item.x, item.y);
  3375. startPoint = 1;
  3376. }
  3377. if (j > 0 && item.x > leftSpace && item.x < rightSpace) {
  3378. context.lineTo(item.x, item.y);
  3379. }
  3380. };
  3381. }
  3382. if (areaOption.type === 'step') {
  3383. for (let j = 0; j < points.length; j++) {
  3384. let item = points[j];
  3385. if (startPoint == 0 && item.x > leftSpace) {
  3386. context.moveTo(item.x, item.y);
  3387. startPoint = 1;
  3388. }
  3389. if (j > 0 && item.x > leftSpace && item.x < rightSpace) {
  3390. context.lineTo(item.x, points[j - 1].y);
  3391. context.lineTo(item.x, item.y);
  3392. }
  3393. };
  3394. }
  3395. context.lineTo(lastPoint.x, endY);
  3396. context.lineTo(firstPoint.x, endY);
  3397. context.lineTo(firstPoint.x, firstPoint.y);
  3398. } else {
  3399. let item = points[0];
  3400. context.moveTo(item.x - eachSpacing / 2, item.y);
  3401. context.lineTo(item.x + eachSpacing / 2, item.y);
  3402. context.lineTo(item.x + eachSpacing / 2, endY);
  3403. context.lineTo(item.x - eachSpacing / 2, endY);
  3404. context.moveTo(item.x - eachSpacing / 2, item.y);
  3405. }
  3406. context.closePath();
  3407. context.fill();
  3408. //画连线
  3409. if (areaOption.addLine) {
  3410. if (eachSeries.lineType == 'dash') {
  3411. let dashLength = eachSeries.dashLength ? eachSeries.dashLength : 8;
  3412. dashLength *= opts.pix;
  3413. context.setLineDash([dashLength, dashLength]);
  3414. }
  3415. context.beginPath();
  3416. context.setStrokeStyle(eachSeries.color);
  3417. context.setLineWidth(areaOption.width * opts.pix);
  3418. if (points.length === 1) {
  3419. context.moveTo(points[0].x, points[0].y);
  3420. context.arc(points[0].x, points[0].y, 1, 0, 2 * Math.PI);
  3421. } else {
  3422. context.moveTo(points[0].x, points[0].y);
  3423. let startPoint = 0;
  3424. if (areaOption.type === 'curve') {
  3425. for (let j = 0; j < points.length; j++) {
  3426. let item = points[j];
  3427. if (startPoint == 0 && item.x > leftSpace) {
  3428. context.moveTo(item.x, item.y);
  3429. startPoint = 1;
  3430. }
  3431. if (j > 0 && item.x > leftSpace && item.x < rightSpace) {
  3432. let ctrlPoint = createCurveControlPoints(points, j - 1);
  3433. context.bezierCurveTo(ctrlPoint.ctrA.x, ctrlPoint.ctrA.y, ctrlPoint.ctrB.x, ctrlPoint.ctrB.y, item.x, item.y);
  3434. }
  3435. };
  3436. }
  3437. if (areaOption.type === 'straight') {
  3438. for (let j = 0; j < points.length; j++) {
  3439. let item = points[j];
  3440. if (startPoint == 0 && item.x > leftSpace) {
  3441. context.moveTo(item.x, item.y);
  3442. startPoint = 1;
  3443. }
  3444. if (j > 0 && item.x > leftSpace && item.x < rightSpace) {
  3445. context.lineTo(item.x, item.y);
  3446. }
  3447. };
  3448. }
  3449. if (areaOption.type === 'step') {
  3450. for (let j = 0; j < points.length; j++) {
  3451. let item = points[j];
  3452. if (startPoint == 0 && item.x > leftSpace) {
  3453. context.moveTo(item.x, item.y);
  3454. startPoint = 1;
  3455. }
  3456. if (j > 0 && item.x > leftSpace && item.x < rightSpace) {
  3457. context.lineTo(item.x, points[j - 1].y);
  3458. context.lineTo(item.x, item.y);
  3459. }
  3460. };
  3461. }
  3462. context.moveTo(points[0].x, points[0].y);
  3463. }
  3464. context.stroke();
  3465. context.setLineDash([]);
  3466. }
  3467. }
  3468. //画点
  3469. if (opts.dataPointShape !== false) {
  3470. drawPointShape(points, eachSeries.color, eachSeries.pointShape, context, opts);
  3471. }
  3472. });
  3473. if (opts.dataLabel !== false && process === 1) {
  3474. series.forEach(function(eachSeries, seriesIndex) {
  3475. let ranges, minRange, maxRange;
  3476. ranges = [].concat(opts.chartData.yAxisData.ranges[eachSeries.index]);
  3477. minRange = ranges.pop();
  3478. maxRange = ranges.shift();
  3479. var data = eachSeries.data;
  3480. var points = getDataPoints(data, minRange, maxRange, xAxisPoints, eachSpacing, opts, config, process);
  3481. drawPointText(points, eachSeries, config, context, opts);
  3482. });
  3483. }
  3484. context.restore();
  3485. return {
  3486. xAxisPoints: xAxisPoints,
  3487. calPoints: calPoints,
  3488. eachSpacing: eachSpacing
  3489. };
  3490. }
  3491. function drawScatterDataPoints(series, opts, config, context) {
  3492. var process = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : 1;
  3493. var scatterOption = assign({}, {
  3494. type: 'circle'
  3495. }, opts.extra.scatter);
  3496. let xAxisData = opts.chartData.xAxisData,
  3497. xAxisPoints = xAxisData.xAxisPoints,
  3498. eachSpacing = xAxisData.eachSpacing;
  3499. var calPoints = [];
  3500. context.save();
  3501. let leftSpace = 0;
  3502. let rightSpace = opts.width + eachSpacing;
  3503. if (opts._scrollDistance_ && opts._scrollDistance_ !== 0 && opts.enableScroll === true) {
  3504. context.translate(opts._scrollDistance_, 0);
  3505. leftSpace = -opts._scrollDistance_ - eachSpacing * 2 + opts.area[3];
  3506. rightSpace = leftSpace + (opts.xAxis.itemCount + 4) * eachSpacing;
  3507. }
  3508. series.forEach(function(eachSeries, seriesIndex) {
  3509. let ranges, minRange, maxRange;
  3510. ranges = [].concat(opts.chartData.yAxisData.ranges[eachSeries.index]);
  3511. minRange = ranges.pop();
  3512. maxRange = ranges.shift();
  3513. var data = eachSeries.data;
  3514. var points = getDataPoints(data, minRange, maxRange, xAxisPoints, eachSpacing, opts, config, process);
  3515. context.beginPath();
  3516. context.setStrokeStyle(eachSeries.color);
  3517. context.setFillStyle(eachSeries.color);
  3518. context.setLineWidth(1 * opts.pix);
  3519. var shape = eachSeries.pointShape;
  3520. if (shape === 'diamond') {
  3521. points.forEach(function(item, index) {
  3522. if (item !== null) {
  3523. context.moveTo(item.x, item.y - 4.5);
  3524. context.lineTo(item.x - 4.5, item.y);
  3525. context.lineTo(item.x, item.y + 4.5);
  3526. context.lineTo(item.x + 4.5, item.y);
  3527. context.lineTo(item.x, item.y - 4.5);
  3528. }
  3529. });
  3530. } else if (shape === 'circle') {
  3531. points.forEach(function(item, index) {
  3532. if (item !== null) {
  3533. context.moveTo(item.x + 2.5 * opts.pix, item.y);
  3534. context.arc(item.x, item.y, 3 * opts.pix, 0, 2 * Math.PI, false);
  3535. }
  3536. });
  3537. } else if (shape === 'square') {
  3538. points.forEach(function(item, index) {
  3539. if (item !== null) {
  3540. context.moveTo(item.x - 3.5, item.y - 3.5);
  3541. context.rect(item.x - 3.5, item.y - 3.5, 7, 7);
  3542. }
  3543. });
  3544. } else if (shape === 'triangle') {
  3545. points.forEach(function(item, index) {
  3546. if (item !== null) {
  3547. context.moveTo(item.x, item.y - 4.5);
  3548. context.lineTo(item.x - 4.5, item.y + 4.5);
  3549. context.lineTo(item.x + 4.5, item.y + 4.5);
  3550. context.lineTo(item.x, item.y - 4.5);
  3551. }
  3552. });
  3553. } else if (shape === 'triangle') {
  3554. return;
  3555. }
  3556. context.closePath();
  3557. context.fill();
  3558. context.stroke();
  3559. });
  3560. if (opts.dataLabel !== false && process === 1) {
  3561. series.forEach(function(eachSeries, seriesIndex) {
  3562. let ranges, minRange, maxRange;
  3563. ranges = [].concat(opts.chartData.yAxisData.ranges[eachSeries.index]);
  3564. minRange = ranges.pop();
  3565. maxRange = ranges.shift();
  3566. var data = eachSeries.data;
  3567. var points = getDataPoints(data, minRange, maxRange, xAxisPoints, eachSpacing, opts, config, process);
  3568. drawPointText(points, eachSeries, config, context, opts);
  3569. });
  3570. }
  3571. context.restore();
  3572. return {
  3573. xAxisPoints: xAxisPoints,
  3574. calPoints: calPoints,
  3575. eachSpacing: eachSpacing
  3576. };
  3577. }
  3578. function drawBubbleDataPoints(series, opts, config, context) {
  3579. var process = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : 1;
  3580. var bubbleOption = assign({}, {
  3581. opacity: 1,
  3582. border:2
  3583. }, opts.extra.bubble);
  3584. let xAxisData = opts.chartData.xAxisData,
  3585. xAxisPoints = xAxisData.xAxisPoints,
  3586. eachSpacing = xAxisData.eachSpacing;
  3587. var calPoints = [];
  3588. context.save();
  3589. let leftSpace = 0;
  3590. let rightSpace = opts.width + eachSpacing;
  3591. if (opts._scrollDistance_ && opts._scrollDistance_ !== 0 && opts.enableScroll === true) {
  3592. context.translate(opts._scrollDistance_, 0);
  3593. leftSpace = -opts._scrollDistance_ - eachSpacing * 2 + opts.area[3];
  3594. rightSpace = leftSpace + (opts.xAxis.itemCount + 4) * eachSpacing;
  3595. }
  3596. series.forEach(function(eachSeries, seriesIndex) {
  3597. let ranges, minRange, maxRange;
  3598. ranges = [].concat(opts.chartData.yAxisData.ranges[eachSeries.index]);
  3599. minRange = ranges.pop();
  3600. maxRange = ranges.shift();
  3601. var data = eachSeries.data;
  3602. var points = getDataPoints(data, minRange, maxRange, xAxisPoints, eachSpacing, opts, config, process);
  3603. context.beginPath();
  3604. context.setStrokeStyle(eachSeries.color);
  3605. context.setLineWidth(bubbleOption.border * opts.pix);
  3606. context.setFillStyle(hexToRgb(eachSeries.color, bubbleOption.opacity));
  3607. points.forEach(function(item, index) {
  3608. context.moveTo(item.x + item.r, item.y);
  3609. context.arc(item.x, item.y, item.r * opts.pix, 0, 2 * Math.PI, false);
  3610. });
  3611. context.closePath();
  3612. context.fill();
  3613. context.stroke();
  3614. if (opts.dataLabel !== false && process === 1) {
  3615. points.forEach(function(item, index) {
  3616. context.beginPath();
  3617. var fontSize = eachSeries.textSize * opts.pix || config.fontSize;
  3618. context.setFontSize(fontSize);
  3619. context.setFillStyle(eachSeries.textColor || "#FFFFFF");
  3620. context.setTextAlign('center');
  3621. context.fillText(String(item.t), item.x, item.y + fontSize/2);
  3622. context.closePath();
  3623. context.stroke();
  3624. context.setTextAlign('left');
  3625. });
  3626. }
  3627. });
  3628. context.restore();
  3629. return {
  3630. xAxisPoints: xAxisPoints,
  3631. calPoints: calPoints,
  3632. eachSpacing: eachSpacing
  3633. };
  3634. }
  3635. function drawLineDataPoints(series, opts, config, context) {
  3636. var process = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : 1;
  3637. var lineOption = assign({}, {
  3638. type: 'straight',
  3639. width: 2
  3640. }, opts.extra.line);
  3641. lineOption.width *= opts.pix;
  3642. let xAxisData = opts.chartData.xAxisData,
  3643. xAxisPoints = xAxisData.xAxisPoints,
  3644. eachSpacing = xAxisData.eachSpacing;
  3645. var calPoints = [];
  3646. context.save();
  3647. let leftSpace = 0;
  3648. let rightSpace = opts.width + eachSpacing;
  3649. if (opts._scrollDistance_ && opts._scrollDistance_ !== 0 && opts.enableScroll === true) {
  3650. context.translate(opts._scrollDistance_, 0);
  3651. leftSpace = -opts._scrollDistance_ - eachSpacing * 2 + opts.area[3];
  3652. rightSpace = leftSpace + (opts.xAxis.itemCount + 4) * eachSpacing;
  3653. }
  3654. series.forEach(function(eachSeries, seriesIndex) {
  3655. let ranges, minRange, maxRange;
  3656. ranges = [].concat(opts.chartData.yAxisData.ranges[eachSeries.index]);
  3657. minRange = ranges.pop();
  3658. maxRange = ranges.shift();
  3659. var data = eachSeries.data;
  3660. var points = getDataPoints(data, minRange, maxRange, xAxisPoints, eachSpacing, opts, config, process);
  3661. calPoints.push(points);
  3662. var splitPointList = splitPoints(points,eachSeries);
  3663. if (eachSeries.lineType == 'dash') {
  3664. let dashLength = eachSeries.dashLength ? eachSeries.dashLength : 8;
  3665. dashLength *= opts.pix;
  3666. context.setLineDash([dashLength, dashLength]);
  3667. }
  3668. context.beginPath();
  3669. context.setStrokeStyle(eachSeries.color);
  3670. context.setLineWidth(lineOption.width);
  3671. splitPointList.forEach(function(points, index) {
  3672. if (points.length === 1) {
  3673. context.moveTo(points[0].x, points[0].y);
  3674. context.arc(points[0].x, points[0].y, 1, 0, 2 * Math.PI);
  3675. } else {
  3676. context.moveTo(points[0].x, points[0].y);
  3677. let startPoint = 0;
  3678. if (lineOption.type === 'curve') {
  3679. for (let j = 0; j < points.length; j++) {
  3680. let item = points[j];
  3681. if (startPoint == 0 && item.x > leftSpace) {
  3682. context.moveTo(item.x, item.y);
  3683. startPoint = 1;
  3684. }
  3685. if (j > 0 && item.x > leftSpace && item.x < rightSpace) {
  3686. var ctrlPoint = createCurveControlPoints(points, j - 1);
  3687. context.bezierCurveTo(ctrlPoint.ctrA.x, ctrlPoint.ctrA.y, ctrlPoint.ctrB.x, ctrlPoint.ctrB.y, item.x, item.y);
  3688. }
  3689. };
  3690. }
  3691. if (lineOption.type === 'straight') {
  3692. for (let j = 0; j < points.length; j++) {
  3693. let item = points[j];
  3694. if (startPoint == 0 && item.x > leftSpace) {
  3695. context.moveTo(item.x, item.y);
  3696. startPoint = 1;
  3697. }
  3698. if (j > 0 && item.x > leftSpace && item.x < rightSpace) {
  3699. context.lineTo(item.x, item.y);
  3700. }
  3701. };
  3702. }
  3703. if (lineOption.type === 'step') {
  3704. for (let j = 0; j < points.length; j++) {
  3705. let item = points[j];
  3706. if (startPoint == 0 && item.x > leftSpace) {
  3707. context.moveTo(item.x, item.y);
  3708. startPoint = 1;
  3709. }
  3710. if (j > 0 && item.x > leftSpace && item.x < rightSpace) {
  3711. context.lineTo(item.x, points[j - 1].y);
  3712. context.lineTo(item.x, item.y);
  3713. }
  3714. };
  3715. }
  3716. context.moveTo(points[0].x, points[0].y);
  3717. }
  3718. });
  3719. context.stroke();
  3720. context.setLineDash([]);
  3721. if (opts.dataPointShape !== false) {
  3722. drawPointShape(points, eachSeries.color, eachSeries.pointShape, context, opts);
  3723. }
  3724. });
  3725. if (opts.dataLabel !== false && process === 1) {
  3726. series.forEach(function(eachSeries, seriesIndex) {
  3727. let ranges, minRange, maxRange;
  3728. ranges = [].concat(opts.chartData.yAxisData.ranges[eachSeries.index]);
  3729. minRange = ranges.pop();
  3730. maxRange = ranges.shift();
  3731. var data = eachSeries.data;
  3732. var points = getDataPoints(data, minRange, maxRange, xAxisPoints, eachSpacing, opts, config, process);
  3733. drawPointText(points, eachSeries, config, context, opts);
  3734. });
  3735. }
  3736. context.restore();
  3737. return {
  3738. xAxisPoints: xAxisPoints,
  3739. calPoints: calPoints,
  3740. eachSpacing: eachSpacing
  3741. };
  3742. }
  3743. function drawMixDataPoints(series, opts, config, context) {
  3744. let process = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : 1;
  3745. let xAxisData = opts.chartData.xAxisData,
  3746. xAxisPoints = xAxisData.xAxisPoints,
  3747. eachSpacing = xAxisData.eachSpacing;
  3748. let columnOption = assign({}, {
  3749. width: eachSpacing / 2,
  3750. barBorderCircle: false,
  3751. barBorderRadius: [],
  3752. seriesGap: 2,
  3753. linearType: 'none',
  3754. linearOpacity: 1,
  3755. customColor: [],
  3756. colorStop: 0,
  3757. }, opts.extra.mix.column);
  3758. let areaOption = assign({}, {
  3759. opacity: 0.2,
  3760. gradient: false
  3761. }, opts.extra.mix.area);
  3762. let lineOption = assign({}, {
  3763. width: 2
  3764. }, opts.extra.mix.line);
  3765. let endY = opts.height - opts.area[2];
  3766. let calPoints = [];
  3767. var columnIndex = 0;
  3768. var columnLength = 0;
  3769. series.forEach(function(eachSeries, seriesIndex) {
  3770. if (eachSeries.type == 'column') {
  3771. columnLength += 1;
  3772. }
  3773. });
  3774. context.save();
  3775. let leftNum = -2;
  3776. let rightNum = xAxisPoints.length + 2;
  3777. let leftSpace = 0;
  3778. let rightSpace = opts.width + eachSpacing;
  3779. if (opts._scrollDistance_ && opts._scrollDistance_ !== 0 && opts.enableScroll === true) {
  3780. context.translate(opts._scrollDistance_, 0);
  3781. leftNum = Math.floor(-opts._scrollDistance_ / eachSpacing) - 2;
  3782. rightNum = leftNum + opts.xAxis.itemCount + 4;
  3783. leftSpace = -opts._scrollDistance_ - eachSpacing * 2 + opts.area[3];
  3784. rightSpace = leftSpace + (opts.xAxis.itemCount + 4) * eachSpacing;
  3785. }
  3786. columnOption.customColor = fillCustomColor(columnOption.linearType, columnOption.customColor, series, config);
  3787. series.forEach(function(eachSeries, seriesIndex) {
  3788. let ranges, minRange, maxRange;
  3789. ranges = [].concat(opts.chartData.yAxisData.ranges[eachSeries.index]);
  3790. minRange = ranges.pop();
  3791. maxRange = ranges.shift();
  3792. var data = eachSeries.data;
  3793. var points = getDataPoints(data, minRange, maxRange, xAxisPoints, eachSpacing, opts, config, process);
  3794. calPoints.push(points);
  3795. // 绘制柱状数据图
  3796. if (eachSeries.type == 'column') {
  3797. points = fixColumeData(points, eachSpacing, columnLength, columnIndex, config, opts);
  3798. for (let i = 0; i < points.length; i++) {
  3799. let item = points[i];
  3800. if (item !== null && i > leftNum && i < rightNum) {
  3801. var startX = item.x - item.width / 2;
  3802. var height = opts.height - item.y - opts.area[2];
  3803. context.beginPath();
  3804. var fillColor = item.color || eachSeries.color
  3805. var strokeColor = item.color || eachSeries.color
  3806. if (columnOption.linearType !== 'none') {
  3807. var grd = context.createLinearGradient(startX, item.y, startX, opts.height - opts.area[2]);
  3808. //透明渐变
  3809. if (columnOption.linearType == 'opacity') {
  3810. grd.addColorStop(0, hexToRgb(fillColor, columnOption.linearOpacity));
  3811. grd.addColorStop(1, hexToRgb(fillColor, 1));
  3812. } else {
  3813. grd.addColorStop(0, hexToRgb(columnOption.customColor[eachSeries.linearIndex], columnOption.linearOpacity));
  3814. grd.addColorStop(columnOption.colorStop, hexToRgb(columnOption.customColor[eachSeries.linearIndex], columnOption.linearOpacity));
  3815. grd.addColorStop(1, hexToRgb(fillColor, 1));
  3816. }
  3817. fillColor = grd
  3818. }
  3819. // 圆角边框
  3820. if ((columnOption.barBorderRadius && columnOption.barBorderRadius.length === 4) || columnOption.barBorderCircle) {
  3821. const left = startX;
  3822. const top = item.y;
  3823. const width = item.width;
  3824. const height = opts.height - opts.area[2] - item.y;
  3825. if (columnOption.barBorderCircle) {
  3826. columnOption.barBorderRadius = [width / 2, width / 2, 0, 0];
  3827. }
  3828. let [r0, r1, r2, r3] = columnOption.barBorderRadius;
  3829. let minRadius = Math.min(width/2,height/2);
  3830. r0 = r0 > minRadius ? minRadius : r0;
  3831. r1 = r1 > minRadius ? minRadius : r1;
  3832. r2 = r2 > minRadius ? minRadius : r2;
  3833. r3 = r3 > minRadius ? minRadius : r3;
  3834. r0 = r0 < 0 ? 0 : r0;
  3835. r1 = r1 < 0 ? 0 : r1;
  3836. r2 = r2 < 0 ? 0 : r2;
  3837. r3 = r3 < 0 ? 0 : r3;
  3838. context.arc(left + r0, top + r0, r0, -Math.PI, -Math.PI / 2);
  3839. context.arc(left + width - r1, top + r1, r1, -Math.PI / 2, 0);
  3840. context.arc(left + width - r2, top + height - r2, r2, 0, Math.PI / 2);
  3841. context.arc(left + r3, top + height - r3, r3, Math.PI / 2, Math.PI);
  3842. } else {
  3843. context.moveTo(startX, item.y);
  3844. context.lineTo(startX + item.width, item.y);
  3845. context.lineTo(startX + item.width, opts.height - opts.area[2]);
  3846. context.lineTo(startX, opts.height - opts.area[2]);
  3847. context.lineTo(startX, item.y);
  3848. context.setLineWidth(1)
  3849. context.setStrokeStyle(strokeColor);
  3850. }
  3851. context.setFillStyle(fillColor);
  3852. context.closePath();
  3853. context.fill();
  3854. }
  3855. }
  3856. columnIndex += 1;
  3857. }
  3858. //绘制区域图数据
  3859. if (eachSeries.type == 'area') {
  3860. let splitPointList = splitPoints(points,eachSeries);
  3861. for (let i = 0; i < splitPointList.length; i++) {
  3862. let points = splitPointList[i];
  3863. // 绘制区域数据
  3864. context.beginPath();
  3865. context.setStrokeStyle(eachSeries.color);
  3866. context.setStrokeStyle(hexToRgb(eachSeries.color, areaOption.opacity));
  3867. if (areaOption.gradient) {
  3868. let gradient = context.createLinearGradient(0, opts.area[0], 0, opts.height - opts.area[2]);
  3869. gradient.addColorStop('0', hexToRgb(eachSeries.color, areaOption.opacity));
  3870. gradient.addColorStop('1.0', hexToRgb("#FFFFFF", 0.1));
  3871. context.setFillStyle(gradient);
  3872. } else {
  3873. context.setFillStyle(hexToRgb(eachSeries.color, areaOption.opacity));
  3874. }
  3875. context.setLineWidth(2 * opts.pix);
  3876. if (points.length > 1) {
  3877. var firstPoint = points[0];
  3878. let lastPoint = points[points.length - 1];
  3879. context.moveTo(firstPoint.x, firstPoint.y);
  3880. let startPoint = 0;
  3881. if (eachSeries.style === 'curve') {
  3882. for (let j = 0; j < points.length; j++) {
  3883. let item = points[j];
  3884. if (startPoint == 0 && item.x > leftSpace) {
  3885. context.moveTo(item.x, item.y);
  3886. startPoint = 1;
  3887. }
  3888. if (j > 0 && item.x > leftSpace && item.x < rightSpace) {
  3889. var ctrlPoint = createCurveControlPoints(points, j - 1);
  3890. context.bezierCurveTo(ctrlPoint.ctrA.x, ctrlPoint.ctrA.y, ctrlPoint.ctrB.x, ctrlPoint.ctrB.y, item.x, item.y);
  3891. }
  3892. };
  3893. } else {
  3894. for (let j = 0; j < points.length; j++) {
  3895. let item = points[j];
  3896. if (startPoint == 0 && item.x > leftSpace) {
  3897. context.moveTo(item.x, item.y);
  3898. startPoint = 1;
  3899. }
  3900. if (j > 0 && item.x > leftSpace && item.x < rightSpace) {
  3901. context.lineTo(item.x, item.y);
  3902. }
  3903. };
  3904. }
  3905. context.lineTo(lastPoint.x, endY);
  3906. context.lineTo(firstPoint.x, endY);
  3907. context.lineTo(firstPoint.x, firstPoint.y);
  3908. } else {
  3909. let item = points[0];
  3910. context.moveTo(item.x - eachSpacing / 2, item.y);
  3911. context.lineTo(item.x + eachSpacing / 2, item.y);
  3912. context.lineTo(item.x + eachSpacing / 2, endY);
  3913. context.lineTo(item.x - eachSpacing / 2, endY);
  3914. context.moveTo(item.x - eachSpacing / 2, item.y);
  3915. }
  3916. context.closePath();
  3917. context.fill();
  3918. }
  3919. }
  3920. // 绘制折线数据图
  3921. if (eachSeries.type == 'line') {
  3922. var splitPointList = splitPoints(points,eachSeries);
  3923. splitPointList.forEach(function(points, index) {
  3924. if (eachSeries.lineType == 'dash') {
  3925. let dashLength = eachSeries.dashLength ? eachSeries.dashLength : 8;
  3926. dashLength *= opts.pix;
  3927. context.setLineDash([dashLength, dashLength]);
  3928. }
  3929. context.beginPath();
  3930. context.setStrokeStyle(eachSeries.color);
  3931. context.setLineWidth(lineOption.width * opts.pix);
  3932. if (points.length === 1) {
  3933. context.moveTo(points[0].x, points[0].y);
  3934. context.arc(points[0].x, points[0].y, 1, 0, 2 * Math.PI);
  3935. } else {
  3936. context.moveTo(points[0].x, points[0].y);
  3937. let startPoint = 0;
  3938. if (eachSeries.style == 'curve') {
  3939. for (let j = 0; j < points.length; j++) {
  3940. let item = points[j];
  3941. if (startPoint == 0 && item.x > leftSpace) {
  3942. context.moveTo(item.x, item.y);
  3943. startPoint = 1;
  3944. }
  3945. if (j > 0 && item.x > leftSpace && item.x < rightSpace) {
  3946. var ctrlPoint = createCurveControlPoints(points, j - 1);
  3947. context.bezierCurveTo(ctrlPoint.ctrA.x, ctrlPoint.ctrA.y, ctrlPoint.ctrB.x, ctrlPoint.ctrB.y,
  3948. item.x, item.y);
  3949. }
  3950. }
  3951. } else {
  3952. for (let j = 0; j < points.length; j++) {
  3953. let item = points[j];
  3954. if (startPoint == 0 && item.x > leftSpace) {
  3955. context.moveTo(item.x, item.y);
  3956. startPoint = 1;
  3957. }
  3958. if (j > 0 && item.x > leftSpace && item.x < rightSpace) {
  3959. context.lineTo(item.x, item.y);
  3960. }
  3961. }
  3962. }
  3963. context.moveTo(points[0].x, points[0].y);
  3964. }
  3965. context.stroke();
  3966. context.setLineDash([]);
  3967. });
  3968. }
  3969. // 绘制点数据图
  3970. if (eachSeries.type == 'point') {
  3971. eachSeries.addPoint = true;
  3972. }
  3973. if (eachSeries.addPoint == true && eachSeries.type !== 'column') {
  3974. drawPointShape(points, eachSeries.color, eachSeries.pointShape, context, opts);
  3975. }
  3976. });
  3977. if (opts.dataLabel !== false && process === 1) {
  3978. var columnIndex = 0;
  3979. series.forEach(function(eachSeries, seriesIndex) {
  3980. let ranges, minRange, maxRange;
  3981. ranges = [].concat(opts.chartData.yAxisData.ranges[eachSeries.index]);
  3982. minRange = ranges.pop();
  3983. maxRange = ranges.shift();
  3984. var data = eachSeries.data;
  3985. var points = getDataPoints(data, minRange, maxRange, xAxisPoints, eachSpacing, opts, config, process);
  3986. if (eachSeries.type !== 'column') {
  3987. drawPointText(points, eachSeries, config, context, opts);
  3988. } else {
  3989. points = fixColumeData(points, eachSpacing, columnLength, columnIndex, config, opts);
  3990. drawPointText(points, eachSeries, config, context, opts);
  3991. columnIndex += 1;
  3992. }
  3993. });
  3994. }
  3995. context.restore();
  3996. return {
  3997. xAxisPoints: xAxisPoints,
  3998. calPoints: calPoints,
  3999. eachSpacing: eachSpacing,
  4000. }
  4001. }
  4002. function drawToolTipBridge(opts, config, context, process, eachSpacing, xAxisPoints) {
  4003. var toolTipOption = opts.extra.tooltip || {};
  4004. if (toolTipOption.horizentalLine && opts.tooltip && process === 1 && (opts.type == 'line' || opts.type == 'area' || opts.type == 'column' || opts.type == 'mount' || opts.type == 'candle' || opts.type == 'mix')) {
  4005. drawToolTipHorizentalLine(opts, config, context, eachSpacing, xAxisPoints)
  4006. }
  4007. context.save();
  4008. if (opts._scrollDistance_ && opts._scrollDistance_ !== 0 && opts.enableScroll === true) {
  4009. context.translate(opts._scrollDistance_, 0);
  4010. }
  4011. if (opts.tooltip && opts.tooltip.textList && opts.tooltip.textList.length && process === 1) {
  4012. drawToolTip(opts.tooltip.textList, opts.tooltip.offset, opts, config, context, eachSpacing, xAxisPoints);
  4013. }
  4014. context.restore();
  4015. }
  4016. function drawXAxis(categories, opts, config, context) {
  4017. let xAxisData = opts.chartData.xAxisData,
  4018. xAxisPoints = xAxisData.xAxisPoints,
  4019. startX = xAxisData.startX,
  4020. endX = xAxisData.endX,
  4021. eachSpacing = xAxisData.eachSpacing;
  4022. var boundaryGap = 'center';
  4023. if (opts.type == 'bar' || opts.type == 'line' || opts.type == 'area'|| opts.type == 'scatter' || opts.type == 'bubble') {
  4024. boundaryGap = opts.xAxis.boundaryGap;
  4025. }
  4026. var startY = opts.height - opts.area[2];
  4027. var endY = opts.area[0];
  4028. //绘制滚动条
  4029. if (opts.enableScroll && opts.xAxis.scrollShow) {
  4030. var scrollY = opts.height - opts.area[2] + config.xAxisHeight;
  4031. var scrollScreenWidth = endX - startX;
  4032. var scrollTotalWidth = eachSpacing * (xAxisPoints.length - 1);
  4033. if(opts.type == 'mount' && opts.extra && opts.extra.mount && opts.extra.mount.widthRatio && opts.extra.mount.widthRatio > 1){
  4034. if(opts.extra.mount.widthRatio>2) opts.extra.mount.widthRatio = 2
  4035. scrollTotalWidth += (opts.extra.mount.widthRatio - 1)*eachSpacing;
  4036. }
  4037. var scrollWidth = scrollScreenWidth * scrollScreenWidth / scrollTotalWidth;
  4038. var scrollLeft = 0;
  4039. if (opts._scrollDistance_) {
  4040. scrollLeft = -opts._scrollDistance_ * (scrollScreenWidth) / scrollTotalWidth;
  4041. }
  4042. context.beginPath();
  4043. context.setLineCap('round');
  4044. context.setLineWidth(6 * opts.pix);
  4045. context.setStrokeStyle(opts.xAxis.scrollBackgroundColor || "#EFEBEF");
  4046. context.moveTo(startX, scrollY);
  4047. context.lineTo(endX, scrollY);
  4048. context.stroke();
  4049. context.closePath();
  4050. context.beginPath();
  4051. context.setLineCap('round');
  4052. context.setLineWidth(6 * opts.pix);
  4053. context.setStrokeStyle(opts.xAxis.scrollColor || "#A6A6A6");
  4054. context.moveTo(startX + scrollLeft, scrollY);
  4055. context.lineTo(startX + scrollLeft + scrollWidth, scrollY);
  4056. context.stroke();
  4057. context.closePath();
  4058. context.setLineCap('butt');
  4059. }
  4060. context.save();
  4061. if (opts._scrollDistance_ && opts._scrollDistance_ !== 0) {
  4062. context.translate(opts._scrollDistance_, 0);
  4063. }
  4064. //绘制X轴刻度线
  4065. if (opts.xAxis.calibration === true) {
  4066. context.setStrokeStyle(opts.xAxis.gridColor || "#cccccc");
  4067. context.setLineCap('butt');
  4068. context.setLineWidth(1 * opts.pix);
  4069. xAxisPoints.forEach(function(item, index) {
  4070. if (index > 0) {
  4071. context.beginPath();
  4072. context.moveTo(item - eachSpacing / 2, startY);
  4073. context.lineTo(item - eachSpacing / 2, startY + 3 * opts.pix);
  4074. context.closePath();
  4075. context.stroke();
  4076. }
  4077. });
  4078. }
  4079. //绘制X轴网格
  4080. if (opts.xAxis.disableGrid !== true) {
  4081. context.setStrokeStyle(opts.xAxis.gridColor || "#cccccc");
  4082. context.setLineCap('butt');
  4083. context.setLineWidth(1 * opts.pix);
  4084. if (opts.xAxis.gridType == 'dash') {
  4085. context.setLineDash([opts.xAxis.dashLength * opts.pix, opts.xAxis.dashLength * opts.pix]);
  4086. }
  4087. opts.xAxis.gridEval = opts.xAxis.gridEval || 1;
  4088. xAxisPoints.forEach(function(item, index) {
  4089. if (index % opts.xAxis.gridEval == 0) {
  4090. context.beginPath();
  4091. context.moveTo(item, startY);
  4092. context.lineTo(item, endY);
  4093. context.stroke();
  4094. }
  4095. });
  4096. context.setLineDash([]);
  4097. }
  4098. //绘制X轴文案
  4099. if (opts.xAxis.disabled !== true) {
  4100. // 对X轴列表做抽稀处理
  4101. //默认全部显示X轴标签
  4102. let maxXAxisListLength = categories.length;
  4103. //如果设置了X轴单屏数量
  4104. if (opts.xAxis.labelCount) {
  4105. //如果设置X轴密度
  4106. if (opts.xAxis.itemCount) {
  4107. maxXAxisListLength = Math.ceil(categories.length / opts.xAxis.itemCount * opts.xAxis.labelCount);
  4108. } else {
  4109. maxXAxisListLength = opts.xAxis.labelCount;
  4110. }
  4111. maxXAxisListLength -= 1;
  4112. }
  4113. let ratio = Math.ceil(categories.length / maxXAxisListLength);
  4114. let newCategories = [];
  4115. let cgLength = categories.length;
  4116. for (let i = 0; i < cgLength; i++) {
  4117. if (i % ratio !== 0) {
  4118. newCategories.push("");
  4119. } else {
  4120. newCategories.push(categories[i]);
  4121. }
  4122. }
  4123. newCategories[cgLength - 1] = categories[cgLength - 1];
  4124. var xAxisFontSize = opts.xAxis.fontSize * opts.pix || config.fontSize;
  4125. if (config._xAxisTextAngle_ === 0) {
  4126. newCategories.forEach(function(item, index) {
  4127. var xitem = opts.xAxis.formatter ? opts.xAxis.formatter(item,index,opts) : item;
  4128. var offset = -measureText(String(xitem), xAxisFontSize, context) / 2;
  4129. if (boundaryGap == 'center') {
  4130. offset += eachSpacing / 2;
  4131. }
  4132. var scrollHeight = 0;
  4133. if (opts.xAxis.scrollShow) {
  4134. scrollHeight = 6 * opts.pix;
  4135. }
  4136. // 如果在主视图区域内
  4137. var _scrollDistance_ = opts._scrollDistance_ || 0;
  4138. var truePoints = boundaryGap == 'center' ? xAxisPoints[index] + eachSpacing / 2 : xAxisPoints[index];
  4139. if((truePoints - Math.abs(_scrollDistance_)) >= opts.area[3] && (truePoints - Math.abs(_scrollDistance_)) <= (opts.width - opts.area[1])){
  4140. context.beginPath();
  4141. context.setFontSize(xAxisFontSize);
  4142. context.setFillStyle(opts.xAxis.fontColor || opts.fontColor);
  4143. context.fillText(String(xitem), xAxisPoints[index] + offset, startY + xAxisFontSize + (config.xAxisHeight - scrollHeight - xAxisFontSize) / 2);
  4144. context.closePath();
  4145. context.stroke();
  4146. }
  4147. });
  4148. } else {
  4149. newCategories.forEach(function(item, index) {
  4150. var xitem = opts.xAxis.formatter ? opts.xAxis.formatter(item) : item;
  4151. // 如果在主视图区域内
  4152. var _scrollDistance_ = opts._scrollDistance_ || 0;
  4153. var truePoints = boundaryGap == 'center' ? xAxisPoints[index] + eachSpacing / 2 : xAxisPoints[index];
  4154. if((truePoints - Math.abs(_scrollDistance_)) >= opts.area[3] && (truePoints - Math.abs(_scrollDistance_)) <= (opts.width - opts.area[1])){
  4155. context.save();
  4156. context.beginPath();
  4157. context.setFontSize(xAxisFontSize);
  4158. context.setFillStyle(opts.xAxis.fontColor || opts.fontColor);
  4159. var textWidth = measureText(String(xitem), xAxisFontSize, context);
  4160. var offsetX = xAxisPoints[index];
  4161. if (boundaryGap == 'center') {
  4162. offsetX = xAxisPoints[index] + eachSpacing / 2;
  4163. }
  4164. var scrollHeight = 0;
  4165. if (opts.xAxis.scrollShow) {
  4166. scrollHeight = 6 * opts.pix;
  4167. }
  4168. var offsetY = startY + 6 * opts.pix + xAxisFontSize - xAxisFontSize * Math.abs(Math.sin(config._xAxisTextAngle_));
  4169. if(opts.xAxis.rotateAngle < 0){
  4170. offsetX -= xAxisFontSize / 2;
  4171. textWidth = 0;
  4172. }else{
  4173. offsetX += xAxisFontSize / 2;
  4174. textWidth = -textWidth;
  4175. }
  4176. context.translate(offsetX, offsetY);
  4177. context.rotate(-1 * config._xAxisTextAngle_);
  4178. context.fillText(String(xitem), textWidth , 0 );
  4179. context.closePath();
  4180. context.stroke();
  4181. context.restore();
  4182. }
  4183. });
  4184. }
  4185. }
  4186. context.restore();
  4187. //绘制X轴轴线
  4188. if (opts.xAxis.axisLine) {
  4189. context.beginPath();
  4190. context.setStrokeStyle(opts.xAxis.axisLineColor);
  4191. context.setLineWidth(1 * opts.pix);
  4192. context.moveTo(startX, opts.height - opts.area[2]);
  4193. context.lineTo(endX, opts.height - opts.area[2]);
  4194. context.stroke();
  4195. }
  4196. }
  4197. function drawYAxisGrid(categories, opts, config, context) {
  4198. if (opts.yAxis.disableGrid === true) {
  4199. return;
  4200. }
  4201. let spacingValid = opts.height - opts.area[0] - opts.area[2];
  4202. let eachSpacing = spacingValid / opts.yAxis.splitNumber;
  4203. let startX = opts.area[3];
  4204. let xAxisPoints = opts.chartData.xAxisData.xAxisPoints,
  4205. xAxiseachSpacing = opts.chartData.xAxisData.eachSpacing;
  4206. let TotalWidth = xAxiseachSpacing * (xAxisPoints.length - 1);
  4207. if(opts.type == 'mount' && opts.extra && opts.extra.mount && opts.extra.mount.widthRatio && opts.extra.mount.widthRatio > 1 ){
  4208. if(opts.extra.mount.widthRatio>2) opts.extra.mount.widthRatio = 2
  4209. TotalWidth += (opts.extra.mount.widthRatio - 1)*xAxiseachSpacing;
  4210. }
  4211. let endX = startX + TotalWidth;
  4212. let points = [];
  4213. let startY = 1
  4214. if (opts.xAxis.axisLine === false) {
  4215. startY = 0
  4216. }
  4217. for (let i = startY; i < opts.yAxis.splitNumber + 1; i++) {
  4218. points.push(opts.height - opts.area[2] - eachSpacing * i);
  4219. }
  4220. context.save();
  4221. if (opts._scrollDistance_ && opts._scrollDistance_ !== 0) {
  4222. context.translate(opts._scrollDistance_, 0);
  4223. }
  4224. if (opts.yAxis.gridType == 'dash') {
  4225. context.setLineDash([opts.yAxis.dashLength * opts.pix, opts.yAxis.dashLength * opts.pix]);
  4226. }
  4227. context.setStrokeStyle(opts.yAxis.gridColor);
  4228. context.setLineWidth(1 * opts.pix);
  4229. points.forEach(function(item, index) {
  4230. context.beginPath();
  4231. context.moveTo(startX, item);
  4232. context.lineTo(endX, item);
  4233. context.stroke();
  4234. });
  4235. context.setLineDash([]);
  4236. context.restore();
  4237. }
  4238. function drawYAxis(series, opts, config, context) {
  4239. if (opts.yAxis.disabled === true) {
  4240. return;
  4241. }
  4242. var spacingValid = opts.height - opts.area[0] - opts.area[2];
  4243. var eachSpacing = spacingValid / opts.yAxis.splitNumber;
  4244. var startX = opts.area[3];
  4245. var endX = opts.width - opts.area[1];
  4246. var endY = opts.height - opts.area[2];
  4247. // set YAxis background
  4248. context.beginPath();
  4249. context.setFillStyle(opts.background);
  4250. if (opts.enableScroll == true && opts.xAxis.scrollPosition && opts.xAxis.scrollPosition !== 'left') {
  4251. context.fillRect(0, 0, startX, endY + 2 * opts.pix);
  4252. }
  4253. if (opts.enableScroll == true && opts.xAxis.scrollPosition && opts.xAxis.scrollPosition !== 'right') {
  4254. context.fillRect(endX, 0, opts.width, endY + 2 * opts.pix);
  4255. }
  4256. context.closePath();
  4257. context.stroke();
  4258. let tStartLeft = opts.area[3];
  4259. let tStartRight = opts.width - opts.area[1];
  4260. let tStartCenter = opts.area[3] + (opts.width - opts.area[1] - opts.area[3]) / 2;
  4261. if (opts.yAxis.data) {
  4262. for (let i = 0; i < opts.yAxis.data.length; i++) {
  4263. let yData = opts.yAxis.data[i];
  4264. var points = [];
  4265. if(yData.type === 'categories'){
  4266. for (let i = 0; i <= yData.categories.length; i++) {
  4267. points.push(opts.area[0] + spacingValid / yData.categories.length / 2 + spacingValid / yData.categories.length * i);
  4268. }
  4269. }else{
  4270. for (let i = 0; i <= opts.yAxis.splitNumber; i++) {
  4271. points.push(opts.area[0] + eachSpacing * i);
  4272. }
  4273. }
  4274. if (yData.disabled !== true) {
  4275. let rangesFormat = opts.chartData.yAxisData.rangesFormat[i];
  4276. let yAxisFontSize = yData.fontSize ? yData.fontSize * opts.pix : config.fontSize;
  4277. let yAxisWidth = opts.chartData.yAxisData.yAxisWidth[i];
  4278. let textAlign = yData.textAlign || "right";
  4279. //画Y轴刻度及文案
  4280. rangesFormat.forEach(function(item, index) {
  4281. var pos = points[index];
  4282. context.beginPath();
  4283. context.setFontSize(yAxisFontSize);
  4284. context.setLineWidth(1 * opts.pix);
  4285. context.setStrokeStyle(yData.axisLineColor || '#cccccc');
  4286. context.setFillStyle(yData.fontColor || opts.fontColor);
  4287. let tmpstrat = 0;
  4288. let gapwidth = 4 * opts.pix;
  4289. if (yAxisWidth.position == 'left') {
  4290. //画刻度线
  4291. if (yData.calibration == true) {
  4292. context.moveTo(tStartLeft, pos);
  4293. context.lineTo(tStartLeft - 3 * opts.pix, pos);
  4294. gapwidth += 3 * opts.pix;
  4295. }
  4296. //画文字
  4297. switch (textAlign) {
  4298. case "left":
  4299. context.setTextAlign('left');
  4300. tmpstrat = tStartLeft - yAxisWidth.width
  4301. break;
  4302. case "right":
  4303. context.setTextAlign('right');
  4304. tmpstrat = tStartLeft - gapwidth
  4305. break;
  4306. default:
  4307. context.setTextAlign('center');
  4308. tmpstrat = tStartLeft - yAxisWidth.width / 2
  4309. }
  4310. context.fillText(String(item), tmpstrat, pos + yAxisFontSize / 2 - 3 * opts.pix);
  4311. } else if (yAxisWidth.position == 'right') {
  4312. //画刻度线
  4313. if (yData.calibration == true) {
  4314. context.moveTo(tStartRight, pos);
  4315. context.lineTo(tStartRight + 3 * opts.pix, pos);
  4316. gapwidth += 3 * opts.pix;
  4317. }
  4318. switch (textAlign) {
  4319. case "left":
  4320. context.setTextAlign('left');
  4321. tmpstrat = tStartRight + gapwidth
  4322. break;
  4323. case "right":
  4324. context.setTextAlign('right');
  4325. tmpstrat = tStartRight + yAxisWidth.width
  4326. break;
  4327. default:
  4328. context.setTextAlign('center');
  4329. tmpstrat = tStartRight + yAxisWidth.width / 2
  4330. }
  4331. context.fillText(String(item), tmpstrat, pos + yAxisFontSize / 2 - 3 * opts.pix);
  4332. } else if (yAxisWidth.position == 'center') {
  4333. //画刻度线
  4334. if (yData.calibration == true) {
  4335. context.moveTo(tStartCenter, pos);
  4336. context.lineTo(tStartCenter - 3 * opts.pix, pos);
  4337. gapwidth += 3 * opts.pix;
  4338. }
  4339. //画文字
  4340. switch (textAlign) {
  4341. case "left":
  4342. context.setTextAlign('left');
  4343. tmpstrat = tStartCenter - yAxisWidth.width
  4344. break;
  4345. case "right":
  4346. context.setTextAlign('right');
  4347. tmpstrat = tStartCenter - gapwidth
  4348. break;
  4349. default:
  4350. context.setTextAlign('center');
  4351. tmpstrat = tStartCenter - yAxisWidth.width / 2
  4352. }
  4353. context.fillText(String(item), tmpstrat, pos + yAxisFontSize / 2 - 3 * opts.pix);
  4354. }
  4355. context.closePath();
  4356. context.stroke();
  4357. context.setTextAlign('left');
  4358. });
  4359. //画Y轴轴线
  4360. if (yData.axisLine !== false) {
  4361. context.beginPath();
  4362. context.setStrokeStyle(yData.axisLineColor || '#cccccc');
  4363. context.setLineWidth(1 * opts.pix);
  4364. if (yAxisWidth.position == 'left') {
  4365. context.moveTo(tStartLeft, opts.height - opts.area[2]);
  4366. context.lineTo(tStartLeft, opts.area[0]);
  4367. } else if (yAxisWidth.position == 'right') {
  4368. context.moveTo(tStartRight, opts.height - opts.area[2]);
  4369. context.lineTo(tStartRight, opts.area[0]);
  4370. } else if (yAxisWidth.position == 'center') {
  4371. context.moveTo(tStartCenter, opts.height - opts.area[2]);
  4372. context.lineTo(tStartCenter, opts.area[0]);
  4373. }
  4374. context.stroke();
  4375. }
  4376. //画Y轴标题
  4377. if (opts.yAxis.showTitle) {
  4378. let titleFontSize = yData.titleFontSize * opts.pix || config.fontSize;
  4379. let title = yData.title;
  4380. context.beginPath();
  4381. context.setFontSize(titleFontSize);
  4382. context.setFillStyle(yData.titleFontColor || opts.fontColor);
  4383. if (yAxisWidth.position == 'left') {
  4384. context.fillText(title, tStartLeft - measureText(title, titleFontSize, context) / 2 + (yData.titleOffsetX || 0), opts.area[0] - (10 - (yData.titleOffsetY || 0)) * opts.pix);
  4385. } else if (yAxisWidth.position == 'right') {
  4386. context.fillText(title, tStartRight - measureText(title, titleFontSize, context) / 2 + (yData.titleOffsetX || 0), opts.area[0] - (10 - (yData.titleOffsetY || 0)) * opts.pix);
  4387. } else if (yAxisWidth.position == 'center') {
  4388. context.fillText(title, tStartCenter - measureText(title, titleFontSize, context) / 2 + (yData.titleOffsetX || 0), opts.area[0] - (10 - (yData.titleOffsetY || 0)) * opts.pix);
  4389. }
  4390. context.closePath();
  4391. context.stroke();
  4392. }
  4393. if (yAxisWidth.position == 'left') {
  4394. tStartLeft -= (yAxisWidth.width + opts.yAxis.padding * opts.pix);
  4395. } else {
  4396. tStartRight += yAxisWidth.width + opts.yAxis.padding * opts.pix;
  4397. }
  4398. }
  4399. }
  4400. }
  4401. }
  4402. function drawLegend(series, opts, config, context, chartData) {
  4403. if (opts.legend.show === false) {
  4404. return;
  4405. }
  4406. let legendData = chartData.legendData;
  4407. let legendList = legendData.points;
  4408. let legendArea = legendData.area;
  4409. let padding = opts.legend.padding * opts.pix;
  4410. let fontSize = opts.legend.fontSize * opts.pix;
  4411. let shapeWidth = 15 * opts.pix;
  4412. let shapeRight = 5 * opts.pix;
  4413. let itemGap = opts.legend.itemGap * opts.pix;
  4414. let lineHeight = Math.max(opts.legend.lineHeight * opts.pix, fontSize);
  4415. //画背景及边框
  4416. context.beginPath();
  4417. context.setLineWidth(opts.legend.borderWidth * opts.pix);
  4418. context.setStrokeStyle(opts.legend.borderColor);
  4419. context.setFillStyle(opts.legend.backgroundColor);
  4420. context.moveTo(legendArea.start.x, legendArea.start.y);
  4421. context.rect(legendArea.start.x, legendArea.start.y, legendArea.width, legendArea.height);
  4422. context.closePath();
  4423. context.fill();
  4424. context.stroke();
  4425. legendList.forEach(function(itemList, listIndex) {
  4426. let width = 0;
  4427. let height = 0;
  4428. width = legendData.widthArr[listIndex];
  4429. height = legendData.heightArr[listIndex];
  4430. let startX = 0;
  4431. let startY = 0;
  4432. if (opts.legend.position == 'top' || opts.legend.position == 'bottom') {
  4433. switch (opts.legend.float) {
  4434. case 'left':
  4435. startX = legendArea.start.x + padding;
  4436. break;
  4437. case 'right':
  4438. startX = legendArea.start.x + legendArea.width - width;
  4439. break;
  4440. default:
  4441. startX = legendArea.start.x + (legendArea.width - width) / 2;
  4442. }
  4443. startY = legendArea.start.y + padding + listIndex * lineHeight;
  4444. } else {
  4445. if (listIndex == 0) {
  4446. width = 0;
  4447. } else {
  4448. width = legendData.widthArr[listIndex - 1];
  4449. }
  4450. startX = legendArea.start.x + padding + width;
  4451. startY = legendArea.start.y + padding + (legendArea.height - height) / 2;
  4452. }
  4453. context.setFontSize(config.fontSize);
  4454. for (let i = 0; i < itemList.length; i++) {
  4455. let item = itemList[i];
  4456. item.area = [0, 0, 0, 0];
  4457. item.area[0] = startX;
  4458. item.area[1] = startY;
  4459. item.area[3] = startY + lineHeight;
  4460. context.beginPath();
  4461. context.setLineWidth(1 * opts.pix);
  4462. context.setStrokeStyle(item.show ? item.color : opts.legend.hiddenColor);
  4463. context.setFillStyle(item.show ? item.color : opts.legend.hiddenColor);
  4464. switch (item.legendShape) {
  4465. case 'line':
  4466. context.moveTo(startX, startY + 0.5 * lineHeight - 2 * opts.pix);
  4467. context.fillRect(startX, startY + 0.5 * lineHeight - 2 * opts.pix, 15 * opts.pix, 4 * opts.pix);
  4468. break;
  4469. case 'triangle':
  4470. context.moveTo(startX + 7.5 * opts.pix, startY + 0.5 * lineHeight - 5 * opts.pix);
  4471. context.lineTo(startX + 2.5 * opts.pix, startY + 0.5 * lineHeight + 5 * opts.pix);
  4472. context.lineTo(startX + 12.5 * opts.pix, startY + 0.5 * lineHeight + 5 * opts.pix);
  4473. context.lineTo(startX + 7.5 * opts.pix, startY + 0.5 * lineHeight - 5 * opts.pix);
  4474. break;
  4475. case 'diamond':
  4476. context.moveTo(startX + 7.5 * opts.pix, startY + 0.5 * lineHeight - 5 * opts.pix);
  4477. context.lineTo(startX + 2.5 * opts.pix, startY + 0.5 * lineHeight);
  4478. context.lineTo(startX + 7.5 * opts.pix, startY + 0.5 * lineHeight + 5 * opts.pix);
  4479. context.lineTo(startX + 12.5 * opts.pix, startY + 0.5 * lineHeight);
  4480. context.lineTo(startX + 7.5 * opts.pix, startY + 0.5 * lineHeight - 5 * opts.pix);
  4481. break;
  4482. case 'circle':
  4483. context.moveTo(startX + 7.5 * opts.pix, startY + 0.5 * lineHeight);
  4484. context.arc(startX + 7.5 * opts.pix, startY + 0.5 * lineHeight, 5 * opts.pix, 0, 2 * Math.PI);
  4485. break;
  4486. case 'rect':
  4487. context.moveTo(startX, startY + 0.5 * lineHeight - 5 * opts.pix);
  4488. context.fillRect(startX, startY + 0.5 * lineHeight - 5 * opts.pix, 15 * opts.pix, 10 * opts.pix);
  4489. break;
  4490. case 'square':
  4491. context.moveTo(startX + 5 * opts.pix, startY + 0.5 * lineHeight - 5 * opts.pix);
  4492. context.fillRect(startX + 5 * opts.pix, startY + 0.5 * lineHeight - 5 * opts.pix, 10 * opts.pix, 10 * opts.pix);
  4493. break;
  4494. case 'none':
  4495. break;
  4496. default:
  4497. context.moveTo(startX, startY + 0.5 * lineHeight - 5 * opts.pix);
  4498. context.fillRect(startX, startY + 0.5 * lineHeight - 5 * opts.pix, 15 * opts.pix, 10 * opts.pix);
  4499. }
  4500. context.closePath();
  4501. context.fill();
  4502. context.stroke();
  4503. startX += shapeWidth + shapeRight;
  4504. let fontTrans = 0.5 * lineHeight + 0.5 * fontSize - 2;
  4505. const legendText = item.legendText ? item.legendText : item.name;
  4506. context.beginPath();
  4507. context.setFontSize(fontSize);
  4508. context.setFillStyle(item.show ? opts.legend.fontColor : opts.legend.hiddenColor);
  4509. context.fillText(legendText, startX, startY + fontTrans);
  4510. context.closePath();
  4511. context.stroke();
  4512. if (opts.legend.position == 'top' || opts.legend.position == 'bottom') {
  4513. startX += measureText(legendText, fontSize, context) + itemGap;
  4514. item.area[2] = startX;
  4515. } else {
  4516. item.area[2] = startX + measureText(legendText, fontSize, context) + itemGap;;
  4517. startX -= shapeWidth + shapeRight;
  4518. startY += lineHeight;
  4519. }
  4520. }
  4521. });
  4522. }
  4523. function drawPieDataPoints(series, opts, config, context) {
  4524. var process = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : 1;
  4525. var pieOption = assign({}, {
  4526. activeOpacity: 0.5,
  4527. activeRadius: 10,
  4528. offsetAngle: 0,
  4529. labelWidth: 15,
  4530. ringWidth: 30,
  4531. customRadius: 0,
  4532. border: false,
  4533. borderWidth: 2,
  4534. borderColor: '#FFFFFF',
  4535. centerColor: '#FFFFFF',
  4536. linearType: 'none',
  4537. customColor: [],
  4538. }, opts.type == "pie" ? opts.extra.pie : opts.extra.ring);
  4539. var centerPosition = {
  4540. x: opts.area[3] + (opts.width - opts.area[1] - opts.area[3]) / 2,
  4541. y: opts.area[0] + (opts.height - opts.area[0] - opts.area[2]) / 2
  4542. };
  4543. if (config.pieChartLinePadding == 0) {
  4544. config.pieChartLinePadding = pieOption.activeRadius * opts.pix;
  4545. }
  4546. var radius = Math.min((opts.width - opts.area[1] - opts.area[3]) / 2 - config.pieChartLinePadding - config.pieChartTextPadding - config._pieTextMaxLength_, (opts.height - opts.area[0] - opts.area[2]) / 2 - config.pieChartLinePadding - config.pieChartTextPadding);
  4547. radius = radius < 10 ? 10 : radius;
  4548. if (pieOption.customRadius > 0) {
  4549. radius = pieOption.customRadius * opts.pix;
  4550. }
  4551. series = getPieDataPoints(series, radius, process);
  4552. var activeRadius = pieOption.activeRadius * opts.pix;
  4553. pieOption.customColor = fillCustomColor(pieOption.linearType, pieOption.customColor, series, config);
  4554. series = series.map(function(eachSeries) {
  4555. eachSeries._start_ += (pieOption.offsetAngle) * Math.PI / 180;
  4556. return eachSeries;
  4557. });
  4558. series.forEach(function(eachSeries, seriesIndex) {
  4559. if (opts.tooltip) {
  4560. if (opts.tooltip.index == seriesIndex) {
  4561. context.beginPath();
  4562. context.setFillStyle(hexToRgb(eachSeries.color, pieOption.activeOpacity || 0.5));
  4563. context.moveTo(centerPosition.x, centerPosition.y);
  4564. context.arc(centerPosition.x, centerPosition.y, eachSeries._radius_ + activeRadius, eachSeries._start_, eachSeries._start_ + 2 * eachSeries._proportion_ * Math.PI);
  4565. context.closePath();
  4566. context.fill();
  4567. }
  4568. }
  4569. context.beginPath();
  4570. context.setLineWidth(pieOption.borderWidth * opts.pix);
  4571. context.lineJoin = "round";
  4572. context.setStrokeStyle(pieOption.borderColor);
  4573. var fillcolor = eachSeries.color;
  4574. if (pieOption.linearType == 'custom') {
  4575. var grd;
  4576. if(context.createCircularGradient){
  4577. grd = context.createCircularGradient(centerPosition.x, centerPosition.y, eachSeries._radius_)
  4578. }else{
  4579. grd = context.createRadialGradient(centerPosition.x, centerPosition.y, 0,centerPosition.x, centerPosition.y, eachSeries._radius_)
  4580. }
  4581. grd.addColorStop(0, hexToRgb(pieOption.customColor[eachSeries.linearIndex], 1))
  4582. grd.addColorStop(1, hexToRgb(eachSeries.color, 1))
  4583. fillcolor = grd
  4584. }
  4585. context.setFillStyle(fillcolor);
  4586. context.moveTo(centerPosition.x, centerPosition.y);
  4587. context.arc(centerPosition.x, centerPosition.y, eachSeries._radius_, eachSeries._start_, eachSeries._start_ + 2 * eachSeries._proportion_ * Math.PI);
  4588. context.closePath();
  4589. context.fill();
  4590. if (pieOption.border == true) {
  4591. context.stroke();
  4592. }
  4593. });
  4594. if (opts.type === 'ring') {
  4595. var innerPieWidth = radius * 0.6;
  4596. if (typeof pieOption.ringWidth === 'number' && pieOption.ringWidth > 0) {
  4597. innerPieWidth = Math.max(0, radius - pieOption.ringWidth * opts.pix);
  4598. }
  4599. context.beginPath();
  4600. context.setFillStyle(pieOption.centerColor);
  4601. context.moveTo(centerPosition.x, centerPosition.y);
  4602. context.arc(centerPosition.x, centerPosition.y, innerPieWidth, 0, 2 * Math.PI);
  4603. context.closePath();
  4604. context.fill();
  4605. }
  4606. if (opts.dataLabel !== false && process === 1) {
  4607. drawPieText(series, opts, config, context, radius, centerPosition);
  4608. }
  4609. if (process === 1 && opts.type === 'ring') {
  4610. drawRingTitle(opts, config, context, centerPosition);
  4611. }
  4612. return {
  4613. center: centerPosition,
  4614. radius: radius,
  4615. series: series
  4616. };
  4617. }
  4618. function drawRoseDataPoints(series, opts, config, context) {
  4619. var process = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : 1;
  4620. var roseOption = assign({}, {
  4621. type: 'area',
  4622. activeOpacity: 0.5,
  4623. activeRadius: 10,
  4624. offsetAngle: 0,
  4625. labelWidth: 15,
  4626. border: false,
  4627. borderWidth: 2,
  4628. borderColor: '#FFFFFF',
  4629. linearType: 'none',
  4630. customColor: [],
  4631. }, opts.extra.rose);
  4632. if (config.pieChartLinePadding == 0) {
  4633. config.pieChartLinePadding = roseOption.activeRadius * opts.pix;
  4634. }
  4635. var centerPosition = {
  4636. x: opts.area[3] + (opts.width - opts.area[1] - opts.area[3]) / 2,
  4637. y: opts.area[0] + (opts.height - opts.area[0] - opts.area[2]) / 2
  4638. };
  4639. var radius = Math.min((opts.width - opts.area[1] - opts.area[3]) / 2 - config.pieChartLinePadding - config.pieChartTextPadding - config._pieTextMaxLength_, (opts.height - opts.area[0] - opts.area[2]) / 2 - config.pieChartLinePadding - config.pieChartTextPadding);
  4640. radius = radius < 10 ? 10 : radius;
  4641. var minRadius = roseOption.minRadius || radius * 0.5;
  4642. series = getRoseDataPoints(series, roseOption.type, minRadius, radius, process);
  4643. var activeRadius = roseOption.activeRadius * opts.pix;
  4644. roseOption.customColor = fillCustomColor(roseOption.linearType, roseOption.customColor, series, config);
  4645. series = series.map(function(eachSeries) {
  4646. eachSeries._start_ += (roseOption.offsetAngle || 0) * Math.PI / 180;
  4647. return eachSeries;
  4648. });
  4649. series.forEach(function(eachSeries, seriesIndex) {
  4650. if (opts.tooltip) {
  4651. if (opts.tooltip.index == seriesIndex) {
  4652. context.beginPath();
  4653. context.setFillStyle(hexToRgb(eachSeries.color, roseOption.activeOpacity || 0.5));
  4654. context.moveTo(centerPosition.x, centerPosition.y);
  4655. context.arc(centerPosition.x, centerPosition.y, activeRadius + eachSeries._radius_, eachSeries._start_, eachSeries._start_ + 2 * eachSeries._rose_proportion_ * Math.PI);
  4656. context.closePath();
  4657. context.fill();
  4658. }
  4659. }
  4660. context.beginPath();
  4661. context.setLineWidth(roseOption.borderWidth * opts.pix);
  4662. context.lineJoin = "round";
  4663. context.setStrokeStyle(roseOption.borderColor);
  4664. var fillcolor = eachSeries.color;
  4665. if (roseOption.linearType == 'custom') {
  4666. var grd;
  4667. if(context.createCircularGradient){
  4668. grd = context.createCircularGradient(centerPosition.x, centerPosition.y, eachSeries._radius_)
  4669. }else{
  4670. grd = context.createRadialGradient(centerPosition.x, centerPosition.y, 0,centerPosition.x, centerPosition.y, eachSeries._radius_)
  4671. }
  4672. grd.addColorStop(0, hexToRgb(roseOption.customColor[eachSeries.linearIndex], 1))
  4673. grd.addColorStop(1, hexToRgb(eachSeries.color, 1))
  4674. fillcolor = grd
  4675. }
  4676. context.setFillStyle(fillcolor);
  4677. context.moveTo(centerPosition.x, centerPosition.y);
  4678. context.arc(centerPosition.x, centerPosition.y, eachSeries._radius_, eachSeries._start_, eachSeries._start_ + 2 * eachSeries._rose_proportion_ * Math.PI);
  4679. context.closePath();
  4680. context.fill();
  4681. if (roseOption.border == true) {
  4682. context.stroke();
  4683. }
  4684. });
  4685. if (opts.dataLabel !== false && process === 1) {
  4686. drawPieText(series, opts, config, context, radius, centerPosition);
  4687. }
  4688. return {
  4689. center: centerPosition,
  4690. radius: radius,
  4691. series: series
  4692. };
  4693. }
  4694. function drawArcbarDataPoints(series, opts, config, context) {
  4695. var process = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : 1;
  4696. var arcbarOption = assign({}, {
  4697. startAngle: 0.75,
  4698. endAngle: 0.25,
  4699. type: 'default',
  4700. direction: 'cw',
  4701. lineCap: 'round',
  4702. width: 12 ,
  4703. gap: 2 ,
  4704. linearType: 'none',
  4705. customColor: [],
  4706. }, opts.extra.arcbar);
  4707. series = getArcbarDataPoints(series, arcbarOption, process);
  4708. var centerPosition;
  4709. if (arcbarOption.centerX || arcbarOption.centerY) {
  4710. centerPosition = {
  4711. x: arcbarOption.centerX ? arcbarOption.centerX : opts.width / 2,
  4712. y: arcbarOption.centerY ? arcbarOption.centerY : opts.height / 2
  4713. };
  4714. } else {
  4715. centerPosition = {
  4716. x: opts.width / 2,
  4717. y: opts.height / 2
  4718. };
  4719. }
  4720. var radius;
  4721. if (arcbarOption.radius) {
  4722. radius = arcbarOption.radius;
  4723. } else {
  4724. radius = Math.min(centerPosition.x, centerPosition.y);
  4725. radius -= 5 * opts.pix;
  4726. radius -= arcbarOption.width / 2;
  4727. }
  4728. radius = radius < 10 ? 10 : radius;
  4729. arcbarOption.customColor = fillCustomColor(arcbarOption.linearType, arcbarOption.customColor, series, config);
  4730. for (let i = 0; i < series.length; i++) {
  4731. let eachSeries = series[i];
  4732. //背景颜色
  4733. context.setLineWidth(arcbarOption.width * opts.pix);
  4734. context.setStrokeStyle(arcbarOption.backgroundColor || '#E9E9E9');
  4735. context.setLineCap(arcbarOption.lineCap);
  4736. context.beginPath();
  4737. if (arcbarOption.type == 'default') {
  4738. context.arc(centerPosition.x, centerPosition.y, radius - (arcbarOption.width * opts.pix + arcbarOption.gap * opts.pix) * i, arcbarOption.startAngle * Math.PI, arcbarOption.endAngle * Math.PI, arcbarOption.direction == 'ccw');
  4739. } else {
  4740. context.arc(centerPosition.x, centerPosition.y, radius - (arcbarOption.width * opts.pix + arcbarOption.gap * opts.pix) * i, 0, 2 * Math.PI, arcbarOption.direction == 'ccw');
  4741. }
  4742. context.stroke();
  4743. //进度条
  4744. var fillColor = eachSeries.color
  4745. if(arcbarOption.linearType == 'custom'){
  4746. var grd = context.createLinearGradient(centerPosition.x - radius, centerPosition.y, centerPosition.x + radius, centerPosition.y);
  4747. grd.addColorStop(1, hexToRgb(arcbarOption.customColor[eachSeries.linearIndex], 1))
  4748. grd.addColorStop(0, hexToRgb(eachSeries.color, 1))
  4749. fillColor = grd;
  4750. }
  4751. context.setLineWidth(arcbarOption.width * opts.pix);
  4752. context.setStrokeStyle(fillColor);
  4753. context.setLineCap(arcbarOption.lineCap);
  4754. context.beginPath();
  4755. context.arc(centerPosition.x, centerPosition.y, radius - (arcbarOption.width * opts.pix + arcbarOption.gap * opts.pix) * i, arcbarOption.startAngle * Math.PI, eachSeries._proportion_ * Math.PI, arcbarOption.direction == 'ccw');
  4756. context.stroke();
  4757. }
  4758. drawRingTitle(opts, config, context, centerPosition);
  4759. return {
  4760. center: centerPosition,
  4761. radius: radius,
  4762. series: series
  4763. };
  4764. }
  4765. function drawGaugeDataPoints(categories, series, opts, config, context) {
  4766. var process = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : 1;
  4767. var gaugeOption = assign({}, {
  4768. type: 'default',
  4769. startAngle: 0.75,
  4770. endAngle: 0.25,
  4771. width: 15,
  4772. labelOffset:13,
  4773. splitLine: {
  4774. fixRadius: 0,
  4775. splitNumber: 10,
  4776. width: 15,
  4777. color: '#FFFFFF',
  4778. childNumber: 5,
  4779. childWidth: 5
  4780. },
  4781. pointer: {
  4782. width: 15,
  4783. color: 'auto'
  4784. }
  4785. }, opts.extra.gauge);
  4786. if (gaugeOption.oldAngle == undefined) {
  4787. gaugeOption.oldAngle = gaugeOption.startAngle;
  4788. }
  4789. if (gaugeOption.oldData == undefined) {
  4790. gaugeOption.oldData = 0;
  4791. }
  4792. categories = getGaugeAxisPoints(categories, gaugeOption.startAngle, gaugeOption.endAngle);
  4793. var centerPosition = {
  4794. x: opts.width / 2,
  4795. y: opts.height / 2
  4796. };
  4797. var radius = Math.min(centerPosition.x, centerPosition.y);
  4798. radius -= 5 * opts.pix;
  4799. radius -= gaugeOption.width / 2;
  4800. radius = radius < 10 ? 10 : radius;
  4801. var innerRadius = radius - gaugeOption.width;
  4802. var totalAngle = 0;
  4803. //判断仪表盘的样式:default百度样式,progress新样式
  4804. if (gaugeOption.type == 'progress') {
  4805. //## 第一步画中心圆形背景和进度条背景
  4806. //中心圆形背景
  4807. var pieRadius = radius - gaugeOption.width * 3;
  4808. context.beginPath();
  4809. let gradient = context.createLinearGradient(centerPosition.x, centerPosition.y - pieRadius, centerPosition.x, centerPosition.y + pieRadius);
  4810. //配置渐变填充(起点:中心点向上减半径;结束点中心点向下加半径)
  4811. gradient.addColorStop('0', hexToRgb(series[0].color, 0.3));
  4812. gradient.addColorStop('1.0', hexToRgb("#FFFFFF", 0.1));
  4813. context.setFillStyle(gradient);
  4814. context.arc(centerPosition.x, centerPosition.y, pieRadius, 0, 2 * Math.PI, false);
  4815. context.fill();
  4816. //画进度条背景
  4817. context.setLineWidth(gaugeOption.width);
  4818. context.setStrokeStyle(hexToRgb(series[0].color, 0.3));
  4819. context.setLineCap('round');
  4820. context.beginPath();
  4821. context.arc(centerPosition.x, centerPosition.y, innerRadius, gaugeOption.startAngle * Math.PI, gaugeOption.endAngle * Math.PI, false);
  4822. context.stroke();
  4823. //## 第二步画刻度线
  4824. totalAngle = gaugeOption.startAngle - gaugeOption.endAngle + 1;
  4825. let splitAngle = totalAngle / gaugeOption.splitLine.splitNumber;
  4826. let childAngle = totalAngle / gaugeOption.splitLine.splitNumber / gaugeOption.splitLine.childNumber;
  4827. let startX = -radius - gaugeOption.width * 0.5 - gaugeOption.splitLine.fixRadius;
  4828. let endX = -radius - gaugeOption.width - gaugeOption.splitLine.fixRadius + gaugeOption.splitLine.width;
  4829. context.save();
  4830. context.translate(centerPosition.x, centerPosition.y);
  4831. context.rotate((gaugeOption.startAngle - 1) * Math.PI);
  4832. let len = gaugeOption.splitLine.splitNumber * gaugeOption.splitLine.childNumber + 1;
  4833. let proc = series[0].data * process;
  4834. for (let i = 0; i < len; i++) {
  4835. context.beginPath();
  4836. //刻度线随进度变色
  4837. if (proc > (i / len)) {
  4838. context.setStrokeStyle(hexToRgb(series[0].color, 1));
  4839. } else {
  4840. context.setStrokeStyle(hexToRgb(series[0].color, 0.3));
  4841. }
  4842. context.setLineWidth(3 * opts.pix);
  4843. context.moveTo(startX, 0);
  4844. context.lineTo(endX, 0);
  4845. context.stroke();
  4846. context.rotate(childAngle * Math.PI);
  4847. }
  4848. context.restore();
  4849. //## 第三步画进度条
  4850. series = getGaugeArcbarDataPoints(series, gaugeOption, process);
  4851. context.setLineWidth(gaugeOption.width);
  4852. context.setStrokeStyle(series[0].color);
  4853. context.setLineCap('round');
  4854. context.beginPath();
  4855. context.arc(centerPosition.x, centerPosition.y, innerRadius, gaugeOption.startAngle * Math.PI, series[0]._proportion_ * Math.PI, false);
  4856. context.stroke();
  4857. //## 第四步画指针
  4858. let pointerRadius = radius - gaugeOption.width * 2.5;
  4859. context.save();
  4860. context.translate(centerPosition.x, centerPosition.y);
  4861. context.rotate((series[0]._proportion_ - 1) * Math.PI);
  4862. context.beginPath();
  4863. context.setLineWidth(gaugeOption.width / 3);
  4864. let gradient3 = context.createLinearGradient(0, -pointerRadius * 0.6, 0, pointerRadius * 0.6);
  4865. gradient3.addColorStop('0', hexToRgb('#FFFFFF', 0));
  4866. gradient3.addColorStop('0.5', hexToRgb(series[0].color, 1));
  4867. gradient3.addColorStop('1.0', hexToRgb('#FFFFFF', 0));
  4868. context.setStrokeStyle(gradient3);
  4869. context.arc(0, 0, pointerRadius, 0.85 * Math.PI, 1.15 * Math.PI, false);
  4870. context.stroke();
  4871. context.beginPath();
  4872. context.setLineWidth(1);
  4873. context.setStrokeStyle(series[0].color);
  4874. context.setFillStyle(series[0].color);
  4875. context.moveTo(-pointerRadius - gaugeOption.width / 3 / 2, -4);
  4876. context.lineTo(-pointerRadius - gaugeOption.width / 3 / 2 - 4, 0);
  4877. context.lineTo(-pointerRadius - gaugeOption.width / 3 / 2, 4);
  4878. context.lineTo(-pointerRadius - gaugeOption.width / 3 / 2, -4);
  4879. context.stroke();
  4880. context.fill();
  4881. context.restore();
  4882. //default百度样式
  4883. } else {
  4884. //画背景
  4885. context.setLineWidth(gaugeOption.width);
  4886. context.setLineCap('butt');
  4887. for (let i = 0; i < categories.length; i++) {
  4888. let eachCategories = categories[i];
  4889. context.beginPath();
  4890. context.setStrokeStyle(eachCategories.color);
  4891. context.arc(centerPosition.x, centerPosition.y, radius, eachCategories._startAngle_ * Math.PI, eachCategories._endAngle_ * Math.PI, false);
  4892. context.stroke();
  4893. }
  4894. context.save();
  4895. //画刻度线
  4896. totalAngle = gaugeOption.startAngle - gaugeOption.endAngle + 1;
  4897. let splitAngle = totalAngle / gaugeOption.splitLine.splitNumber;
  4898. let childAngle = totalAngle / gaugeOption.splitLine.splitNumber / gaugeOption.splitLine.childNumber;
  4899. let startX = -radius - gaugeOption.width * 0.5 - gaugeOption.splitLine.fixRadius;
  4900. let endX = -radius - gaugeOption.width * 0.5 - gaugeOption.splitLine.fixRadius + gaugeOption.splitLine.width;
  4901. let childendX = -radius - gaugeOption.width * 0.5 - gaugeOption.splitLine.fixRadius + gaugeOption.splitLine.childWidth;
  4902. context.translate(centerPosition.x, centerPosition.y);
  4903. context.rotate((gaugeOption.startAngle - 1) * Math.PI);
  4904. for (let i = 0; i < gaugeOption.splitLine.splitNumber + 1; i++) {
  4905. context.beginPath();
  4906. context.setStrokeStyle(gaugeOption.splitLine.color);
  4907. context.setLineWidth(2 * opts.pix);
  4908. context.moveTo(startX, 0);
  4909. context.lineTo(endX, 0);
  4910. context.stroke();
  4911. context.rotate(splitAngle * Math.PI);
  4912. }
  4913. context.restore();
  4914. context.save();
  4915. context.translate(centerPosition.x, centerPosition.y);
  4916. context.rotate((gaugeOption.startAngle - 1) * Math.PI);
  4917. for (let i = 0; i < gaugeOption.splitLine.splitNumber * gaugeOption.splitLine.childNumber + 1; i++) {
  4918. context.beginPath();
  4919. context.setStrokeStyle(gaugeOption.splitLine.color);
  4920. context.setLineWidth(1 * opts.pix);
  4921. context.moveTo(startX, 0);
  4922. context.lineTo(childendX, 0);
  4923. context.stroke();
  4924. context.rotate(childAngle * Math.PI);
  4925. }
  4926. context.restore();
  4927. //画指针
  4928. series = getGaugeDataPoints(series, categories, gaugeOption, process);
  4929. for (let i = 0; i < series.length; i++) {
  4930. let eachSeries = series[i];
  4931. context.save();
  4932. context.translate(centerPosition.x, centerPosition.y);
  4933. context.rotate((eachSeries._proportion_ - 1) * Math.PI);
  4934. context.beginPath();
  4935. context.setFillStyle(eachSeries.color);
  4936. context.moveTo(gaugeOption.pointer.width, 0);
  4937. context.lineTo(0, -gaugeOption.pointer.width / 2);
  4938. context.lineTo(-innerRadius, 0);
  4939. context.lineTo(0, gaugeOption.pointer.width / 2);
  4940. context.lineTo(gaugeOption.pointer.width, 0);
  4941. context.closePath();
  4942. context.fill();
  4943. context.beginPath();
  4944. context.setFillStyle('#FFFFFF');
  4945. context.arc(0, 0, gaugeOption.pointer.width / 6, 0, 2 * Math.PI, false);
  4946. context.fill();
  4947. context.restore();
  4948. }
  4949. if (opts.dataLabel !== false) {
  4950. drawGaugeLabel(gaugeOption, radius, centerPosition, opts, config, context);
  4951. }
  4952. }
  4953. //画仪表盘标题,副标题
  4954. drawRingTitle(opts, config, context, centerPosition);
  4955. if (process === 1 && opts.type === 'gauge') {
  4956. opts.extra.gauge.oldAngle = series[0]._proportion_;
  4957. opts.extra.gauge.oldData = series[0].data;
  4958. }
  4959. return {
  4960. center: centerPosition,
  4961. radius: radius,
  4962. innerRadius: innerRadius,
  4963. categories: categories,
  4964. totalAngle: totalAngle
  4965. };
  4966. }
  4967. function drawRadarDataPoints(series, opts, config, context) {
  4968. var process = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : 1;
  4969. var radarOption = assign({}, {
  4970. gridColor: '#cccccc',
  4971. gridType: 'radar',
  4972. gridEval:1,
  4973. axisLabel:false,
  4974. axisLabelTofix:0,
  4975. labelColor:'#666666',
  4976. labelPointShow:false,
  4977. labelPointRadius:3,
  4978. labelPointColor:'#cccccc',
  4979. opacity: 0.2,
  4980. gridCount: 3,
  4981. border:false,
  4982. borderWidth:2,
  4983. linearType: 'none',
  4984. customColor: [],
  4985. }, opts.extra.radar);
  4986. var coordinateAngle = getRadarCoordinateSeries(opts.categories.length);
  4987. var centerPosition = {
  4988. x: opts.area[3] + (opts.width - opts.area[1] - opts.area[3]) / 2,
  4989. y: opts.area[0] + (opts.height - opts.area[0] - opts.area[2]) / 2
  4990. };
  4991. var xr = (opts.width - opts.area[1] - opts.area[3]) / 2
  4992. var yr = (opts.height - opts.area[0] - opts.area[2]) / 2
  4993. var radius = Math.min(xr - (getMaxTextListLength(opts.categories, config.fontSize, context) + config.radarLabelTextMargin), yr - config.radarLabelTextMargin);
  4994. radius -= config.radarLabelTextMargin * opts.pix;
  4995. radius = radius < 10 ? 10 : radius;
  4996. // 画分割线
  4997. context.beginPath();
  4998. context.setLineWidth(1 * opts.pix);
  4999. context.setStrokeStyle(radarOption.gridColor);
  5000. coordinateAngle.forEach(function(angle,index) {
  5001. var pos = convertCoordinateOrigin(radius * Math.cos(angle), radius * Math.sin(angle), centerPosition);
  5002. context.moveTo(centerPosition.x, centerPosition.y);
  5003. if (index % radarOption.gridEval == 0) {
  5004. context.lineTo(pos.x, pos.y);
  5005. }
  5006. });
  5007. context.stroke();
  5008. context.closePath();
  5009. // 画背景网格
  5010. var _loop = function _loop(i) {
  5011. var startPos = {};
  5012. context.beginPath();
  5013. context.setLineWidth(1 * opts.pix);
  5014. context.setStrokeStyle(radarOption.gridColor);
  5015. if (radarOption.gridType == 'radar') {
  5016. coordinateAngle.forEach(function(angle, index) {
  5017. var pos = convertCoordinateOrigin(radius / radarOption.gridCount * i * Math.cos(angle), radius /
  5018. radarOption.gridCount * i * Math.sin(angle), centerPosition);
  5019. if (index === 0) {
  5020. startPos = pos;
  5021. context.moveTo(pos.x, pos.y);
  5022. } else {
  5023. context.lineTo(pos.x, pos.y);
  5024. }
  5025. });
  5026. context.lineTo(startPos.x, startPos.y);
  5027. } else {
  5028. var pos = convertCoordinateOrigin(radius / radarOption.gridCount * i * Math.cos(1.5), radius / radarOption.gridCount * i * Math.sin(1.5), centerPosition);
  5029. context.arc(centerPosition.x, centerPosition.y, centerPosition.y - pos.y, 0, 2 * Math.PI, false);
  5030. }
  5031. context.stroke();
  5032. context.closePath();
  5033. };
  5034. for (var i = 1; i <= radarOption.gridCount; i++) {
  5035. _loop(i);
  5036. }
  5037. radarOption.customColor = fillCustomColor(radarOption.linearType, radarOption.customColor, series, config);
  5038. var radarDataPoints = getRadarDataPoints(coordinateAngle, centerPosition, radius, series, opts, process);
  5039. radarDataPoints.forEach(function(eachSeries, seriesIndex) {
  5040. // 绘制区域数据
  5041. context.beginPath();
  5042. context.setLineWidth(radarOption.borderWidth * opts.pix);
  5043. context.setStrokeStyle(eachSeries.color);
  5044. var fillcolor = hexToRgb(eachSeries.color, radarOption.opacity);
  5045. if (radarOption.linearType == 'custom') {
  5046. var grd;
  5047. if(context.createCircularGradient){
  5048. grd = context.createCircularGradient(centerPosition.x, centerPosition.y, radius)
  5049. }else{
  5050. grd = context.createRadialGradient(centerPosition.x, centerPosition.y, 0,centerPosition.x, centerPosition.y, radius)
  5051. }
  5052. grd.addColorStop(0, hexToRgb(radarOption.customColor[series[seriesIndex].linearIndex], radarOption.opacity))
  5053. grd.addColorStop(1, hexToRgb(eachSeries.color, radarOption.opacity))
  5054. fillcolor = grd
  5055. }
  5056. context.setFillStyle(fillcolor);
  5057. eachSeries.data.forEach(function(item, index) {
  5058. if (index === 0) {
  5059. context.moveTo(item.position.x, item.position.y);
  5060. } else {
  5061. context.lineTo(item.position.x, item.position.y);
  5062. }
  5063. });
  5064. context.closePath();
  5065. context.fill();
  5066. if(radarOption.border === true){
  5067. context.stroke();
  5068. }
  5069. context.closePath();
  5070. if (opts.dataPointShape !== false) {
  5071. var points = eachSeries.data.map(function(item) {
  5072. return item.position;
  5073. });
  5074. drawPointShape(points, eachSeries.color, eachSeries.pointShape, context, opts);
  5075. }
  5076. });
  5077. // 画刻度值
  5078. if(radarOption.axisLabel === true){
  5079. const maxData = Math.max(radarOption.max, Math.max.apply(null, dataCombine(series)));
  5080. const stepLength = radius / radarOption.gridCount;
  5081. const fontSize = opts.fontSize * opts.pix;
  5082. context.setFontSize(fontSize);
  5083. context.setFillStyle(opts.fontColor);
  5084. context.setTextAlign('left');
  5085. for (var i = 0; i < radarOption.gridCount + 1; i++) {
  5086. let label = i * maxData / radarOption.gridCount;
  5087. label = label.toFixed(radarOption.axisLabelTofix);
  5088. context.fillText(String(label), centerPosition.x + 3 * opts.pix, centerPosition.y - i * stepLength + fontSize / 2);
  5089. }
  5090. }
  5091. // draw label text
  5092. drawRadarLabel(coordinateAngle, radius, centerPosition, opts, config, context);
  5093. // draw dataLabel
  5094. if (opts.dataLabel !== false && process === 1) {
  5095. radarDataPoints.forEach(function(eachSeries, seriesIndex) {
  5096. context.beginPath();
  5097. var fontSize = eachSeries.textSize * opts.pix || config.fontSize;
  5098. context.setFontSize(fontSize);
  5099. context.setFillStyle(eachSeries.textColor || opts.fontColor);
  5100. eachSeries.data.forEach(function(item, index) {
  5101. //如果是中心点垂直的上下点位
  5102. if(Math.abs(item.position.x - centerPosition.x)<2){
  5103. //如果在上面
  5104. if(item.position.y < centerPosition.y){
  5105. context.setTextAlign('center');
  5106. context.fillText(item.value, item.position.x, item.position.y - 4);
  5107. }else{
  5108. context.setTextAlign('center');
  5109. context.fillText(item.value, item.position.x, item.position.y + fontSize + 2);
  5110. }
  5111. }else{
  5112. //如果在左侧
  5113. if(item.position.x < centerPosition.x){
  5114. context.setTextAlign('right');
  5115. context.fillText(item.value, item.position.x - 4, item.position.y + fontSize / 2 - 2);
  5116. }else{
  5117. context.setTextAlign('left');
  5118. context.fillText(item.value, item.position.x + 4, item.position.y + fontSize / 2 - 2);
  5119. }
  5120. }
  5121. });
  5122. context.closePath();
  5123. context.stroke();
  5124. });
  5125. context.setTextAlign('left');
  5126. }
  5127. return {
  5128. center: centerPosition,
  5129. radius: radius,
  5130. angleList: coordinateAngle
  5131. };
  5132. }
  5133. // 经纬度转墨卡托
  5134. function lonlat2mercator(longitude, latitude) {
  5135. var mercator = Array(2);
  5136. var x = longitude * 20037508.34 / 180;
  5137. var y = Math.log(Math.tan((90 + latitude) * Math.PI / 360)) / (Math.PI / 180);
  5138. y = y * 20037508.34 / 180;
  5139. mercator[0] = x;
  5140. mercator[1] = y;
  5141. return mercator;
  5142. }
  5143. // 墨卡托转经纬度
  5144. function mercator2lonlat(longitude, latitude) {
  5145. var lonlat = Array(2)
  5146. var x = longitude / 20037508.34 * 180;
  5147. var y = latitude / 20037508.34 * 180;
  5148. y = 180 / Math.PI * (2 * Math.atan(Math.exp(y * Math.PI / 180)) - Math.PI / 2);
  5149. lonlat[0] = x;
  5150. lonlat[1] = y;
  5151. return lonlat;
  5152. }
  5153. function getBoundingBox(data) {
  5154. var bounds = {},coords;
  5155. bounds.xMin = 180;
  5156. bounds.xMax = 0;
  5157. bounds.yMin = 90;
  5158. bounds.yMax = 0
  5159. for (var i = 0; i < data.length; i++) {
  5160. var coorda = data[i].geometry.coordinates
  5161. for (var k = 0; k < coorda.length; k++) {
  5162. coords = coorda[k];
  5163. if (coords.length == 1) {
  5164. coords = coords[0]
  5165. }
  5166. for (var j = 0; j < coords.length; j++) {
  5167. var longitude = coords[j][0];
  5168. var latitude = coords[j][1];
  5169. var point = {
  5170. x: longitude,
  5171. y: latitude
  5172. }
  5173. bounds.xMin = bounds.xMin < point.x ? bounds.xMin : point.x;
  5174. bounds.xMax = bounds.xMax > point.x ? bounds.xMax : point.x;
  5175. bounds.yMin = bounds.yMin < point.y ? bounds.yMin : point.y;
  5176. bounds.yMax = bounds.yMax > point.y ? bounds.yMax : point.y;
  5177. }
  5178. }
  5179. }
  5180. return bounds;
  5181. }
  5182. function coordinateToPoint(latitude, longitude, bounds, scale, xoffset, yoffset) {
  5183. return {
  5184. x: (longitude - bounds.xMin) * scale + xoffset,
  5185. y: (bounds.yMax - latitude) * scale + yoffset
  5186. };
  5187. }
  5188. function pointToCoordinate(pointY, pointX, bounds, scale, xoffset, yoffset) {
  5189. return {
  5190. x: (pointX - xoffset) / scale + bounds.xMin,
  5191. y: bounds.yMax - (pointY - yoffset) / scale
  5192. };
  5193. }
  5194. function isRayIntersectsSegment(poi, s_poi, e_poi) {
  5195. if (s_poi[1] == e_poi[1]) {
  5196. return false;
  5197. }
  5198. if (s_poi[1] > poi[1] && e_poi[1] > poi[1]) {
  5199. return false;
  5200. }
  5201. if (s_poi[1] < poi[1] && e_poi[1] < poi[1]) {
  5202. return false;
  5203. }
  5204. if (s_poi[1] == poi[1] && e_poi[1] > poi[1]) {
  5205. return false;
  5206. }
  5207. if (e_poi[1] == poi[1] && s_poi[1] > poi[1]) {
  5208. return false;
  5209. }
  5210. if (s_poi[0] < poi[0] && e_poi[1] < poi[1]) {
  5211. return false;
  5212. }
  5213. let xseg = e_poi[0] - (e_poi[0] - s_poi[0]) * (e_poi[1] - poi[1]) / (e_poi[1] - s_poi[1]);
  5214. if (xseg < poi[0]) {
  5215. return false;
  5216. } else {
  5217. return true;
  5218. }
  5219. }
  5220. function isPoiWithinPoly(poi, poly, mercator) {
  5221. let sinsc = 0;
  5222. for (let i = 0; i < poly.length; i++) {
  5223. let epoly = poly[i][0];
  5224. if (poly.length == 1) {
  5225. epoly = poly[i][0]
  5226. }
  5227. for (let j = 0; j < epoly.length - 1; j++) {
  5228. let s_poi = epoly[j];
  5229. let e_poi = epoly[j + 1];
  5230. if (mercator) {
  5231. s_poi = lonlat2mercator(epoly[j][0], epoly[j][1]);
  5232. e_poi = lonlat2mercator(epoly[j + 1][0], epoly[j + 1][1]);
  5233. }
  5234. if (isRayIntersectsSegment(poi, s_poi, e_poi)) {
  5235. sinsc += 1;
  5236. }
  5237. }
  5238. }
  5239. if (sinsc % 2 == 1) {
  5240. return true;
  5241. } else {
  5242. return false;
  5243. }
  5244. }
  5245. function drawMapDataPoints(series, opts, config, context) {
  5246. var mapOption = assign({}, {
  5247. border: true,
  5248. mercator: false,
  5249. borderWidth: 1,
  5250. active:true,
  5251. borderColor: '#666666',
  5252. fillOpacity: 0.6,
  5253. activeBorderColor: '#f04864',
  5254. activeFillColor: '#facc14',
  5255. activeFillOpacity: 1
  5256. }, opts.extra.map);
  5257. var coords, point;
  5258. var data = series;
  5259. var bounds = getBoundingBox(data);
  5260. if (mapOption.mercator) {
  5261. var max = lonlat2mercator(bounds.xMax, bounds.yMax)
  5262. var min = lonlat2mercator(bounds.xMin, bounds.yMin)
  5263. bounds.xMax = max[0]
  5264. bounds.yMax = max[1]
  5265. bounds.xMin = min[0]
  5266. bounds.yMin = min[1]
  5267. }
  5268. var xScale = opts.width / Math.abs(bounds.xMax - bounds.xMin);
  5269. var yScale = opts.height / Math.abs(bounds.yMax - bounds.yMin);
  5270. var scale = xScale < yScale ? xScale : yScale;
  5271. var xoffset = opts.width / 2 - Math.abs(bounds.xMax - bounds.xMin) / 2 * scale;
  5272. var yoffset = opts.height / 2 - Math.abs(bounds.yMax - bounds.yMin) / 2 * scale;
  5273. for (var i = 0; i < data.length; i++) {
  5274. context.beginPath();
  5275. context.setLineWidth(mapOption.borderWidth * opts.pix);
  5276. context.setStrokeStyle(mapOption.borderColor);
  5277. context.setFillStyle(hexToRgb(series[i].color, series[i].fillOpacity||mapOption.fillOpacity));
  5278. if (mapOption.active == true && opts.tooltip) {
  5279. if (opts.tooltip.index == i) {
  5280. context.setStrokeStyle(mapOption.activeBorderColor);
  5281. context.setFillStyle(hexToRgb(mapOption.activeFillColor, mapOption.activeFillOpacity));
  5282. }
  5283. }
  5284. var coorda = data[i].geometry.coordinates
  5285. for (var k = 0; k < coorda.length; k++) {
  5286. coords = coorda[k];
  5287. if (coords.length == 1) {
  5288. coords = coords[0]
  5289. }
  5290. for (var j = 0; j < coords.length; j++) {
  5291. var gaosi = Array(2);
  5292. if (mapOption.mercator) {
  5293. gaosi = lonlat2mercator(coords[j][0], coords[j][1])
  5294. } else {
  5295. gaosi = coords[j]
  5296. }
  5297. point = coordinateToPoint(gaosi[1], gaosi[0], bounds, scale, xoffset, yoffset)
  5298. if (j === 0) {
  5299. context.beginPath();
  5300. context.moveTo(point.x, point.y);
  5301. } else {
  5302. context.lineTo(point.x, point.y);
  5303. }
  5304. }
  5305. context.fill();
  5306. if (mapOption.border == true) {
  5307. context.stroke();
  5308. }
  5309. }
  5310. }
  5311. if (opts.dataLabel == true) {
  5312. for (var i = 0; i < data.length; i++) {
  5313. var centerPoint = data[i].properties.centroid;
  5314. if (centerPoint) {
  5315. if (mapOption.mercator) {
  5316. centerPoint = lonlat2mercator(data[i].properties.centroid[0], data[i].properties.centroid[1])
  5317. }
  5318. point = coordinateToPoint(centerPoint[1], centerPoint[0], bounds, scale, xoffset, yoffset);
  5319. let fontSize = data[i].textSize * opts.pix || config.fontSize;
  5320. let fontColor = data[i].textColor || opts.fontColor;
  5321. if(mapOption.active && mapOption.activeTextColor && opts.tooltip && opts.tooltip.index == i){
  5322. fontColor = mapOption.activeTextColor;
  5323. }
  5324. let text = data[i].properties.name;
  5325. context.beginPath();
  5326. context.setFontSize(fontSize)
  5327. context.setFillStyle(fontColor)
  5328. context.fillText(text, point.x - measureText(text, fontSize, context) / 2, point.y + fontSize / 2);
  5329. context.closePath();
  5330. context.stroke();
  5331. }
  5332. }
  5333. }
  5334. opts.chartData.mapData = {
  5335. bounds: bounds,
  5336. scale: scale,
  5337. xoffset: xoffset,
  5338. yoffset: yoffset,
  5339. mercator: mapOption.mercator
  5340. }
  5341. drawToolTipBridge(opts, config, context, 1);
  5342. context.draw();
  5343. }
  5344. function normalInt(min, max, iter) {
  5345. iter = iter == 0 ? 1 : iter;
  5346. var arr = [];
  5347. for (var i = 0; i < iter; i++) {
  5348. arr[i] = Math.random();
  5349. };
  5350. return Math.floor(arr.reduce(function(i, j) {
  5351. return i + j
  5352. }) / iter * (max - min)) + min;
  5353. };
  5354. function collisionNew(area, points, width, height) {
  5355. var isIn = false;
  5356. for (let i = 0; i < points.length; i++) {
  5357. if (points[i].area) {
  5358. if (area[3] < points[i].area[1] || area[0] > points[i].area[2] || area[1] > points[i].area[3] || area[2] < points[i].area[0]) {
  5359. if (area[0] < 0 || area[1] < 0 || area[2] > width || area[3] > height) {
  5360. isIn = true;
  5361. break;
  5362. } else {
  5363. isIn = false;
  5364. }
  5365. } else {
  5366. isIn = true;
  5367. break;
  5368. }
  5369. }
  5370. }
  5371. return isIn;
  5372. };
  5373. function getWordCloudPoint(opts, type, context) {
  5374. let points = opts.series;
  5375. switch (type) {
  5376. case 'normal':
  5377. for (let i = 0; i < points.length; i++) {
  5378. let text = points[i].name;
  5379. let tHeight = points[i].textSize * opts.pix;
  5380. let tWidth = measureText(text, tHeight, context);
  5381. let x, y;
  5382. let area;
  5383. let breaknum = 0;
  5384. while (true) {
  5385. breaknum++;
  5386. x = normalInt(-opts.width / 2, opts.width / 2, 5) - tWidth / 2;
  5387. y = normalInt(-opts.height / 2, opts.height / 2, 5) + tHeight / 2;
  5388. area = [x - 5 + opts.width / 2, y - 5 - tHeight + opts.height / 2, x + tWidth + 5 + opts.width / 2, y + 5 +
  5389. opts.height / 2
  5390. ];
  5391. let isCollision = collisionNew(area, points, opts.width, opts.height);
  5392. if (!isCollision) break;
  5393. if (breaknum == 1000) {
  5394. area = [-100, -100, -100, -100];
  5395. break;
  5396. }
  5397. };
  5398. points[i].area = area;
  5399. }
  5400. break;
  5401. case 'vertical':
  5402. function Spin() {
  5403. //获取均匀随机值,是否旋转,旋转的概率为(1-0.5)
  5404. if (Math.random() > 0.7) {
  5405. return true;
  5406. } else {
  5407. return false
  5408. };
  5409. };
  5410. for (let i = 0; i < points.length; i++) {
  5411. let text = points[i].name;
  5412. let tHeight = points[i].textSize * opts.pix;
  5413. let tWidth = measureText(text, tHeight, context);
  5414. let isSpin = Spin();
  5415. let x, y, area, areav;
  5416. let breaknum = 0;
  5417. while (true) {
  5418. breaknum++;
  5419. let isCollision;
  5420. if (isSpin) {
  5421. x = normalInt(-opts.width / 2, opts.width / 2, 5) - tWidth / 2;
  5422. y = normalInt(-opts.height / 2, opts.height / 2, 5) + tHeight / 2;
  5423. area = [y - 5 - tWidth + opts.width / 2, (-x - 5 + opts.height / 2), y + 5 + opts.width / 2, (-x + tHeight + 5 + opts.height / 2)];
  5424. areav = [opts.width - (opts.width / 2 - opts.height / 2) - (-x + tHeight + 5 + opts.height / 2) - 5, (opts.height / 2 - opts.width / 2) + (y - 5 - tWidth + opts.width / 2) - 5, opts.width - (opts.width / 2 - opts.height / 2) - (-x + tHeight + 5 + opts.height / 2) + tHeight, (opts.height / 2 - opts.width / 2) + (y - 5 - tWidth + opts.width / 2) + tWidth + 5];
  5425. isCollision = collisionNew(areav, points, opts.height, opts.width);
  5426. } else {
  5427. x = normalInt(-opts.width / 2, opts.width / 2, 5) - tWidth / 2;
  5428. y = normalInt(-opts.height / 2, opts.height / 2, 5) + tHeight / 2;
  5429. area = [x - 5 + opts.width / 2, y - 5 - tHeight + opts.height / 2, x + tWidth + 5 + opts.width / 2, y + 5 + opts.height / 2];
  5430. isCollision = collisionNew(area, points, opts.width, opts.height);
  5431. }
  5432. if (!isCollision) break;
  5433. if (breaknum == 1000) {
  5434. area = [-1000, -1000, -1000, -1000];
  5435. break;
  5436. }
  5437. };
  5438. if (isSpin) {
  5439. points[i].area = areav;
  5440. points[i].areav = area;
  5441. } else {
  5442. points[i].area = area;
  5443. }
  5444. points[i].rotate = isSpin;
  5445. };
  5446. break;
  5447. }
  5448. return points;
  5449. }
  5450. function drawWordCloudDataPoints(series, opts, config, context) {
  5451. let process = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : 1;
  5452. let wordOption = assign({}, {
  5453. type: 'normal',
  5454. autoColors: true
  5455. }, opts.extra.word);
  5456. if (!opts.chartData.wordCloudData) {
  5457. opts.chartData.wordCloudData = getWordCloudPoint(opts, wordOption.type, context);
  5458. }
  5459. context.beginPath();
  5460. context.setFillStyle(opts.background);
  5461. context.rect(0, 0, opts.width, opts.height);
  5462. context.fill();
  5463. context.save();
  5464. let points = opts.chartData.wordCloudData;
  5465. context.translate(opts.width / 2, opts.height / 2);
  5466. for (let i = 0; i < points.length; i++) {
  5467. context.save();
  5468. if (points[i].rotate) {
  5469. context.rotate(90 * Math.PI / 180);
  5470. }
  5471. let text = points[i].name;
  5472. let tHeight = points[i].textSize * opts.pix;
  5473. let tWidth = measureText(text, tHeight, context);
  5474. context.beginPath();
  5475. context.setStrokeStyle(points[i].color);
  5476. context.setFillStyle(points[i].color);
  5477. context.setFontSize(tHeight);
  5478. if (points[i].rotate) {
  5479. if (points[i].areav[0] > 0) {
  5480. if (opts.tooltip) {
  5481. if (opts.tooltip.index == i) {
  5482. context.strokeText(text, (points[i].areav[0] + 5 - opts.width / 2) * process - tWidth * (1 - process) / 2, (points[i].areav[1] + 5 + tHeight - opts.height / 2) * process);
  5483. } else {
  5484. context.fillText(text, (points[i].areav[0] + 5 - opts.width / 2) * process - tWidth * (1 - process) / 2, (points[i].areav[1] + 5 + tHeight - opts.height / 2) * process);
  5485. }
  5486. } else {
  5487. context.fillText(text, (points[i].areav[0] + 5 - opts.width / 2) * process - tWidth * (1 - process) / 2, (points[i].areav[1] + 5 + tHeight - opts.height / 2) * process);
  5488. }
  5489. }
  5490. } else {
  5491. if (points[i].area[0] > 0) {
  5492. if (opts.tooltip) {
  5493. if (opts.tooltip.index == i) {
  5494. context.strokeText(text, (points[i].area[0] + 5 - opts.width / 2) * process - tWidth * (1 - process) / 2, (points[i].area[1] + 5 + tHeight - opts.height / 2) * process);
  5495. } else {
  5496. context.fillText(text, (points[i].area[0] + 5 - opts.width / 2) * process - tWidth * (1 - process) / 2, (points[i].area[1] + 5 + tHeight - opts.height / 2) * process);
  5497. }
  5498. } else {
  5499. context.fillText(text, (points[i].area[0] + 5 - opts.width / 2) * process - tWidth * (1 - process) / 2, (points[i].area[1] + 5 + tHeight - opts.height / 2) * process);
  5500. }
  5501. }
  5502. }
  5503. context.stroke();
  5504. context.restore();
  5505. }
  5506. context.restore();
  5507. }
  5508. function drawFunnelDataPoints(series, opts, config, context) {
  5509. let process = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : 1;
  5510. let funnelOption = assign({}, {
  5511. type:'funnel',
  5512. activeWidth: 10,
  5513. activeOpacity: 0.3,
  5514. border: false,
  5515. borderWidth: 2,
  5516. borderColor: '#FFFFFF',
  5517. fillOpacity: 1,
  5518. minSize: 0,
  5519. labelAlign: 'right',
  5520. linearType: 'none',
  5521. customColor: [],
  5522. }, opts.extra.funnel);
  5523. let eachSpacing = (opts.height - opts.area[0] - opts.area[2]) / series.length;
  5524. let centerPosition = {
  5525. x: opts.area[3] + (opts.width - opts.area[1] - opts.area[3]) / 2,
  5526. y: opts.height - opts.area[2]
  5527. };
  5528. let activeWidth = funnelOption.activeWidth * opts.pix;
  5529. let radius = Math.min((opts.width - opts.area[1] - opts.area[3]) / 2 - activeWidth, (opts.height - opts.area[0] - opts.area[2]) / 2 - activeWidth);
  5530. let seriesNew = getFunnelDataPoints(series, radius, funnelOption, eachSpacing, process);
  5531. context.save();
  5532. context.translate(centerPosition.x, centerPosition.y);
  5533. funnelOption.customColor = fillCustomColor(funnelOption.linearType, funnelOption.customColor, series, config);
  5534. if(funnelOption.type == 'pyramid'){
  5535. for (let i = 0; i < seriesNew.length; i++) {
  5536. if (i == seriesNew.length -1) {
  5537. if (opts.tooltip) {
  5538. if (opts.tooltip.index == i) {
  5539. context.beginPath();
  5540. context.setFillStyle(hexToRgb(seriesNew[i].color, funnelOption.activeOpacity));
  5541. context.moveTo(-activeWidth, -eachSpacing);
  5542. context.lineTo(-seriesNew[i].radius - activeWidth, 0);
  5543. context.lineTo(seriesNew[i].radius + activeWidth, 0);
  5544. context.lineTo(activeWidth, -eachSpacing);
  5545. context.lineTo(-activeWidth, -eachSpacing);
  5546. context.closePath();
  5547. context.fill();
  5548. }
  5549. }
  5550. seriesNew[i].funnelArea = [centerPosition.x - seriesNew[i].radius, centerPosition.y - eachSpacing * (i + 1), centerPosition.x + seriesNew[i].radius, centerPosition.y - eachSpacing * i];
  5551. context.beginPath();
  5552. context.setLineWidth(funnelOption.borderWidth * opts.pix);
  5553. context.setStrokeStyle(funnelOption.borderColor);
  5554. var fillColor = hexToRgb(seriesNew[i].color, funnelOption.fillOpacity);
  5555. if (funnelOption.linearType == 'custom') {
  5556. var grd = context.createLinearGradient(seriesNew[i].radius, -eachSpacing, -seriesNew[i].radius, -eachSpacing);
  5557. grd.addColorStop(0, hexToRgb(seriesNew[i].color, funnelOption.fillOpacity));
  5558. grd.addColorStop(0.5, hexToRgb(funnelOption.customColor[seriesNew[i].linearIndex], funnelOption.fillOpacity));
  5559. grd.addColorStop(1, hexToRgb(seriesNew[i].color, funnelOption.fillOpacity));
  5560. fillColor = grd
  5561. }
  5562. context.setFillStyle(fillColor);
  5563. context.moveTo(0, -eachSpacing);
  5564. context.lineTo(-seriesNew[i].radius, 0);
  5565. context.lineTo(seriesNew[i].radius, 0);
  5566. context.lineTo(0, -eachSpacing);
  5567. context.closePath();
  5568. context.fill();
  5569. if (funnelOption.border == true) {
  5570. context.stroke();
  5571. }
  5572. } else {
  5573. if (opts.tooltip) {
  5574. if (opts.tooltip.index == i) {
  5575. context.beginPath();
  5576. context.setFillStyle(hexToRgb(seriesNew[i].color, funnelOption.activeOpacity));
  5577. context.moveTo(0, 0);
  5578. context.lineTo(-seriesNew[i].radius - activeWidth, 0);
  5579. context.lineTo(-seriesNew[i + 1].radius - activeWidth, -eachSpacing);
  5580. context.lineTo(seriesNew[i + 1].radius + activeWidth, -eachSpacing);
  5581. context.lineTo(seriesNew[i].radius + activeWidth, 0);
  5582. context.lineTo(0, 0);
  5583. context.closePath();
  5584. context.fill();
  5585. }
  5586. }
  5587. seriesNew[i].funnelArea = [centerPosition.x - seriesNew[i].radius, centerPosition.y - eachSpacing * (i + 1), centerPosition.x + seriesNew[i].radius, centerPosition.y - eachSpacing * i];
  5588. context.beginPath();
  5589. context.setLineWidth(funnelOption.borderWidth * opts.pix);
  5590. context.setStrokeStyle(funnelOption.borderColor);
  5591. var fillColor = hexToRgb(seriesNew[i].color, funnelOption.fillOpacity);
  5592. if (funnelOption.linearType == 'custom') {
  5593. var grd = context.createLinearGradient(seriesNew[i].radius, -eachSpacing, -seriesNew[i].radius, -eachSpacing);
  5594. grd.addColorStop(0, hexToRgb(seriesNew[i].color, funnelOption.fillOpacity));
  5595. grd.addColorStop(0.5, hexToRgb(funnelOption.customColor[seriesNew[i].linearIndex], funnelOption.fillOpacity));
  5596. grd.addColorStop(1, hexToRgb(seriesNew[i].color, funnelOption.fillOpacity));
  5597. fillColor = grd
  5598. }
  5599. context.setFillStyle(fillColor);
  5600. context.moveTo(0, 0);
  5601. context.lineTo(-seriesNew[i].radius, 0);
  5602. context.lineTo(-seriesNew[i + 1].radius, -eachSpacing);
  5603. context.lineTo(seriesNew[i + 1].radius, -eachSpacing);
  5604. context.lineTo(seriesNew[i].radius, 0);
  5605. context.lineTo(0, 0);
  5606. context.closePath();
  5607. context.fill();
  5608. if (funnelOption.border == true) {
  5609. context.stroke();
  5610. }
  5611. }
  5612. context.translate(0, -eachSpacing)
  5613. }
  5614. }else{
  5615. context.translate(0, - (seriesNew.length - 1) * eachSpacing);
  5616. for (let i = 0; i < seriesNew.length; i++) {
  5617. if (i == seriesNew.length - 1) {
  5618. if (opts.tooltip) {
  5619. if (opts.tooltip.index == i) {
  5620. context.beginPath();
  5621. context.setFillStyle(hexToRgb(seriesNew[i].color, funnelOption.activeOpacity));
  5622. context.moveTo(-activeWidth - funnelOption.minSize/2, 0);
  5623. context.lineTo(-seriesNew[i].radius - activeWidth, -eachSpacing);
  5624. context.lineTo(seriesNew[i].radius + activeWidth, -eachSpacing);
  5625. context.lineTo(activeWidth + funnelOption.minSize/2, 0);
  5626. context.lineTo(-activeWidth - funnelOption.minSize/2, 0);
  5627. context.closePath();
  5628. context.fill();
  5629. }
  5630. }
  5631. seriesNew[i].funnelArea = [centerPosition.x - seriesNew[i].radius, centerPosition.y - eachSpacing, centerPosition.x + seriesNew[i].radius, centerPosition.y ];
  5632. context.beginPath();
  5633. context.setLineWidth(funnelOption.borderWidth * opts.pix);
  5634. context.setStrokeStyle(funnelOption.borderColor);
  5635. var fillColor = hexToRgb(seriesNew[i].color, funnelOption.fillOpacity);
  5636. if (funnelOption.linearType == 'custom') {
  5637. var grd = context.createLinearGradient(seriesNew[i].radius, -eachSpacing, -seriesNew[i].radius, -eachSpacing);
  5638. grd.addColorStop(0, hexToRgb(seriesNew[i].color, funnelOption.fillOpacity));
  5639. grd.addColorStop(0.5, hexToRgb(funnelOption.customColor[seriesNew[i].linearIndex], funnelOption.fillOpacity));
  5640. grd.addColorStop(1, hexToRgb(seriesNew[i].color, funnelOption.fillOpacity));
  5641. fillColor = grd
  5642. }
  5643. context.setFillStyle(fillColor);
  5644. context.moveTo(0, 0);
  5645. context.lineTo(-funnelOption.minSize/2, 0);
  5646. context.lineTo(-seriesNew[i].radius, -eachSpacing);
  5647. context.lineTo(seriesNew[i].radius, -eachSpacing);
  5648. context.lineTo(funnelOption.minSize/2, 0);
  5649. context.lineTo(0, 0);
  5650. context.closePath();
  5651. context.fill();
  5652. if (funnelOption.border == true) {
  5653. context.stroke();
  5654. }
  5655. } else {
  5656. if (opts.tooltip) {
  5657. if (opts.tooltip.index == i) {
  5658. context.beginPath();
  5659. context.setFillStyle(hexToRgb(seriesNew[i].color, funnelOption.activeOpacity));
  5660. context.moveTo(0, 0);
  5661. context.lineTo(-seriesNew[i + 1].radius - activeWidth, 0);
  5662. context.lineTo(-seriesNew[i].radius - activeWidth, -eachSpacing);
  5663. context.lineTo(seriesNew[i].radius + activeWidth, -eachSpacing);
  5664. context.lineTo(seriesNew[i + 1].radius + activeWidth, 0);
  5665. context.lineTo(0, 0);
  5666. context.closePath();
  5667. context.fill();
  5668. }
  5669. }
  5670. seriesNew[i].funnelArea = [centerPosition.x - seriesNew[i].radius, centerPosition.y - eachSpacing * (seriesNew.length - i), centerPosition.x + seriesNew[i].radius, centerPosition.y - eachSpacing * (seriesNew.length - i - 1)];
  5671. context.beginPath();
  5672. context.setLineWidth(funnelOption.borderWidth * opts.pix);
  5673. context.setStrokeStyle(funnelOption.borderColor);
  5674. var fillColor = hexToRgb(seriesNew[i].color, funnelOption.fillOpacity);
  5675. if (funnelOption.linearType == 'custom') {
  5676. var grd = context.createLinearGradient(seriesNew[i].radius, -eachSpacing, -seriesNew[i].radius, -eachSpacing);
  5677. grd.addColorStop(0, hexToRgb(seriesNew[i].color, funnelOption.fillOpacity));
  5678. grd.addColorStop(0.5, hexToRgb(funnelOption.customColor[seriesNew[i].linearIndex], funnelOption.fillOpacity));
  5679. grd.addColorStop(1, hexToRgb(seriesNew[i].color, funnelOption.fillOpacity));
  5680. fillColor = grd
  5681. }
  5682. context.setFillStyle(fillColor);
  5683. context.moveTo(0, 0);
  5684. context.lineTo(-seriesNew[i + 1].radius, 0);
  5685. context.lineTo(-seriesNew[i].radius, -eachSpacing);
  5686. context.lineTo(seriesNew[i].radius, -eachSpacing);
  5687. context.lineTo(seriesNew[i + 1].radius, 0);
  5688. context.lineTo(0, 0);
  5689. context.closePath();
  5690. context.fill();
  5691. if (funnelOption.border == true) {
  5692. context.stroke();
  5693. }
  5694. }
  5695. context.translate(0, eachSpacing)
  5696. }
  5697. }
  5698. context.restore();
  5699. if (opts.dataLabel !== false && process === 1) {
  5700. drawFunnelText(seriesNew, opts, context, eachSpacing, funnelOption.labelAlign, activeWidth, centerPosition);
  5701. }
  5702. if (process === 1) {
  5703. drawFunnelCenterText(seriesNew, opts, context, eachSpacing, funnelOption.labelAlign, activeWidth, centerPosition);
  5704. }
  5705. return {
  5706. center: centerPosition,
  5707. radius: radius,
  5708. series: seriesNew
  5709. };
  5710. }
  5711. function drawFunnelText(series, opts, context, eachSpacing, labelAlign, activeWidth, centerPosition) {
  5712. for (let i = 0; i < series.length; i++) {
  5713. let item = series[i];
  5714. if(item.labelShow === false){
  5715. continue;
  5716. }
  5717. let startX, endX, startY, fontSize;
  5718. let text = item.formatter ? item.formatter(item,i,series,opts) : util.toFixed(item._proportion_ * 100) + '%';
  5719. text = item.labelText ? item.labelText : text;
  5720. if (labelAlign == 'right') {
  5721. if (i == series.length -1) {
  5722. startX = (item.funnelArea[2] + centerPosition.x) / 2;
  5723. } else {
  5724. startX = (item.funnelArea[2] + series[i + 1].funnelArea[2]) / 2;
  5725. }
  5726. endX = startX + activeWidth * 2;
  5727. startY = item.funnelArea[1] + eachSpacing / 2;
  5728. fontSize = item.textSize * opts.pix || opts.fontSize * opts.pix;
  5729. context.setLineWidth(1 * opts.pix);
  5730. context.setStrokeStyle(item.color);
  5731. context.setFillStyle(item.color);
  5732. context.beginPath();
  5733. context.moveTo(startX, startY);
  5734. context.lineTo(endX, startY);
  5735. context.stroke();
  5736. context.closePath();
  5737. context.beginPath();
  5738. context.moveTo(endX, startY);
  5739. context.arc(endX, startY, 2 * opts.pix, 0, 2 * Math.PI);
  5740. context.closePath();
  5741. context.fill();
  5742. context.beginPath();
  5743. context.setFontSize(fontSize);
  5744. context.setFillStyle(item.textColor || opts.fontColor);
  5745. context.fillText(text, endX + 5, startY + fontSize / 2 - 2);
  5746. context.closePath();
  5747. context.stroke();
  5748. context.closePath();
  5749. }
  5750. if (labelAlign == 'left') {
  5751. if (i == series.length -1) {
  5752. startX = (item.funnelArea[0] + centerPosition.x) / 2;
  5753. } else {
  5754. startX = (item.funnelArea[0] + series[i + 1].funnelArea[0]) / 2;
  5755. }
  5756. endX = startX - activeWidth * 2;
  5757. startY = item.funnelArea[1] + eachSpacing / 2;
  5758. fontSize = item.textSize * opts.pix || opts.fontSize * opts.pix;
  5759. context.setLineWidth(1 * opts.pix);
  5760. context.setStrokeStyle(item.color);
  5761. context.setFillStyle(item.color);
  5762. context.beginPath();
  5763. context.moveTo(startX, startY);
  5764. context.lineTo(endX, startY);
  5765. context.stroke();
  5766. context.closePath();
  5767. context.beginPath();
  5768. context.moveTo(endX, startY);
  5769. context.arc(endX, startY, 2, 0, 2 * Math.PI);
  5770. context.closePath();
  5771. context.fill();
  5772. context.beginPath();
  5773. context.setFontSize(fontSize);
  5774. context.setFillStyle(item.textColor || opts.fontColor);
  5775. context.fillText(text, endX - 5 - measureText(text, fontSize, context), startY + fontSize / 2 - 2);
  5776. context.closePath();
  5777. context.stroke();
  5778. context.closePath();
  5779. }
  5780. }
  5781. }
  5782. function drawFunnelCenterText(series, opts, context, eachSpacing, labelAlign, activeWidth, centerPosition) {
  5783. for (let i = 0; i < series.length; i++) {
  5784. let item = series[i];
  5785. let startY, fontSize;
  5786. if (item.centerText) {
  5787. startY = item.funnelArea[1] + eachSpacing / 2;
  5788. fontSize = item.centerTextSize * opts.pix || opts.fontSize * opts.pix;
  5789. context.beginPath();
  5790. context.setFontSize(fontSize);
  5791. context.setFillStyle(item.centerTextColor || "#FFFFFF");
  5792. context.fillText(item.centerText, centerPosition.x - measureText(item.centerText, fontSize, context) / 2, startY + fontSize / 2 - 2);
  5793. context.closePath();
  5794. context.stroke();
  5795. context.closePath();
  5796. }
  5797. }
  5798. }
  5799. function drawCanvas(opts, context) {
  5800. context.draw();
  5801. }
  5802. var Timing = {
  5803. easeIn: function easeIn(pos) {
  5804. return Math.pow(pos, 3);
  5805. },
  5806. easeOut: function easeOut(pos) {
  5807. return Math.pow(pos - 1, 3) + 1;
  5808. },
  5809. easeInOut: function easeInOut(pos) {
  5810. if ((pos /= 0.5) < 1) {
  5811. return 0.5 * Math.pow(pos, 3);
  5812. } else {
  5813. return 0.5 * (Math.pow(pos - 2, 3) + 2);
  5814. }
  5815. },
  5816. linear: function linear(pos) {
  5817. return pos;
  5818. }
  5819. };
  5820. function Animation(opts) {
  5821. this.isStop = false;
  5822. opts.duration = typeof opts.duration === 'undefined' ? 1000 : opts.duration;
  5823. opts.timing = opts.timing || 'easeInOut';
  5824. var delay = 17;
  5825. function createAnimationFrame() {
  5826. if (typeof setTimeout !== 'undefined') {
  5827. return function(step, delay) {
  5828. setTimeout(function() {
  5829. var timeStamp = +new Date();
  5830. step(timeStamp);
  5831. }, delay);
  5832. };
  5833. } else if (typeof requestAnimationFrame !== 'undefined') {
  5834. return requestAnimationFrame;
  5835. } else {
  5836. return function(step) {
  5837. step(null);
  5838. };
  5839. }
  5840. };
  5841. var animationFrame = createAnimationFrame();
  5842. var startTimeStamp = null;
  5843. var _step = function step(timestamp) {
  5844. if (timestamp === null || this.isStop === true) {
  5845. opts.onProcess && opts.onProcess(1);
  5846. opts.onAnimationFinish && opts.onAnimationFinish();
  5847. return;
  5848. }
  5849. if (startTimeStamp === null) {
  5850. startTimeStamp = timestamp;
  5851. }
  5852. if (timestamp - startTimeStamp < opts.duration) {
  5853. var process = (timestamp - startTimeStamp) / opts.duration;
  5854. var timingFunction = Timing[opts.timing];
  5855. process = timingFunction(process);
  5856. opts.onProcess && opts.onProcess(process);
  5857. animationFrame(_step, delay);
  5858. } else {
  5859. opts.onProcess && opts.onProcess(1);
  5860. opts.onAnimationFinish && opts.onAnimationFinish();
  5861. }
  5862. };
  5863. _step = _step.bind(this);
  5864. animationFrame(_step, delay);
  5865. }
  5866. Animation.prototype.stop = function() {
  5867. this.isStop = true;
  5868. };
  5869. function drawCharts(type, opts, config, context) {
  5870. var _this = this;
  5871. var series = opts.series;
  5872. //兼容ECharts饼图类数据格式
  5873. if (type === 'pie' || type === 'ring' || type === 'mount' || type === 'rose' || type === 'funnel') {
  5874. series = fixPieSeries(series, opts, config);
  5875. }
  5876. var categories = opts.categories;
  5877. if (type === 'mount') {
  5878. categories = [];
  5879. for (let j = 0; j < series.length; j++) {
  5880. if(series[j].show !== false) categories.push(series[j].name)
  5881. }
  5882. opts.categories = categories;
  5883. }
  5884. series = fillSeries(series, opts, config);
  5885. var duration = opts.animation ? opts.duration : 0;
  5886. _this.animationInstance && _this.animationInstance.stop();
  5887. var seriesMA = null;
  5888. if (type == 'candle') {
  5889. let average = assign({}, opts.extra.candle.average);
  5890. if (average.show) {
  5891. seriesMA = calCandleMA(average.day, average.name, average.color, series[0].data);
  5892. seriesMA = fillSeries(seriesMA, opts, config);
  5893. opts.seriesMA = seriesMA;
  5894. } else if (opts.seriesMA) {
  5895. seriesMA = opts.seriesMA = fillSeries(opts.seriesMA, opts, config);
  5896. } else {
  5897. seriesMA = series;
  5898. }
  5899. } else {
  5900. seriesMA = series;
  5901. }
  5902. /* 过滤掉show=false的series */
  5903. opts._series_ = series = filterSeries(series);
  5904. //重新计算图表区域
  5905. opts.area = new Array(4);
  5906. //复位绘图区域
  5907. for (let j = 0; j < 4; j++) {
  5908. opts.area[j] = opts.padding[j] * opts.pix;
  5909. }
  5910. //通过计算三大区域:图例、X轴、Y轴的大小,确定绘图区域
  5911. var _calLegendData = calLegendData(seriesMA, opts, config, opts.chartData, context),
  5912. legendHeight = _calLegendData.area.wholeHeight,
  5913. legendWidth = _calLegendData.area.wholeWidth;
  5914. switch (opts.legend.position) {
  5915. case 'top':
  5916. opts.area[0] += legendHeight;
  5917. break;
  5918. case 'bottom':
  5919. opts.area[2] += legendHeight;
  5920. break;
  5921. case 'left':
  5922. opts.area[3] += legendWidth;
  5923. break;
  5924. case 'right':
  5925. opts.area[1] += legendWidth;
  5926. break;
  5927. }
  5928. let _calYAxisData = {},
  5929. yAxisWidth = 0;
  5930. if (opts.type === 'line' || opts.type === 'column'|| opts.type === 'mount' || opts.type === 'area' || opts.type === 'mix' || opts.type === 'candle' || opts.type === 'scatter' || opts.type === 'bubble' || opts.type === 'bar') {
  5931. _calYAxisData = calYAxisData(series, opts, config, context);
  5932. yAxisWidth = _calYAxisData.yAxisWidth;
  5933. //如果显示Y轴标题
  5934. if (opts.yAxis.showTitle) {
  5935. let maxTitleHeight = 0;
  5936. for (let i = 0; i < opts.yAxis.data.length; i++) {
  5937. maxTitleHeight = Math.max(maxTitleHeight, opts.yAxis.data[i].titleFontSize ? opts.yAxis.data[i].titleFontSize * opts.pix : config.fontSize)
  5938. }
  5939. opts.area[0] += maxTitleHeight;
  5940. }
  5941. let rightIndex = 0,
  5942. leftIndex = 0;
  5943. //计算主绘图区域左右位置
  5944. for (let i = 0; i < yAxisWidth.length; i++) {
  5945. if (yAxisWidth[i].position == 'left') {
  5946. if (leftIndex > 0) {
  5947. opts.area[3] += yAxisWidth[i].width + opts.yAxis.padding * opts.pix;
  5948. } else {
  5949. opts.area[3] += yAxisWidth[i].width;
  5950. }
  5951. leftIndex += 1;
  5952. } else if (yAxisWidth[i].position == 'right') {
  5953. if (rightIndex > 0) {
  5954. opts.area[1] += yAxisWidth[i].width + opts.yAxis.padding * opts.pix;
  5955. } else {
  5956. opts.area[1] += yAxisWidth[i].width;
  5957. }
  5958. rightIndex += 1;
  5959. }
  5960. }
  5961. } else {
  5962. config.yAxisWidth = yAxisWidth;
  5963. }
  5964. opts.chartData.yAxisData = _calYAxisData;
  5965. if (opts.categories && opts.categories.length && opts.type !== 'radar' && opts.type !== 'gauge' && opts.type !== 'bar') {
  5966. opts.chartData.xAxisData = getXAxisPoints(opts.categories, opts, config);
  5967. let _calCategoriesData = calCategoriesData(opts.categories, opts, config, opts.chartData.xAxisData.eachSpacing, context),
  5968. xAxisHeight = _calCategoriesData.xAxisHeight,
  5969. angle = _calCategoriesData.angle;
  5970. config.xAxisHeight = xAxisHeight;
  5971. config._xAxisTextAngle_ = angle;
  5972. opts.area[2] += xAxisHeight;
  5973. opts.chartData.categoriesData = _calCategoriesData;
  5974. } else {
  5975. if (opts.type === 'line' || opts.type === 'area' || opts.type === 'scatter' || opts.type === 'bubble' || opts.type === 'bar') {
  5976. opts.chartData.xAxisData = calXAxisData(series, opts, config, context);
  5977. categories = opts.chartData.xAxisData.rangesFormat;
  5978. let _calCategoriesData = calCategoriesData(categories, opts, config, opts.chartData.xAxisData.eachSpacing, context),
  5979. xAxisHeight = _calCategoriesData.xAxisHeight,
  5980. angle = _calCategoriesData.angle;
  5981. config.xAxisHeight = xAxisHeight;
  5982. config._xAxisTextAngle_ = angle;
  5983. opts.area[2] += xAxisHeight;
  5984. opts.chartData.categoriesData = _calCategoriesData;
  5985. } else {
  5986. opts.chartData.xAxisData = {
  5987. xAxisPoints: []
  5988. };
  5989. }
  5990. }
  5991. //计算右对齐偏移距离
  5992. if (opts.enableScroll && opts.xAxis.scrollAlign == 'right' && opts._scrollDistance_ === undefined) {
  5993. let offsetLeft = 0,
  5994. xAxisPoints = opts.chartData.xAxisData.xAxisPoints,
  5995. startX = opts.chartData.xAxisData.startX,
  5996. endX = opts.chartData.xAxisData.endX,
  5997. eachSpacing = opts.chartData.xAxisData.eachSpacing;
  5998. let totalWidth = eachSpacing * (xAxisPoints.length - 1);
  5999. let screenWidth = endX - startX;
  6000. offsetLeft = screenWidth - totalWidth;
  6001. _this.scrollOption.currentOffset = offsetLeft;
  6002. _this.scrollOption.startTouchX = offsetLeft;
  6003. _this.scrollOption.distance = 0;
  6004. _this.scrollOption.lastMoveTime = 0;
  6005. opts._scrollDistance_ = offsetLeft;
  6006. }
  6007. if (type === 'pie' || type === 'ring' || type === 'rose') {
  6008. config._pieTextMaxLength_ = opts.dataLabel === false ? 0 : getPieTextMaxLength(seriesMA, config, context, opts);
  6009. }
  6010. switch (type) {
  6011. case 'word':
  6012. this.animationInstance = new Animation({
  6013. timing: opts.timing,
  6014. duration: duration,
  6015. onProcess: function(process) {
  6016. context.clearRect(0, 0, opts.width, opts.height);
  6017. if (opts.rotate) {
  6018. contextRotate(context, opts);
  6019. }
  6020. drawWordCloudDataPoints(series, opts, config, context, process);
  6021. drawCanvas(opts, context);
  6022. },
  6023. onAnimationFinish: function onAnimationFinish() {
  6024. _this.uevent.trigger('renderComplete');
  6025. }
  6026. });
  6027. break;
  6028. case 'map':
  6029. context.clearRect(0, 0, opts.width, opts.height);
  6030. drawMapDataPoints(series, opts, config, context);
  6031. setTimeout(()=>{
  6032. this.uevent.trigger('renderComplete');
  6033. },50)
  6034. break;
  6035. case 'funnel':
  6036. this.animationInstance = new Animation({
  6037. timing: opts.timing,
  6038. duration: duration,
  6039. onProcess: function(process) {
  6040. context.clearRect(0, 0, opts.width, opts.height);
  6041. if (opts.rotate) {
  6042. contextRotate(context, opts);
  6043. }
  6044. opts.chartData.funnelData = drawFunnelDataPoints(series, opts, config, context, process);
  6045. drawLegend(opts.series, opts, config, context, opts.chartData);
  6046. drawToolTipBridge(opts, config, context, process);
  6047. drawCanvas(opts, context);
  6048. },
  6049. onAnimationFinish: function onAnimationFinish() {
  6050. _this.uevent.trigger('renderComplete');
  6051. }
  6052. });
  6053. break;
  6054. case 'line':
  6055. this.animationInstance = new Animation({
  6056. timing: opts.timing,
  6057. duration: duration,
  6058. onProcess: function onProcess(process) {
  6059. context.clearRect(0, 0, opts.width, opts.height);
  6060. if (opts.rotate) {
  6061. contextRotate(context, opts);
  6062. }
  6063. drawYAxisGrid(categories, opts, config, context);
  6064. drawXAxis(categories, opts, config, context);
  6065. var _drawLineDataPoints = drawLineDataPoints(series, opts, config, context, process),
  6066. xAxisPoints = _drawLineDataPoints.xAxisPoints,
  6067. calPoints = _drawLineDataPoints.calPoints,
  6068. eachSpacing = _drawLineDataPoints.eachSpacing;
  6069. opts.chartData.xAxisPoints = xAxisPoints;
  6070. opts.chartData.calPoints = calPoints;
  6071. opts.chartData.eachSpacing = eachSpacing;
  6072. drawYAxis(series, opts, config, context);
  6073. if (opts.enableMarkLine !== false && process === 1) {
  6074. drawMarkLine(opts, config, context);
  6075. }
  6076. drawLegend(opts.series, opts, config, context, opts.chartData);
  6077. drawToolTipBridge(opts, config, context, process, eachSpacing, xAxisPoints);
  6078. drawCanvas(opts, context);
  6079. },
  6080. onAnimationFinish: function onAnimationFinish() {
  6081. _this.uevent.trigger('renderComplete');
  6082. }
  6083. });
  6084. break;
  6085. case 'scatter':
  6086. this.animationInstance = new Animation({
  6087. timing: opts.timing,
  6088. duration: duration,
  6089. onProcess: function onProcess(process) {
  6090. context.clearRect(0, 0, opts.width, opts.height);
  6091. if (opts.rotate) {
  6092. contextRotate(context, opts);
  6093. }
  6094. drawYAxisGrid(categories, opts, config, context);
  6095. drawXAxis(categories, opts, config, context);
  6096. var _drawScatterDataPoints = drawScatterDataPoints(series, opts, config, context, process),
  6097. xAxisPoints = _drawScatterDataPoints.xAxisPoints,
  6098. calPoints = _drawScatterDataPoints.calPoints,
  6099. eachSpacing = _drawScatterDataPoints.eachSpacing;
  6100. opts.chartData.xAxisPoints = xAxisPoints;
  6101. opts.chartData.calPoints = calPoints;
  6102. opts.chartData.eachSpacing = eachSpacing;
  6103. drawYAxis(series, opts, config, context);
  6104. if (opts.enableMarkLine !== false && process === 1) {
  6105. drawMarkLine(opts, config, context);
  6106. }
  6107. drawLegend(opts.series, opts, config, context, opts.chartData);
  6108. drawToolTipBridge(opts, config, context, process, eachSpacing, xAxisPoints);
  6109. drawCanvas(opts, context);
  6110. },
  6111. onAnimationFinish: function onAnimationFinish() {
  6112. _this.uevent.trigger('renderComplete');
  6113. }
  6114. });
  6115. break;
  6116. case 'bubble':
  6117. this.animationInstance = new Animation({
  6118. timing: opts.timing,
  6119. duration: duration,
  6120. onProcess: function onProcess(process) {
  6121. context.clearRect(0, 0, opts.width, opts.height);
  6122. if (opts.rotate) {
  6123. contextRotate(context, opts);
  6124. }
  6125. drawYAxisGrid(categories, opts, config, context);
  6126. drawXAxis(categories, opts, config, context);
  6127. var _drawBubbleDataPoints = drawBubbleDataPoints(series, opts, config, context, process),
  6128. xAxisPoints = _drawBubbleDataPoints.xAxisPoints,
  6129. calPoints = _drawBubbleDataPoints.calPoints,
  6130. eachSpacing = _drawBubbleDataPoints.eachSpacing;
  6131. opts.chartData.xAxisPoints = xAxisPoints;
  6132. opts.chartData.calPoints = calPoints;
  6133. opts.chartData.eachSpacing = eachSpacing;
  6134. drawYAxis(series, opts, config, context);
  6135. if (opts.enableMarkLine !== false && process === 1) {
  6136. drawMarkLine(opts, config, context);
  6137. }
  6138. drawLegend(opts.series, opts, config, context, opts.chartData);
  6139. drawToolTipBridge(opts, config, context, process, eachSpacing, xAxisPoints);
  6140. drawCanvas(opts, context);
  6141. },
  6142. onAnimationFinish: function onAnimationFinish() {
  6143. _this.uevent.trigger('renderComplete');
  6144. }
  6145. });
  6146. break;
  6147. case 'mix':
  6148. this.animationInstance = new Animation({
  6149. timing: opts.timing,
  6150. duration: duration,
  6151. onProcess: function onProcess(process) {
  6152. context.clearRect(0, 0, opts.width, opts.height);
  6153. if (opts.rotate) {
  6154. contextRotate(context, opts);
  6155. }
  6156. drawYAxisGrid(categories, opts, config, context);
  6157. drawXAxis(categories, opts, config, context);
  6158. var _drawMixDataPoints = drawMixDataPoints(series, opts, config, context, process),
  6159. xAxisPoints = _drawMixDataPoints.xAxisPoints,
  6160. calPoints = _drawMixDataPoints.calPoints,
  6161. eachSpacing = _drawMixDataPoints.eachSpacing;
  6162. opts.chartData.xAxisPoints = xAxisPoints;
  6163. opts.chartData.calPoints = calPoints;
  6164. opts.chartData.eachSpacing = eachSpacing;
  6165. drawYAxis(series, opts, config, context);
  6166. if (opts.enableMarkLine !== false && process === 1) {
  6167. drawMarkLine(opts, config, context);
  6168. }
  6169. drawLegend(opts.series, opts, config, context, opts.chartData);
  6170. drawToolTipBridge(opts, config, context, process, eachSpacing, xAxisPoints);
  6171. drawCanvas(opts, context);
  6172. },
  6173. onAnimationFinish: function onAnimationFinish() {
  6174. _this.uevent.trigger('renderComplete');
  6175. }
  6176. });
  6177. break;
  6178. case 'column':
  6179. this.animationInstance = new Animation({
  6180. timing: opts.timing,
  6181. duration: duration,
  6182. onProcess: function onProcess(process) {
  6183. context.clearRect(0, 0, opts.width, opts.height);
  6184. if (opts.rotate) {
  6185. contextRotate(context, opts);
  6186. }
  6187. drawYAxisGrid(categories, opts, config, context);
  6188. drawXAxis(categories, opts, config, context);
  6189. var _drawColumnDataPoints = drawColumnDataPoints(series, opts, config, context, process),
  6190. xAxisPoints = _drawColumnDataPoints.xAxisPoints,
  6191. calPoints = _drawColumnDataPoints.calPoints,
  6192. eachSpacing = _drawColumnDataPoints.eachSpacing;
  6193. opts.chartData.xAxisPoints = xAxisPoints;
  6194. opts.chartData.calPoints = calPoints;
  6195. opts.chartData.eachSpacing = eachSpacing;
  6196. drawYAxis(series, opts, config, context);
  6197. if (opts.enableMarkLine !== false && process === 1) {
  6198. drawMarkLine(opts, config, context);
  6199. }
  6200. drawLegend(opts.series, opts, config, context, opts.chartData);
  6201. drawToolTipBridge(opts, config, context, process, eachSpacing, xAxisPoints);
  6202. drawCanvas(opts, context);
  6203. },
  6204. onAnimationFinish: function onAnimationFinish() {
  6205. _this.uevent.trigger('renderComplete');
  6206. }
  6207. });
  6208. break;
  6209. case 'mount':
  6210. this.animationInstance = new Animation({
  6211. timing: opts.timing,
  6212. duration: duration,
  6213. onProcess: function onProcess(process) {
  6214. context.clearRect(0, 0, opts.width, opts.height);
  6215. if (opts.rotate) {
  6216. contextRotate(context, opts);
  6217. }
  6218. drawYAxisGrid(categories, opts, config, context);
  6219. drawXAxis(categories, opts, config, context);
  6220. var _drawMountDataPoints = drawMountDataPoints(series, opts, config, context, process),
  6221. xAxisPoints = _drawMountDataPoints.xAxisPoints,
  6222. calPoints = _drawMountDataPoints.calPoints,
  6223. eachSpacing = _drawMountDataPoints.eachSpacing;
  6224. opts.chartData.xAxisPoints = xAxisPoints;
  6225. opts.chartData.calPoints = calPoints;
  6226. opts.chartData.eachSpacing = eachSpacing;
  6227. drawYAxis(series, opts, config, context);
  6228. if (opts.enableMarkLine !== false && process === 1) {
  6229. drawMarkLine(opts, config, context);
  6230. }
  6231. drawLegend(opts.series, opts, config, context, opts.chartData);
  6232. drawToolTipBridge(opts, config, context, process, eachSpacing, xAxisPoints);
  6233. drawCanvas(opts, context);
  6234. },
  6235. onAnimationFinish: function onAnimationFinish() {
  6236. _this.uevent.trigger('renderComplete');
  6237. }
  6238. });
  6239. break;
  6240. case 'bar':
  6241. this.animationInstance = new Animation({
  6242. timing: opts.timing,
  6243. duration: duration,
  6244. onProcess: function onProcess(process) {
  6245. context.clearRect(0, 0, opts.width, opts.height);
  6246. if (opts.rotate) {
  6247. contextRotate(context, opts);
  6248. }
  6249. drawXAxis(categories, opts, config, context);
  6250. var _drawBarDataPoints = drawBarDataPoints(series, opts, config, context, process),
  6251. yAxisPoints = _drawBarDataPoints.yAxisPoints,
  6252. calPoints = _drawBarDataPoints.calPoints,
  6253. eachSpacing = _drawBarDataPoints.eachSpacing;
  6254. opts.chartData.yAxisPoints = yAxisPoints;
  6255. opts.chartData.xAxisPoints = opts.chartData.xAxisData.xAxisPoints;
  6256. opts.chartData.calPoints = calPoints;
  6257. opts.chartData.eachSpacing = eachSpacing;
  6258. drawYAxis(series, opts, config, context);
  6259. if (opts.enableMarkLine !== false && process === 1) {
  6260. drawMarkLine(opts, config, context);
  6261. }
  6262. drawLegend(opts.series, opts, config, context, opts.chartData);
  6263. drawToolTipBridge(opts, config, context, process, eachSpacing, yAxisPoints);
  6264. drawCanvas(opts, context);
  6265. },
  6266. onAnimationFinish: function onAnimationFinish() {
  6267. _this.uevent.trigger('renderComplete');
  6268. }
  6269. });
  6270. break;
  6271. case 'area':
  6272. this.animationInstance = new Animation({
  6273. timing: opts.timing,
  6274. duration: duration,
  6275. onProcess: function onProcess(process) {
  6276. context.clearRect(0, 0, opts.width, opts.height);
  6277. if (opts.rotate) {
  6278. contextRotate(context, opts);
  6279. }
  6280. drawYAxisGrid(categories, opts, config, context);
  6281. drawXAxis(categories, opts, config, context);
  6282. var _drawAreaDataPoints = drawAreaDataPoints(series, opts, config, context, process),
  6283. xAxisPoints = _drawAreaDataPoints.xAxisPoints,
  6284. calPoints = _drawAreaDataPoints.calPoints,
  6285. eachSpacing = _drawAreaDataPoints.eachSpacing;
  6286. opts.chartData.xAxisPoints = xAxisPoints;
  6287. opts.chartData.calPoints = calPoints;
  6288. opts.chartData.eachSpacing = eachSpacing;
  6289. drawYAxis(series, opts, config, context);
  6290. if (opts.enableMarkLine !== false && process === 1) {
  6291. drawMarkLine(opts, config, context);
  6292. }
  6293. drawLegend(opts.series, opts, config, context, opts.chartData);
  6294. drawToolTipBridge(opts, config, context, process, eachSpacing, xAxisPoints);
  6295. drawCanvas(opts, context);
  6296. },
  6297. onAnimationFinish: function onAnimationFinish() {
  6298. _this.uevent.trigger('renderComplete');
  6299. }
  6300. });
  6301. break;
  6302. case 'ring':
  6303. this.animationInstance = new Animation({
  6304. timing: opts.timing,
  6305. duration: duration,
  6306. onProcess: function onProcess(process) {
  6307. context.clearRect(0, 0, opts.width, opts.height);
  6308. if (opts.rotate) {
  6309. contextRotate(context, opts);
  6310. }
  6311. opts.chartData.pieData = drawPieDataPoints(series, opts, config, context, process);
  6312. drawLegend(opts.series, opts, config, context, opts.chartData);
  6313. drawToolTipBridge(opts, config, context, process);
  6314. drawCanvas(opts, context);
  6315. },
  6316. onAnimationFinish: function onAnimationFinish() {
  6317. _this.uevent.trigger('renderComplete');
  6318. }
  6319. });
  6320. break;
  6321. case 'pie':
  6322. this.animationInstance = new Animation({
  6323. timing: opts.timing,
  6324. duration: duration,
  6325. onProcess: function onProcess(process) {
  6326. context.clearRect(0, 0, opts.width, opts.height);
  6327. if (opts.rotate) {
  6328. contextRotate(context, opts);
  6329. }
  6330. opts.chartData.pieData = drawPieDataPoints(series, opts, config, context, process);
  6331. drawLegend(opts.series, opts, config, context, opts.chartData);
  6332. drawToolTipBridge(opts, config, context, process);
  6333. drawCanvas(opts, context);
  6334. },
  6335. onAnimationFinish: function onAnimationFinish() {
  6336. _this.uevent.trigger('renderComplete');
  6337. }
  6338. });
  6339. break;
  6340. case 'rose':
  6341. this.animationInstance = new Animation({
  6342. timing: opts.timing,
  6343. duration: duration,
  6344. onProcess: function onProcess(process) {
  6345. context.clearRect(0, 0, opts.width, opts.height);
  6346. if (opts.rotate) {
  6347. contextRotate(context, opts);
  6348. }
  6349. opts.chartData.pieData = drawRoseDataPoints(series, opts, config, context, process);
  6350. drawLegend(opts.series, opts, config, context, opts.chartData);
  6351. drawToolTipBridge(opts, config, context, process);
  6352. drawCanvas(opts, context);
  6353. },
  6354. onAnimationFinish: function onAnimationFinish() {
  6355. _this.uevent.trigger('renderComplete');
  6356. }
  6357. });
  6358. break;
  6359. case 'radar':
  6360. this.animationInstance = new Animation({
  6361. timing: opts.timing,
  6362. duration: duration,
  6363. onProcess: function onProcess(process) {
  6364. context.clearRect(0, 0, opts.width, opts.height);
  6365. if (opts.rotate) {
  6366. contextRotate(context, opts);
  6367. }
  6368. opts.chartData.radarData = drawRadarDataPoints(series, opts, config, context, process);
  6369. drawLegend(opts.series, opts, config, context, opts.chartData);
  6370. drawToolTipBridge(opts, config, context, process);
  6371. drawCanvas(opts, context);
  6372. },
  6373. onAnimationFinish: function onAnimationFinish() {
  6374. _this.uevent.trigger('renderComplete');
  6375. }
  6376. });
  6377. break;
  6378. case 'arcbar':
  6379. this.animationInstance = new Animation({
  6380. timing: opts.timing,
  6381. duration: duration,
  6382. onProcess: function onProcess(process) {
  6383. context.clearRect(0, 0, opts.width, opts.height);
  6384. if (opts.rotate) {
  6385. contextRotate(context, opts);
  6386. }
  6387. opts.chartData.arcbarData = drawArcbarDataPoints(series, opts, config, context, process);
  6388. drawCanvas(opts, context);
  6389. },
  6390. onAnimationFinish: function onAnimationFinish() {
  6391. _this.uevent.trigger('renderComplete');
  6392. }
  6393. });
  6394. break;
  6395. case 'gauge':
  6396. this.animationInstance = new Animation({
  6397. timing: opts.timing,
  6398. duration: duration,
  6399. onProcess: function onProcess(process) {
  6400. context.clearRect(0, 0, opts.width, opts.height);
  6401. if (opts.rotate) {
  6402. contextRotate(context, opts);
  6403. }
  6404. opts.chartData.gaugeData = drawGaugeDataPoints(categories, series, opts, config, context, process);
  6405. drawCanvas(opts, context);
  6406. },
  6407. onAnimationFinish: function onAnimationFinish() {
  6408. _this.uevent.trigger('renderComplete');
  6409. }
  6410. });
  6411. break;
  6412. case 'candle':
  6413. this.animationInstance = new Animation({
  6414. timing: opts.timing,
  6415. duration: duration,
  6416. onProcess: function onProcess(process) {
  6417. context.clearRect(0, 0, opts.width, opts.height);
  6418. if (opts.rotate) {
  6419. contextRotate(context, opts);
  6420. }
  6421. drawYAxisGrid(categories, opts, config, context);
  6422. drawXAxis(categories, opts, config, context);
  6423. var _drawCandleDataPoints = drawCandleDataPoints(series, seriesMA, opts, config, context, process),
  6424. xAxisPoints = _drawCandleDataPoints.xAxisPoints,
  6425. calPoints = _drawCandleDataPoints.calPoints,
  6426. eachSpacing = _drawCandleDataPoints.eachSpacing;
  6427. opts.chartData.xAxisPoints = xAxisPoints;
  6428. opts.chartData.calPoints = calPoints;
  6429. opts.chartData.eachSpacing = eachSpacing;
  6430. drawYAxis(series, opts, config, context);
  6431. if (opts.enableMarkLine !== false && process === 1) {
  6432. drawMarkLine(opts, config, context);
  6433. }
  6434. if (seriesMA) {
  6435. drawLegend(seriesMA, opts, config, context, opts.chartData);
  6436. } else {
  6437. drawLegend(opts.series, opts, config, context, opts.chartData);
  6438. }
  6439. drawToolTipBridge(opts, config, context, process, eachSpacing, xAxisPoints);
  6440. drawCanvas(opts, context);
  6441. },
  6442. onAnimationFinish: function onAnimationFinish() {
  6443. _this.uevent.trigger('renderComplete');
  6444. }
  6445. });
  6446. break;
  6447. }
  6448. }
  6449. function uChartsEvent() {
  6450. this.events = {};
  6451. }
  6452. uChartsEvent.prototype.addEventListener = function(type, listener) {
  6453. this.events[type] = this.events[type] || [];
  6454. this.events[type].push(listener);
  6455. };
  6456. uChartsEvent.prototype.delEventListener = function(type) {
  6457. this.events[type] = [];
  6458. };
  6459. uChartsEvent.prototype.trigger = function() {
  6460. for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
  6461. args[_key] = arguments[_key];
  6462. }
  6463. var type = args[0];
  6464. var params = args.slice(1);
  6465. if (!!this.events[type]) {
  6466. this.events[type].forEach(function(listener) {
  6467. try {
  6468. listener.apply(null, params);
  6469. } catch (e) {
  6470. //console.log('[uCharts] '+e);
  6471. }
  6472. });
  6473. }
  6474. };
  6475. var uCharts = function uCharts(opts) {
  6476. opts.pix = opts.pixelRatio ? opts.pixelRatio : 1;
  6477. opts.fontSize = opts.fontSize ? opts.fontSize : 13;
  6478. opts.fontColor = opts.fontColor ? opts.fontColor : config.fontColor;
  6479. if (opts.background == "" || opts.background == "none") {
  6480. opts.background = "#FFFFFF"
  6481. }
  6482. opts.title = assign({}, opts.title);
  6483. opts.subtitle = assign({}, opts.subtitle);
  6484. opts.duration = opts.duration ? opts.duration : 1000;
  6485. opts.yAxis = assign({}, {
  6486. data: [],
  6487. showTitle: false,
  6488. disabled: false,
  6489. disableGrid: false,
  6490. gridSet: 'number',
  6491. splitNumber: 5,
  6492. gridType: 'solid',
  6493. dashLength: 4 * opts.pix,
  6494. gridColor: '#cccccc',
  6495. padding: 10,
  6496. fontColor: '#666666'
  6497. }, opts.yAxis);
  6498. opts.xAxis = assign({}, {
  6499. rotateLabel: false,
  6500. rotateAngle:45,
  6501. disabled: false,
  6502. disableGrid: false,
  6503. splitNumber: 5,
  6504. calibration:false,
  6505. gridType: 'solid',
  6506. dashLength: 4,
  6507. scrollAlign: 'left',
  6508. boundaryGap: 'center',
  6509. axisLine: true,
  6510. axisLineColor: '#cccccc'
  6511. }, opts.xAxis);
  6512. opts.xAxis.scrollPosition = opts.xAxis.scrollAlign;
  6513. opts.legend = assign({}, {
  6514. show: true,
  6515. position: 'bottom',
  6516. float: 'center',
  6517. backgroundColor: 'rgba(0,0,0,0)',
  6518. borderColor: 'rgba(0,0,0,0)',
  6519. borderWidth: 0,
  6520. padding: 5,
  6521. margin: 5,
  6522. itemGap: 10,
  6523. fontSize: opts.fontSize,
  6524. lineHeight: opts.fontSize,
  6525. fontColor: opts.fontColor,
  6526. formatter: {},
  6527. hiddenColor: '#CECECE'
  6528. }, opts.legend);
  6529. opts.extra = assign({}, opts.extra);
  6530. opts.rotate = opts.rotate ? true : false;
  6531. opts.animation = opts.animation ? true : false;
  6532. opts.rotate = opts.rotate ? true : false;
  6533. opts.canvas2d = opts.canvas2d ? true : false;
  6534. let config$$1 = assign({}, config);
  6535. config$$1.color = opts.color ? opts.color : config$$1.color;
  6536. if (opts.type == 'pie') {
  6537. config$$1.pieChartLinePadding = opts.dataLabel === false ? 0 : opts.extra.pie.labelWidth * opts.pix || config$$1.pieChartLinePadding * opts.pix;
  6538. }
  6539. if (opts.type == 'ring') {
  6540. config$$1.pieChartLinePadding = opts.dataLabel === false ? 0 : opts.extra.ring.labelWidth * opts.pix || config$$1.pieChartLinePadding * opts.pix;
  6541. }
  6542. if (opts.type == 'rose') {
  6543. config$$1.pieChartLinePadding = opts.dataLabel === false ? 0 : opts.extra.rose.labelWidth * opts.pix || config$$1.pieChartLinePadding * opts.pix;
  6544. }
  6545. config$$1.pieChartTextPadding = opts.dataLabel === false ? 0 : config$$1.pieChartTextPadding * opts.pix;
  6546. //屏幕旋转
  6547. config$$1.rotate = opts.rotate;
  6548. if (opts.rotate) {
  6549. let tempWidth = opts.width;
  6550. let tempHeight = opts.height;
  6551. opts.width = tempHeight;
  6552. opts.height = tempWidth;
  6553. }
  6554. //适配高分屏
  6555. opts.padding = opts.padding ? opts.padding : config$$1.padding;
  6556. config$$1.yAxisWidth = config.yAxisWidth * opts.pix;
  6557. config$$1.xAxisHeight = config.xAxisHeight * opts.pix;
  6558. if (opts.enableScroll && opts.xAxis.scrollShow) {
  6559. config$$1.xAxisHeight += 6 * opts.pix;
  6560. }
  6561. config$$1.fontSize = opts.fontSize * opts.pix;
  6562. config$$1.titleFontSize = config.titleFontSize * opts.pix;
  6563. config$$1.subtitleFontSize = config.subtitleFontSize * opts.pix;
  6564. config$$1.toolTipPadding = config.toolTipPadding * opts.pix;
  6565. config$$1.toolTipLineHeight = config.toolTipLineHeight * opts.pix;
  6566. if(!opts.context){
  6567. throw new Error('[uCharts] 未获取到context!注意:v2.0版本后,需要自行获取canvas的绘图上下文并传入opts.context!');
  6568. }
  6569. this.context = opts.context;
  6570. if (!this.context.setTextAlign) {
  6571. this.context.setStrokeStyle = function(e) {
  6572. return this.strokeStyle = e;
  6573. }
  6574. this.context.setLineWidth = function(e) {
  6575. return this.lineWidth = e;
  6576. }
  6577. this.context.setLineCap = function(e) {
  6578. return this.lineCap = e;
  6579. }
  6580. this.context.setFontSize = function(e) {
  6581. return this.font = e + "px sans-serif";
  6582. }
  6583. this.context.setFillStyle = function(e) {
  6584. return this.fillStyle = e;
  6585. }
  6586. this.context.setTextAlign = function(e) {
  6587. return this.textAlign = e;
  6588. }
  6589. this.context.draw = function() {}
  6590. }
  6591. //兼容NVUEsetLineDash
  6592. if(!this.context.setLineDash){
  6593. this.context.setLineDash = function(e) {}
  6594. }
  6595. opts.chartData = {};
  6596. this.uevent = new uChartsEvent();
  6597. this.scrollOption = {
  6598. currentOffset: 0,
  6599. startTouchX: 0,
  6600. distance: 0,
  6601. lastMoveTime: 0
  6602. };
  6603. this.opts = opts;
  6604. this.config = config$$1;
  6605. drawCharts.call(this, opts.type, opts, config$$1, this.context);
  6606. };
  6607. uCharts.prototype.updateData = function() {
  6608. let data = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  6609. this.opts = assign({}, this.opts, data);
  6610. this.opts.updateData = true;
  6611. let scrollPosition = data.scrollPosition || 'current';
  6612. switch (scrollPosition) {
  6613. case 'current':
  6614. this.opts._scrollDistance_ = this.scrollOption.currentOffset;
  6615. break;
  6616. case 'left':
  6617. this.opts._scrollDistance_ = 0;
  6618. this.scrollOption = {
  6619. currentOffset: 0,
  6620. startTouchX: 0,
  6621. distance: 0,
  6622. lastMoveTime: 0
  6623. };
  6624. break;
  6625. case 'right':
  6626. let _calYAxisData = calYAxisData(this.opts.series, this.opts, this.config, this.context), yAxisWidth = _calYAxisData.yAxisWidth;
  6627. this.config.yAxisWidth = yAxisWidth;
  6628. let offsetLeft = 0;
  6629. let _getXAxisPoints0 = getXAxisPoints(this.opts.categories, this.opts, this.config), xAxisPoints = _getXAxisPoints0.xAxisPoints,
  6630. startX = _getXAxisPoints0.startX,
  6631. endX = _getXAxisPoints0.endX,
  6632. eachSpacing = _getXAxisPoints0.eachSpacing;
  6633. let totalWidth = eachSpacing * (xAxisPoints.length - 1);
  6634. let screenWidth = endX - startX;
  6635. offsetLeft = screenWidth - totalWidth;
  6636. this.scrollOption = {
  6637. currentOffset: offsetLeft,
  6638. startTouchX: offsetLeft,
  6639. distance: 0,
  6640. lastMoveTime: 0
  6641. };
  6642. this.opts._scrollDistance_ = offsetLeft;
  6643. break;
  6644. }
  6645. drawCharts.call(this, this.opts.type, this.opts, this.config, this.context);
  6646. };
  6647. uCharts.prototype.zoom = function() {
  6648. var val = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : this.opts.xAxis.itemCount;
  6649. if (this.opts.enableScroll !== true) {
  6650. console.log('[uCharts] 请启用滚动条后使用')
  6651. return;
  6652. }
  6653. //当前屏幕中间点
  6654. let centerPoint = Math.round(Math.abs(this.scrollOption.currentOffset) / this.opts.chartData.eachSpacing) + Math.round(this.opts.xAxis.itemCount / 2);
  6655. this.opts.animation = false;
  6656. this.opts.xAxis.itemCount = val.itemCount;
  6657. //重新计算x轴偏移距离
  6658. let _calYAxisData = calYAxisData(this.opts.series, this.opts, this.config, this.context),
  6659. yAxisWidth = _calYAxisData.yAxisWidth;
  6660. this.config.yAxisWidth = yAxisWidth;
  6661. let offsetLeft = 0;
  6662. let _getXAxisPoints0 = getXAxisPoints(this.opts.categories, this.opts, this.config),
  6663. xAxisPoints = _getXAxisPoints0.xAxisPoints,
  6664. startX = _getXAxisPoints0.startX,
  6665. endX = _getXAxisPoints0.endX,
  6666. eachSpacing = _getXAxisPoints0.eachSpacing;
  6667. let centerLeft = eachSpacing * centerPoint;
  6668. let screenWidth = endX - startX;
  6669. let MaxLeft = screenWidth - eachSpacing * (xAxisPoints.length - 1);
  6670. offsetLeft = screenWidth / 2 - centerLeft;
  6671. if (offsetLeft > 0) {
  6672. offsetLeft = 0;
  6673. }
  6674. if (offsetLeft < MaxLeft) {
  6675. offsetLeft = MaxLeft;
  6676. }
  6677. this.scrollOption = {
  6678. currentOffset: offsetLeft,
  6679. startTouchX: 0,
  6680. distance: 0,
  6681. lastMoveTime: 0
  6682. };
  6683. calValidDistance(this, offsetLeft, this.opts.chartData, this.config, this.opts);
  6684. this.opts._scrollDistance_ = offsetLeft;
  6685. drawCharts.call(this, this.opts.type, this.opts, this.config, this.context);
  6686. };
  6687. uCharts.prototype.dobuleZoom = function(e) {
  6688. if (this.opts.enableScroll !== true) {
  6689. console.log('[uCharts] 请启用滚动条后使用')
  6690. return;
  6691. }
  6692. const tcs = e.changedTouches;
  6693. if (tcs.length < 2) {
  6694. return;
  6695. }
  6696. for (var i = 0; i < tcs.length; i++) {
  6697. tcs[i].x = tcs[i].x ? tcs[i].x : tcs[i].clientX;
  6698. tcs[i].y = tcs[i].y ? tcs[i].y : tcs[i].clientY;
  6699. }
  6700. const ntcs = [getTouches(tcs[0], this.opts, e),getTouches(tcs[1], this.opts, e)];
  6701. const xlength = Math.abs(ntcs[0].x - ntcs[1].x);
  6702. // 记录初始的两指之间的数据
  6703. if(!this.scrollOption.moveCount){
  6704. let cts0 = {changedTouches:[{x:tcs[0].x,y:this.opts.area[0] / this.opts.pix + 2}]};
  6705. let cts1 = {changedTouches:[{x:tcs[1].x,y:this.opts.area[0] / this.opts.pix + 2}]};
  6706. if(this.opts.rotate){
  6707. cts0 = {changedTouches:[{x:this.opts.height / this.opts.pix - this.opts.area[0] / this.opts.pix - 2,y:tcs[0].y}]};
  6708. cts1 = {changedTouches:[{x:this.opts.height / this.opts.pix - this.opts.area[0] / this.opts.pix - 2,y:tcs[1].y}]};
  6709. }
  6710. const moveCurrent1 = this.getCurrentDataIndex(cts0).index;
  6711. const moveCurrent2 = this.getCurrentDataIndex(cts1).index;
  6712. const moveCount = Math.abs(moveCurrent1 - moveCurrent2);
  6713. this.scrollOption.moveCount = moveCount;
  6714. this.scrollOption.moveCurrent1 = Math.min(moveCurrent1, moveCurrent2);
  6715. this.scrollOption.moveCurrent2 = Math.max(moveCurrent1, moveCurrent2);
  6716. return;
  6717. }
  6718. let currentEachSpacing = xlength / this.scrollOption.moveCount;
  6719. let itemCount = (this.opts.width - this.opts.area[1] - this.opts.area[3]) / currentEachSpacing;
  6720. itemCount = itemCount <= 2 ? 2 : itemCount;
  6721. itemCount = itemCount >= this.opts.categories.length ? this.opts.categories.length : itemCount;
  6722. this.opts.animation = false;
  6723. this.opts.xAxis.itemCount = itemCount;
  6724. // 重新计算滚动条偏移距离
  6725. let offsetLeft = 0;
  6726. let _getXAxisPoints0 = getXAxisPoints(this.opts.categories, this.opts, this.config),
  6727. xAxisPoints = _getXAxisPoints0.xAxisPoints,
  6728. startX = _getXAxisPoints0.startX,
  6729. endX = _getXAxisPoints0.endX,
  6730. eachSpacing = _getXAxisPoints0.eachSpacing;
  6731. let currentLeft = eachSpacing * this.scrollOption.moveCurrent1;
  6732. let screenWidth = endX - startX;
  6733. let MaxLeft = screenWidth - eachSpacing * (xAxisPoints.length - 1);
  6734. offsetLeft = -currentLeft+Math.min(ntcs[0].x,ntcs[1].x)-this.opts.area[3]-eachSpacing;
  6735. if (offsetLeft > 0) {
  6736. offsetLeft = 0;
  6737. }
  6738. if (offsetLeft < MaxLeft) {
  6739. offsetLeft = MaxLeft;
  6740. }
  6741. this.scrollOption.currentOffset= offsetLeft;
  6742. this.scrollOption.startTouchX= 0;
  6743. this.scrollOption.distance=0;
  6744. calValidDistance(this, offsetLeft, this.opts.chartData, this.config, this.opts);
  6745. this.opts._scrollDistance_ = offsetLeft;
  6746. drawCharts.call(this, this.opts.type, this.opts, this.config, this.context);
  6747. }
  6748. uCharts.prototype.stopAnimation = function() {
  6749. this.animationInstance && this.animationInstance.stop();
  6750. };
  6751. uCharts.prototype.addEventListener = function(type, listener) {
  6752. this.uevent.addEventListener(type, listener);
  6753. };
  6754. uCharts.prototype.delEventListener = function(type) {
  6755. this.uevent.delEventListener(type);
  6756. };
  6757. uCharts.prototype.getCurrentDataIndex = function(e) {
  6758. var touches = null;
  6759. if (e.changedTouches) {
  6760. touches = e.changedTouches[0];
  6761. } else {
  6762. touches = e.mp.changedTouches[0];
  6763. }
  6764. if (touches) {
  6765. let _touches$ = getTouches(touches, this.opts, e);
  6766. if (this.opts.type === 'pie' || this.opts.type === 'ring') {
  6767. return findPieChartCurrentIndex({
  6768. x: _touches$.x,
  6769. y: _touches$.y
  6770. }, this.opts.chartData.pieData, this.opts);
  6771. } else if (this.opts.type === 'rose') {
  6772. return findRoseChartCurrentIndex({
  6773. x: _touches$.x,
  6774. y: _touches$.y
  6775. }, this.opts.chartData.pieData, this.opts);
  6776. } else if (this.opts.type === 'radar') {
  6777. return findRadarChartCurrentIndex({
  6778. x: _touches$.x,
  6779. y: _touches$.y
  6780. }, this.opts.chartData.radarData, this.opts.categories.length);
  6781. } else if (this.opts.type === 'funnel') {
  6782. return findFunnelChartCurrentIndex({
  6783. x: _touches$.x,
  6784. y: _touches$.y
  6785. }, this.opts.chartData.funnelData);
  6786. } else if (this.opts.type === 'map') {
  6787. return findMapChartCurrentIndex({
  6788. x: _touches$.x,
  6789. y: _touches$.y
  6790. }, this.opts);
  6791. } else if (this.opts.type === 'word') {
  6792. return findWordChartCurrentIndex({
  6793. x: _touches$.x,
  6794. y: _touches$.y
  6795. }, this.opts.chartData.wordCloudData);
  6796. } else if (this.opts.type === 'bar') {
  6797. return findBarChartCurrentIndex({
  6798. x: _touches$.x,
  6799. y: _touches$.y
  6800. }, this.opts.chartData.calPoints, this.opts, this.config, Math.abs(this.scrollOption.currentOffset));
  6801. } else {
  6802. return findCurrentIndex({
  6803. x: _touches$.x,
  6804. y: _touches$.y
  6805. }, this.opts.chartData.calPoints, this.opts, this.config, Math.abs(this.scrollOption.currentOffset));
  6806. }
  6807. }
  6808. return -1;
  6809. };
  6810. uCharts.prototype.getLegendDataIndex = function(e) {
  6811. var touches = null;
  6812. if (e.changedTouches) {
  6813. touches = e.changedTouches[0];
  6814. } else {
  6815. touches = e.mp.changedTouches[0];
  6816. }
  6817. if (touches) {
  6818. let _touches$ = getTouches(touches, this.opts, e);
  6819. return findLegendIndex({
  6820. x: _touches$.x,
  6821. y: _touches$.y
  6822. }, this.opts.chartData.legendData);
  6823. }
  6824. return -1;
  6825. };
  6826. uCharts.prototype.touchLegend = function(e) {
  6827. var option = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  6828. var touches = null;
  6829. if (e.changedTouches) {
  6830. touches = e.changedTouches[0];
  6831. } else {
  6832. touches = e.mp.changedTouches[0];
  6833. }
  6834. if (touches) {
  6835. var _touches$ = getTouches(touches, this.opts, e);
  6836. var index = this.getLegendDataIndex(e);
  6837. if (index >= 0) {
  6838. if (this.opts.type == 'candle') {
  6839. this.opts.seriesMA[index].show = !this.opts.seriesMA[index].show;
  6840. } else {
  6841. this.opts.series[index].show = !this.opts.series[index].show;
  6842. }
  6843. this.opts.animation = option.animation ? true : false;
  6844. this.opts._scrollDistance_ = this.scrollOption.currentOffset;
  6845. drawCharts.call(this, this.opts.type, this.opts, this.config, this.context);
  6846. }
  6847. }
  6848. };
  6849. uCharts.prototype.showToolTip = function(e) {
  6850. var option = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  6851. var touches = null;
  6852. if (e.changedTouches) {
  6853. touches = e.changedTouches[0];
  6854. } else {
  6855. touches = e.mp.changedTouches[0];
  6856. }
  6857. if (!touches) {
  6858. console.log("[uCharts] 未获取到event坐标信息");
  6859. }
  6860. var _touches$ = getTouches(touches, this.opts, e);
  6861. var currentOffset = this.scrollOption.currentOffset;
  6862. var opts = assign({}, this.opts, {
  6863. _scrollDistance_: currentOffset,
  6864. animation: false
  6865. });
  6866. if (this.opts.type === 'line' || this.opts.type === 'area' || this.opts.type === 'column' || this.opts.type === 'scatter' || this.opts.type === 'bubble') {
  6867. var current = this.getCurrentDataIndex(e);
  6868. var index = option.index == undefined ? current.index : option.index;
  6869. if (index > -1 || index.length>0) {
  6870. var seriesData = getSeriesDataItem(this.opts.series, index, current.group);
  6871. if (seriesData.length !== 0) {
  6872. var _getToolTipData = getToolTipData(seriesData, this.opts, index, current.group, this.opts.categories, option),
  6873. textList = _getToolTipData.textList,
  6874. offset = _getToolTipData.offset;
  6875. offset.y = _touches$.y;
  6876. opts.tooltip = {
  6877. textList: option.textList !== undefined ? option.textList : textList,
  6878. offset: option.offset !== undefined ? option.offset : offset,
  6879. option: option,
  6880. index: index
  6881. };
  6882. }
  6883. }
  6884. drawCharts.call(this, opts.type, opts, this.config, this.context);
  6885. }
  6886. if (this.opts.type === 'mount') {
  6887. var index = option.index == undefined ? this.getCurrentDataIndex(e).index : option.index;
  6888. if (index > -1) {
  6889. var opts = assign({}, this.opts, {animation: false});
  6890. var seriesData = assign({}, opts._series_[index]);
  6891. var textList = [{
  6892. text: option.formatter ? option.formatter(seriesData, undefined, index, opts) : seriesData.name + ': ' + seriesData.data,
  6893. color: seriesData.color
  6894. }];
  6895. var offset = {
  6896. x: opts.chartData.calPoints[index].x,
  6897. y: _touches$.y
  6898. };
  6899. opts.tooltip = {
  6900. textList: option.textList ? option.textList : textList,
  6901. offset: option.offset !== undefined ? option.offset : offset,
  6902. option: option,
  6903. index: index
  6904. };
  6905. }
  6906. drawCharts.call(this, opts.type, opts, this.config, this.context);
  6907. }
  6908. if (this.opts.type === 'bar') {
  6909. var current = this.getCurrentDataIndex(e);
  6910. var index = option.index == undefined ? current.index : option.index;
  6911. if (index > -1 || index.length>0) {
  6912. var seriesData = getSeriesDataItem(this.opts.series, index, current.group);
  6913. if (seriesData.length !== 0) {
  6914. var _getToolTipData = getToolTipData(seriesData, this.opts, index, current.group, this.opts.categories, option),
  6915. textList = _getToolTipData.textList,
  6916. offset = _getToolTipData.offset;
  6917. offset.x = _touches$.x;
  6918. opts.tooltip = {
  6919. textList: option.textList !== undefined ? option.textList : textList,
  6920. offset: option.offset !== undefined ? option.offset : offset,
  6921. option: option,
  6922. index: index
  6923. };
  6924. }
  6925. }
  6926. drawCharts.call(this, opts.type, opts, this.config, this.context);
  6927. }
  6928. if (this.opts.type === 'mix') {
  6929. var current = this.getCurrentDataIndex(e);
  6930. var index = option.index == undefined ? current.index : option.index;
  6931. if (index > -1) {
  6932. var currentOffset = this.scrollOption.currentOffset;
  6933. var opts = assign({}, this.opts, {
  6934. _scrollDistance_: currentOffset,
  6935. animation: false
  6936. });
  6937. var seriesData = getSeriesDataItem(this.opts.series, index);
  6938. if (seriesData.length !== 0) {
  6939. var _getMixToolTipData = getMixToolTipData(seriesData, this.opts, index, this.opts.categories, option),
  6940. textList = _getMixToolTipData.textList,
  6941. offset = _getMixToolTipData.offset;
  6942. offset.y = _touches$.y;
  6943. opts.tooltip = {
  6944. textList: option.textList ? option.textList : textList,
  6945. offset: option.offset !== undefined ? option.offset : offset,
  6946. option: option,
  6947. index: index
  6948. };
  6949. }
  6950. }
  6951. drawCharts.call(this, opts.type, opts, this.config, this.context);
  6952. }
  6953. if (this.opts.type === 'candle') {
  6954. var current = this.getCurrentDataIndex(e);
  6955. var index = option.index == undefined ? current.index : option.index;
  6956. if (index > -1) {
  6957. var currentOffset = this.scrollOption.currentOffset;
  6958. var opts = assign({}, this.opts, {
  6959. _scrollDistance_: currentOffset,
  6960. animation: false
  6961. });
  6962. var seriesData = getSeriesDataItem(this.opts.series, index);
  6963. if (seriesData.length !== 0) {
  6964. var _getToolTipData = getCandleToolTipData(this.opts.series[0].data, seriesData, this.opts, index, this.opts.categories, this.opts.extra.candle, option),
  6965. textList = _getToolTipData.textList,
  6966. offset = _getToolTipData.offset;
  6967. offset.y = _touches$.y;
  6968. opts.tooltip = {
  6969. textList: option.textList ? option.textList : textList,
  6970. offset: option.offset !== undefined ? option.offset : offset,
  6971. option: option,
  6972. index: index
  6973. };
  6974. }
  6975. }
  6976. drawCharts.call(this, opts.type, opts, this.config, this.context);
  6977. }
  6978. if (this.opts.type === 'pie' || this.opts.type === 'ring' || this.opts.type === 'rose' || this.opts.type === 'funnel') {
  6979. var index = option.index == undefined ? this.getCurrentDataIndex(e) : option.index;
  6980. if (index > -1) {
  6981. var opts = assign({}, this.opts, {animation: false});
  6982. var seriesData = assign({}, opts._series_[index]);
  6983. var textList = [{
  6984. text: option.formatter ? option.formatter(seriesData, undefined, index, opts) : seriesData.name + ': ' + seriesData.data,
  6985. color: seriesData.color
  6986. }];
  6987. var offset = {
  6988. x: _touches$.x,
  6989. y: _touches$.y
  6990. };
  6991. opts.tooltip = {
  6992. textList: option.textList ? option.textList : textList,
  6993. offset: option.offset !== undefined ? option.offset : offset,
  6994. option: option,
  6995. index: index
  6996. };
  6997. }
  6998. drawCharts.call(this, opts.type, opts, this.config, this.context);
  6999. }
  7000. if (this.opts.type === 'map') {
  7001. var index = option.index == undefined ? this.getCurrentDataIndex(e) : option.index;
  7002. if (index > -1) {
  7003. var opts = assign({}, this.opts, {animation: false});
  7004. var seriesData = assign({}, this.opts.series[index]);
  7005. seriesData.name = seriesData.properties.name
  7006. var textList = [{
  7007. text: option.formatter ? option.formatter(seriesData, undefined, index, this.opts) : seriesData.name,
  7008. color: seriesData.color
  7009. }];
  7010. var offset = {
  7011. x: _touches$.x,
  7012. y: _touches$.y
  7013. };
  7014. opts.tooltip = {
  7015. textList: option.textList ? option.textList : textList,
  7016. offset: option.offset !== undefined ? option.offset : offset,
  7017. option: option,
  7018. index: index
  7019. };
  7020. }
  7021. opts.updateData = false;
  7022. drawCharts.call(this, opts.type, opts, this.config, this.context);
  7023. }
  7024. if (this.opts.type === 'word') {
  7025. var index = option.index == undefined ? this.getCurrentDataIndex(e) : option.index;
  7026. if (index > -1) {
  7027. var opts = assign({}, this.opts, {animation: false});
  7028. var seriesData = assign({}, this.opts.series[index]);
  7029. var textList = [{
  7030. text: option.formatter ? option.formatter(seriesData, undefined, index, this.opts) : seriesData.name,
  7031. color: seriesData.color
  7032. }];
  7033. var offset = {
  7034. x: _touches$.x,
  7035. y: _touches$.y
  7036. };
  7037. opts.tooltip = {
  7038. textList: option.textList ? option.textList : textList,
  7039. offset: option.offset !== undefined ? option.offset : offset,
  7040. option: option,
  7041. index: index
  7042. };
  7043. }
  7044. opts.updateData = false;
  7045. drawCharts.call(this, opts.type, opts, this.config, this.context);
  7046. }
  7047. if (this.opts.type === 'radar') {
  7048. var index = option.index == undefined ? this.getCurrentDataIndex(e) : option.index;
  7049. if (index > -1) {
  7050. var opts = assign({}, this.opts, {animation: false});
  7051. var seriesData = getSeriesDataItem(this.opts.series, index);
  7052. if (seriesData.length !== 0) {
  7053. var textList = seriesData.map((item) => {
  7054. return {
  7055. text: option.formatter ? option.formatter(item, this.opts.categories[index], index, this.opts) : item.name + ': ' + item.data,
  7056. color: item.color
  7057. };
  7058. });
  7059. var offset = {
  7060. x: _touches$.x,
  7061. y: _touches$.y
  7062. };
  7063. opts.tooltip = {
  7064. textList: option.textList ? option.textList : textList,
  7065. offset: option.offset !== undefined ? option.offset : offset,
  7066. option: option,
  7067. index: index
  7068. };
  7069. }
  7070. }
  7071. drawCharts.call(this, opts.type, opts, this.config, this.context);
  7072. }
  7073. };
  7074. uCharts.prototype.translate = function(distance) {
  7075. this.scrollOption = {
  7076. currentOffset: distance,
  7077. startTouchX: distance,
  7078. distance: 0,
  7079. lastMoveTime: 0
  7080. };
  7081. let opts = assign({}, this.opts, {
  7082. _scrollDistance_: distance,
  7083. animation: false
  7084. });
  7085. drawCharts.call(this, this.opts.type, opts, this.config, this.context);
  7086. };
  7087. uCharts.prototype.scrollStart = function(e) {
  7088. var touches = null;
  7089. if (e.changedTouches) {
  7090. touches = e.changedTouches[0];
  7091. } else {
  7092. touches = e.mp.changedTouches[0];
  7093. }
  7094. var _touches$ = getTouches(touches, this.opts, e);
  7095. if (touches && this.opts.enableScroll === true) {
  7096. this.scrollOption.startTouchX = _touches$.x;
  7097. }
  7098. };
  7099. uCharts.prototype.scroll = function(e) {
  7100. if (this.scrollOption.lastMoveTime === 0) {
  7101. this.scrollOption.lastMoveTime = Date.now();
  7102. }
  7103. let Limit = this.opts.touchMoveLimit || 60;
  7104. let currMoveTime = Date.now();
  7105. let duration = currMoveTime - this.scrollOption.lastMoveTime;
  7106. if (duration < Math.floor(1000 / Limit)) return;
  7107. if (this.scrollOption.startTouchX == 0) return;
  7108. this.scrollOption.lastMoveTime = currMoveTime;
  7109. var touches = null;
  7110. if (e.changedTouches) {
  7111. touches = e.changedTouches[0];
  7112. } else {
  7113. touches = e.mp.changedTouches[0];
  7114. }
  7115. if (touches && this.opts.enableScroll === true) {
  7116. var _touches$ = getTouches(touches, this.opts, e);
  7117. var _distance;
  7118. _distance = _touches$.x - this.scrollOption.startTouchX;
  7119. var currentOffset = this.scrollOption.currentOffset;
  7120. var validDistance = calValidDistance(this, currentOffset + _distance, this.opts.chartData, this.config, this.opts);
  7121. this.scrollOption.distance = _distance = validDistance - currentOffset;
  7122. var opts = assign({}, this.opts, {
  7123. _scrollDistance_: currentOffset + _distance,
  7124. animation: false
  7125. });
  7126. this.opts = opts;
  7127. drawCharts.call(this, opts.type, opts, this.config, this.context);
  7128. return currentOffset + _distance;
  7129. }
  7130. };
  7131. uCharts.prototype.scrollEnd = function(e) {
  7132. if (this.opts.enableScroll === true) {
  7133. var _scrollOption = this.scrollOption,
  7134. currentOffset = _scrollOption.currentOffset,
  7135. distance = _scrollOption.distance;
  7136. this.scrollOption.currentOffset = currentOffset + distance;
  7137. this.scrollOption.distance = 0;
  7138. this.scrollOption.moveCount = 0;
  7139. }
  7140. };
  7141. export default uCharts;