u-charts.js 289 KB

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