u-charts.js 271 KB

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