import{d as _,K as z,I as C,w as y,o as I,c as O,g as T,h as F}from"./index-CXwCk-SR.js";import{u as M,i as B,a as R,b as V,c as W,d as k}from"./installCanvasRenderer-rwnueg-z.js";import{i as D}from"./install-BvSgdkOe.js";import{_ as E}from"./_plugin-vue_export-helper-DlAUqK2U.js";const G=_({__name:"TimeChart",props:{series:{},height:{default:180},unit:{},accent:{default:"var(--sw-accent)"},format:{},xLabels:{}},setup(S){M([R,V,D,W,k]);const e=S;function A(t){return e.format==="int"?Math.round(t).toString():e.format==="decimal"?t.toFixed(1):t.toFixed(2)}function w(t){return e.format==="int"?Math.round(t).toString():String(t)}function L(t){if(!t.startsWith("var("))return t;if(typeof window>"u")return"#f97316";const r=t.replace(/^var\(\s*/,"").replace(/\s*\)\s*$/,"");return getComputedStyle(document.documentElement).getPropertyValue(r).trim()||"#f97316"}const v=["#60a5fa","#a78bfa","#22d3ee","#f472b6","#34d399","#fbbf24"],x=F(null);let i=null;function b(){var l;const t=((l=e.series[0])==null?void 0:l.data.length)??0,r=e.xLabels&&e.xLabels.length===t?e.xLabels:Array.from({length:t},(n,s)=>`-${t-s-1}m`);return{backgroundColor:"transparent",tooltip:{trigger:"axis",backgroundColor:"rgba(20,20,24,0.92)",borderColor:"rgba(255,255,255,0.08)",textStyle:{color:"#e5e7eb",fontSize:11},appendToBody:!0,extraCssText:"max-height: 60vh; overflow-y: auto; max-width: 360px; box-shadow: 0 8px 24px rgba(0,0,0,0.45);",position(n,s,d,c,f){const[m,a]=f.contentSize,[o,$]=f.viewSize,u=12,p={};return n[0]+m+u*2>o?p.right=o-n[0]+u:p.left=n[0]+u,n[1]+a+u*2>$?p.bottom=$-n[1]+u:p.top=n[1]+u,p},valueFormatter:n=>typeof n=="number"&&Number.isFinite(n)?`${A(n)}${e.unit?` ${e.unit}`:""}`:"—"},legend:{show:e.series.length>1,top:2,left:4,right:4,padding:[0,0,0,0],textStyle:{color:"#94a3b8",fontSize:10,lineHeight:12},itemWidth:10,itemHeight:8,itemGap:14,icon:"roundRect",type:"scroll"},grid:{left:36,right:e.series.some(n=>(n.yAxisIndex??0)===1)?32:8,top:e.series.length>1?36:10,bottom:8,containLabel:!1},xAxis:{type:"category",data:r,axisLine:{lineStyle:{color:"rgba(255,255,255,0.08)"}},axisLabel:{color:"#64748b",fontSize:9,interval:Math.floor(t/6)},splitLine:{show:!1}},yAxis:(()=>{var m,a;const n=e.series.some(o=>(o.yAxisIndex??0)===1),s=e.series.length>1,d=(m=e.series.find(o=>(o.yAxisIndex??0)===1))==null?void 0:m.unit,c=((a=e.series.find(o=>(o.yAxisIndex??0)===0))==null?void 0:a.unit)??e.unit,f=[{type:"value",name:s?"":c??"",nameTextStyle:{color:"#64748b",fontSize:9,padding:[0,0,0,0]},nameGap:8,axisLine:{show:!1},axisLabel:{color:"#64748b",fontSize:9,formatter:o=>w(o)},splitLine:{lineStyle:{color:"rgba(255,255,255,0.06)"}}}];return n&&f.push({type:"value",name:s?"":d??"",nameTextStyle:{color:"#64748b",fontSize:9},nameGap:8,axisLine:{show:!1},axisLabel:{color:"#64748b",fontSize:9,formatter:o=>w(o)},splitLine:{show:!1}}),f})(),series:e.series.map((n,s)=>{const d=L(e.accent),c=s===0?d:v[(s-1)%v.length];return{name:e.series.some(a=>(a.yAxisIndex??0)===1)&&n.unit?`${n.label} (${n.unit})`:n.label,type:"line",smooth:!0,symbol:"circle",symbolSize:4,showSymbol:!0,yAxisIndex:n.yAxisIndex??0,lineStyle:{width:1.5},data:n.data.map(a=>a===null?"-":a),itemStyle:{color:c,borderColor:c,borderWidth:1},emphasis:{focus:"series",scale:!1,itemStyle:{borderColor:c,borderWidth:2,color:"#fff"}},areaStyle:e.series.length===1?{color:d,opacity:.12}:void 0}})}}function g(t){return t.map(r=>`${r.label}|${r.yAxisIndex??0}|${r.unit??""}|${r.data.length}`).join("::")}let h="";return z(()=>{if(!x.value)return;i=B(x.value,null,{renderer:"canvas"}),i.setOption(b()),h=g(e.series);const t=new ResizeObserver(()=>i==null?void 0:i.resize());t.observe(x.value),C(()=>{t.disconnect(),i==null||i.dispose(),i=null})}),y(()=>e.series,t=>{if(!i)return;const r=g(t);r===h?i.setOption({series:t.map((l,n)=>({name:l.label,data:l.data.map(s=>s===null?"-":s),...n===-1?{}:{}}))}):(i.setOption(b(),{replaceMerge:["series"]}),h=r)},{deep:!0}),y(()=>e.unit,()=>i==null?void 0:i.setOption(b())),y(()=>e.accent,()=>{i==null||i.setOption(b(),{replaceMerge:["series"]}),h=g(e.series)}),(t,r)=>(I(),O("div",{ref_key:"container",ref:x,class:"time-chart",style:T({height:`${S.height}px`})},null,4))}}),K=E(G,[["__scopeId","data-v-b41ed4a8"]]);export{K as T};
