u-charts.js 289 KB

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