import{i as ne,L as _,e as U}from"./index-Csvj-veb.js";import{d as p}from"./dayjs.min-tKPc2Ebd.js";import{t as ae,c as se,g as W,a as re,x as ie,s as le}from"./utils-BnHQDKCA.js";import{c as X}from"./cloneDeep-C6NKQlMO.js";import{d as ce,Y as de,t as fe,Q as me,v as pe,p as ue,o as Fe,b as ge,k as ye}from"./index-bVOhw2NF.js";import"./_initCloneObject-K-Y0ueWp.js";import"./_baseEach-BwxcRWC6.js";import"./_getTag-BJ2nhJXz.js";import"./get-BuNGRF3A.js";import"./toString-eibgRg41.js";import"./_baseFor-mOzdmxoL.js";const he=ce({name:"EsLineGradient",components:{},props:{options:{type:Object,default:()=>({})},datasets:{type:[Array,Object,String],default:()=>[]},eventData:{type:[String,Boolean,Number],default:""},element:{type:Object,default:()=>({})}},setup(u){const i=de(null),B={day:{prev:"昨日",curr:"今日"},month:{prev:"上月",curr:"当月"},year:{prev:"去年",curr:"今年"}},z=(n,F)=>{const{grid:E,title:K,legend:q,tooltip:v,xAxis:C,yAxis:I,codeConfig:N,timeAxisFormatter:d,completeDatas:T,timeCompare:e,dataShowTypes:Z,legendNameType:ee,renderMode:te}=F,oe=ae.bind({timeCompare:e,timeAxisFormatter:d}),R=document.querySelector(`.chart-${u.element.id}`);if(R){i.value||(i.value=ne(R,null,{renderer:te}));const G=n.info,f=Array.isArray(n.values)?n.values:n,P=n.param;if(f&&G&&P){let b=[];T&&(b=se(P,G,f));let l=[],g=[],t=[],w=null;if(f.length>0){const M=W(f,"thingCode");for(const $ in M){const k=W(M[$],"attrKey"),Y=Object.keys(k).length;for(const J in k){let a=k[J];const O=re(G,$,J,Z,ee,a);if(g.push(O),!w){const c=a[0],s=a[a.length-1];c.ts>s.ts&&(a=a.reverse());const h=p(+c.ts),D=p(+s.ts),S=h.diff(D,"day"),A=h.diff(D,"month");w=ie.bind({months:A,days:S,timeAxisFormatter:d,timeCompare:T&&e})}if(T&&b.length>0)if(e){const c=le(b,e),s={},h=c.prev.map((r,V)=>{let o=null;if(e==="day"?o=p(r).format(d||"HH:mm"):e==="month"?o=p(r).format(d||"DD"):e==="year"&&(o=p(r).format(d||"MM")),!t.includes(o)){t.push(o),s[V]=!0;const x=a.find(j=>+j.ts===r);return x&&x.val||0}}),D=c.curr.map((r,V)=>{if(t.length===0){let o=null;if(e==="day"?o=p(r).format(d||"HH:mm"):e==="month"?o=p(r).format(d||"DD"):e==="year"&&(o=p(r).format(d||"MM")),!t.includes(o)){t.push(o);const x=a.find(j=>+j.ts===r);return x&&x.val||0}}else if(s[V]){const o=a.find(x=>+x.ts===r);return o&&o.val||0}});let S="",A="";Y>1?(S=`${O}(${B[e].prev})`,A=`${O}(${B[e].curr})`):Y===1&&(S=`${B[e].prev}`,A=`${B[e].curr}`),g.push(S),g.push(A),l.push({name:S,type:"line",data:h.filter(Boolean)}),l.push({name:A,type:"line",data:D.filter(Boolean)})}else{const c=b.map(s=>{t.push(s);const h=a.find(D=>+D.ts===s);return h&&h.val||0});l.push({name:O,type:"line",data:c})}else{const c=a.map(s=>(t.push(+s.ts),s.val));l.push({name:O,type:"line",data:c})}}}}else g=["测试图例"],t=[1,2,3,4,5,6,7,8],l=[{type:"line",name:"测试图例",data:[100,80,60,40,20,10,5,0]}];t=[...new Set(t)].sort();const H={...q,data:g.filter(Boolean)},m={...C,axisLabel:{...C.axisLabel,formatter:T&&e?null:w},nameLocation:"end",nameGap:5,nameTextStyle:{color:C.nameColor,verticalAlign:"top",lineHeight:28},data:t},y={grid:E,title:K,tooltip:{...v,formatter:oe,borderColor:v.backgroundColor,textStyle:{...v.textStyle,align:"left"}},legend:H,xAxis:m,yAxis:I,series:l};y.color=["#4992FFFF","#7CFFB2FF","#FDDD60FF","#FF6E76FF","#58D9F9FF","#05C091FF"],y.series[0]&&(y.series[0].areaStyle={color:new _(0,1,0,0,[{offset:0,color:"#4992FF10"},{offset:1,color:"#4992FFFF"}])}),y.series[1]&&(y.series[1].areaStyle={color:new _(0,1,0,0,[{offset:0,color:"#7CFFB210"},{offset:1,color:"#7CFFB2FF"}])});const L=new Function("option","datas","instance","echarts",N)(X(y),f,i.value,U);i.value.setOption(L)}else{const b=u.element.dataSource.legendConfig||[{dataField:"data1",legend:"legend1"},{dataField:"data2",legend:"legend2"}],l=[],g=[...new Set(f.map(L=>L.category))],t=[];for(const L of b){const{dataField:M,legend:$}=L;l.push($),t.push({name:$,type:"line",data:f.map(k=>k[M])})}const w={...C,axisLabel:{...C.axisLabel},nameLocation:"end",nameGap:5,nameTextStyle:{color:C.nameColor,verticalAlign:"top",lineHeight:28},data:g},H={...q,data:l.filter(Boolean)},m={grid:E,title:K,tooltip:{...v,borderColor:v.backgroundColor,textStyle:{...v.textStyle,align:"left"}},legend:H,xAxis:w,yAxis:I,series:t};m.color=["#4992FFFF","#7CFFB2FF","#FDDD60FF","#FF6E76FF","#58D9F9FF","#05C091FF"],m.series[0]&&(m.series[0].areaStyle={color:new _(0,1,0,0,[{offset:0,color:"#4992FF10"},{offset:1,color:"#4992FFFF"}])}),m.series[1]&&(m.series[1].areaStyle={color:new _(0,1,0,0,[{offset:0,color:"#7CFFB210"},{offset:1,color:"#7CFFB2FF"}])});const Q=new Function("option","datas","instance","echarts",N)(X(m),f,i.value,U);i.value.setOption(Q)}}};return fe([()=>u.datasets,()=>u.options],([n,F])=>{n&&me(()=>{z(n,F)})},{immediate:!0,deep:!0}),pe(()=>{const n=new ResizeObserver(()=>{i.value.resize()}),F=document.querySelector(`.chart-${u.element.id}`);F&&n.observe(F)}),{myChart:i}}});function xe(u,i,B,z,n,F){return Fe(),ge("div",{class:ye(`chart-${u.element.id}`),width:"100%",height:"100%"},null,2)}const Oe=ue(he,[["render",xe]]);export{Oe as default};