@qfo/qfchart 0.6.8 → 0.7.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -14,25 +14,25 @@
14
14
  * See the License for the specific language governing permissions and
15
15
  * limitations under the License.
16
16
  */
17
- import*as H from"echarts";var It=Object.defineProperty,At=(y,e,t)=>e in y?It(y,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):y[e]=t,ot=(y,e,t)=>(At(y,typeof e!="symbol"?e+"":e,t),t);class St{constructor(e,t,i,s={}){ot(this,"id"),ot(this,"plots"),ot(this,"paneIndex"),ot(this,"height"),ot(this,"collapsed"),ot(this,"titleColor"),ot(this,"controls"),this.id=e,this.plots=t,this.paneIndex=i,this.height=s.height,this.collapsed=s.collapsed||!1,this.titleColor=s.titleColor,this.controls=s.controls}toggleCollapse(){this.collapsed=!this.collapsed}isVisible(){return!this.collapsed}updateData(e){Object.keys(e).forEach(t=>{if(!this.plots[t])this.plots[t]=e[t];else{const i=this.plots[t],s=e[t];if(!i.data)return;s.options&&(i.options={...i.options,...s.options});const n=new Map;i.data?.forEach(a=>{n.set(a.time,a)}),s.data?.forEach(a=>{n.set(a.time,a)}),i.data=Array.from(n.values()).sort((a,u)=>a.time-u.time)}})}}class Z{static createMinFunction(e){return t=>{const i=(t.max-t.min)*(e/100);return t.min-i}}static createMaxFunction(e){return t=>{const i=(t.max-t.min)*(e/100);return t.max+i}}static autoDetectDecimals(e){if(!e||e.length===0)return 2;const t=e[e.length-1].close;if(t===0||!isFinite(t)||isNaN(t))return 2;const i=Math.abs(t);if(i>=1)return 2;const s=Math.ceil(-Math.log10(i));return Math.min(s+4,10)}static formatValue(e,t){return typeof e=="number"?e.toFixed(t):String(e)}}class mt{static calculate(e,t,i,s=!1,n=null,a){let u=0;e>0&&(u=1/e*100);const p=i.yAxisPadding!==void 0?i.yAxisPadding:5,d=Array.from(t.values()).map(v=>v.paneIndex).filter(v=>v>0).sort((v,D)=>v-D).filter((v,D,E)=>E.indexOf(v)===D),f=d.length>0,l=i.dataZoom?.visible??!0,r=i.dataZoom?.position??"top",h=i.dataZoom?.height??6,o=i.dataZoom?.start??0,c=i.dataZoom?.end??100;let g=8,w=92,A=-1;if(n)if(n==="main")A=0;else{const v=t.get(n);v&&(A=v.paneIndex)}if(A!==-1){const v=[],D=[],E=[],_=[],V=i.dataZoom?.start??50,F=i.dataZoom?.end??100;(i.dataZoom?.zoomOnTouch??!0)&&_.push({type:"inside",xAxisIndex:"all",start:V,end:F});const G=f?Math.max(...d):0,R=[];for(let N=0;N<=G;N++){const W=N===A;v.push({left:"10%",right:"10%",top:W?"5%":"0%",height:W?"90%":"0%",show:W,containLabel:!1}),D.push({type:"category",gridIndex:N,data:[],show:W,axisLabel:{show:W,color:"#94a3b8",fontFamily:i.fontFamily},axisLine:{show:W,lineStyle:{color:"#334155"}},splitLine:{show:W,lineStyle:{color:"#334155",opacity:.5}}});let it,et;if(N===0&&A===0?(it=i.yAxisMin!==void 0&&i.yAxisMin!=="auto"?i.yAxisMin:Z.createMinFunction(p),et=i.yAxisMax!==void 0&&i.yAxisMax!=="auto"?i.yAxisMax:Z.createMaxFunction(p)):(it=Z.createMinFunction(p),et=Z.createMaxFunction(p)),E.push({position:"right",gridIndex:N,show:W,scale:!0,min:it,max:et,axisLabel:{show:W,color:"#94a3b8",fontFamily:i.fontFamily,formatter:K=>{if(i.yAxisLabelFormatter)return i.yAxisLabelFormatter(K);const st=i.yAxisDecimalPlaces!==void 0?i.yAxisDecimalPlaces:Z.autoDetectDecimals(a);return Z.formatValue(K,st)}},splitLine:{show:W,lineStyle:{color:"#334155",opacity:.5}}}),N>0){const K=Array.from(t.values()).find(st=>st.paneIndex===N);K&&R.push({index:N,height:W?90:0,top:W?5:0,isCollapsed:!1,indicatorId:K.id,titleColor:K.titleColor,controls:K.controls})}}return{grid:v,xAxis:D,yAxis:E,dataZoom:_,paneLayout:R,mainPaneHeight:A===0?90:0,mainPaneTop:A===0?5:0,pixelToPercent:u,overlayYAxisMap:new Map,separatePaneYAxisOffset:1}}l?r==="top"?(g=h+4,w=95):(w=100-h-2,g=8):(g=5,w=95);let P=5;e>0&&(P=20/e*100);let x=75,b=[];if(f){const v=d.map(F=>{const G=Array.from(t.values()).find(R=>R.paneIndex===F);return{index:F,requestedHeight:G?.height,isCollapsed:G?.collapsed??!1,indicatorId:G?.id,titleColor:G?.titleColor,controls:G?.controls}}).map(F=>({...F,height:F.isCollapsed?3:F.requestedHeight!==void 0?F.requestedHeight:15})),D=v.reduce((F,G)=>F+G.height,0),E=v.length*P,_=D+E;x=w-g-_,s?x=3:x<20&&(x=Math.max(x,10));let V=g+x+P;b=v.map(F=>{const G={index:F.index,height:F.height,top:V,isCollapsed:F.isCollapsed,indicatorId:F.indicatorId,titleColor:F.titleColor,controls:F.controls};return V+=F.height+P,G})}else x=w-g,s&&(x=3);const C=[];C.push({left:"10%",right:"10%",top:g+"%",height:x+"%",containLabel:!1}),b.forEach(v=>{C.push({left:"10%",right:"10%",top:v.top+"%",height:v.height+"%",containLabel:!1})});const I=[0,...b.map((v,D)=>D+1)],m=[],M=b.length===0;m.push({type:"category",data:[],gridIndex:0,scale:!0,axisLine:{onZero:!1,show:!s,lineStyle:{color:"#334155"}},splitLine:{show:!s,lineStyle:{color:"#334155",opacity:.5}},axisLabel:{show:!s,color:"#94a3b8",fontFamily:i.fontFamily||"sans-serif",formatter:v=>{if(i.yAxisLabelFormatter)return i.yAxisLabelFormatter(v);const D=i.yAxisDecimalPlaces!==void 0?i.yAxisDecimalPlaces:Z.autoDetectDecimals(a);return Z.formatValue(v,D)}},axisTick:{show:!s},axisPointer:{label:{show:M,fontSize:11,backgroundColor:"#475569"}}}),b.forEach((v,D)=>{const E=D===b.length-1;m.push({type:"category",gridIndex:D+1,data:[],axisLabel:{show:!1},axisLine:{show:!v.isCollapsed,lineStyle:{color:"#334155"}},axisTick:{show:!1},splitLine:{show:!1},axisPointer:{label:{show:E,fontSize:11,backgroundColor:"#475569"}}})});const k=[];let S,L;i.yAxisMin!==void 0&&i.yAxisMin!=="auto"?S=i.yAxisMin:S=Z.createMinFunction(p),i.yAxisMax!==void 0&&i.yAxisMax!=="auto"?L=i.yAxisMax:L=Z.createMaxFunction(p),k.push({position:"right",scale:!0,min:S,max:L,gridIndex:0,splitLine:{show:!s,lineStyle:{color:"#334155",opacity:.5}},axisLine:{show:!s,lineStyle:{color:"#334155"}},axisLabel:{show:!s,color:"#94a3b8",fontFamily:i.fontFamily||"sans-serif",formatter:v=>{if(i.yAxisLabelFormatter)return i.yAxisLabelFormatter(v);const D=i.yAxisDecimalPlaces!==void 0?i.yAxisDecimalPlaces:Z.autoDetectDecimals(a);return Z.formatValue(v,D)}}});let z=1,O=-1/0,U=1/0;a&&a.length>0&&(O=Math.min(...a.map(v=>v.low)),U=Math.max(...a.map(v=>v.high)));const $=new Map;t.forEach((v,D)=>{v.paneIndex===0&&!v.collapsed&&a&&a.length>0&&Object.entries(v.plots).forEach(([E,_])=>{const V=`${D}::${E}`,F=["background","barcolor","char"],G=_.options.style==="shape"&&(_.options.location==="abovebar"||_.options.location==="belowbar");if(F.includes(_.options.style)){$.has(V)||($.set(V,z),z++);return}if(_.options.style==="shape"&&!G){$.has(V)||($.set(V,z),z++);return}const R=[];if(_.data&&Object.values(_.data).forEach(N=>{typeof N=="number"&&!isNaN(N)&&isFinite(N)&&R.push(N)}),R.length>0){const N=Math.min(...R),W=Math.max(...R),it=W-N,et=U-O,K=N>=O*.5&&W<=U*1.5,st=it>et*.01;K&&st||$.has(V)||($.set(V,z),z++)}})});const B=$.size>0?z-1:0,X=new Set;$.forEach((v,D)=>{t.forEach(E=>{Object.entries(E.plots).forEach(([_,V])=>{`${E.id}::${_}`===D&&["background","barcolor","char"].includes(V.options.style)&&X.add(v)})})});for(let v=0;v<B;v++){const D=v+1,E=X.has(D);k.push({position:"left",scale:!E,min:E?0:Z.createMinFunction(p),max:E?1:Z.createMaxFunction(p),gridIndex:0,show:!1,splitLine:{show:!1},axisLine:{show:!1},axisLabel:{show:!1}})}const tt=z;b.forEach((v,D)=>{k.push({position:"right",scale:!0,min:Z.createMinFunction(p),max:Z.createMaxFunction(p),gridIndex:D+1,splitLine:{show:!v.isCollapsed,lineStyle:{color:"#334155",opacity:.3}},axisLabel:{show:!v.isCollapsed,color:"#94a3b8",fontFamily:i.fontFamily||"sans-serif",fontSize:10,formatter:E=>{if(i.yAxisLabelFormatter)return i.yAxisLabelFormatter(E);const _=i.yAxisDecimalPlaces!==void 0?i.yAxisDecimalPlaces:Z.autoDetectDecimals(a);return Z.formatValue(E,_)}},axisLine:{show:!v.isCollapsed,lineStyle:{color:"#334155"}}})});const J=[];return l&&((i.dataZoom?.zoomOnTouch??!0)&&J.push({type:"inside",xAxisIndex:I,start:o,end:c}),r==="top"?J.push({type:"slider",xAxisIndex:I,top:"1%",height:h+"%",start:o,end:c,borderColor:"#334155",textStyle:{color:"#cbd5e1"},brushSelect:!1}):J.push({type:"slider",xAxisIndex:I,bottom:"1%",height:h+"%",start:o,end:c,borderColor:"#334155",textStyle:{color:"#cbd5e1"},brushSelect:!1})),{grid:C,xAxis:m,yAxis:k,dataZoom:J,paneLayout:b,mainPaneHeight:x,mainPaneTop:g,pixelToPercent:u,overlayYAxisMap:$,separatePaneYAxisOffset:tt}}static calculateMaximized(e,t,i){return{grid:[],xAxis:[],yAxis:[],dataZoom:[],paneLayout:[],mainPaneHeight:0,mainPaneTop:0,pixelToPercent:0}}}class kt{render(e){const{seriesName:t,xAxisIndex:i,yAxisIndex:s,dataArray:n,colorArray:a,plotOptions:u}=e,p="#2962ff";return{name:t,type:"custom",xAxisIndex:i,yAxisIndex:s,renderItem:(d,f)=>{const l=d.dataIndex;if(l===0)return;const r=f.value(1),h=f.value(2);if(r===null||isNaN(r)||h===null||isNaN(h))return;const o=f.coord([l-1,h]),c=f.coord([l,r]);return{type:"line",shape:{x1:o[0],y1:o[1],x2:c[0],y2:c[1]},style:{stroke:a[l]||u.color||p,lineWidth:u.linewidth||1},silent:!0}},data:n.map((d,f)=>[f,d,f>0?n[f-1]:null])}}}class Pt{render(e){const{seriesName:t,xAxisIndex:i,yAxisIndex:s,dataArray:n,colorArray:a,plotOptions:u}=e,p="#2962ff";return{name:t,type:"custom",xAxisIndex:i,yAxisIndex:s,renderItem:(d,f)=>{const l=f.value(0),r=f.value(1);if(isNaN(r)||r===null)return;const h=f.coord([l,r]),o=f.size([1,0])[0];return{type:"line",shape:{x1:h[0]-o/2,y1:h[1],x2:h[0]+o/2,y2:h[1]},style:{stroke:a[d.dataIndex]||u.color||p,lineWidth:u.linewidth||1},silent:!0}},data:n.map((d,f)=>[f,d])}}}class bt{render(e){const{seriesName:t,xAxisIndex:i,yAxisIndex:s,dataArray:n,colorArray:a,plotOptions:u}=e;return{name:t,type:"bar",xAxisIndex:i,yAxisIndex:s,data:n.map((p,d)=>({value:p,itemStyle:a[d]?{color:a[d]}:void 0})),itemStyle:{color:u.color||"#2962ff"}}}}const ft=new Map;function Mt(y,e="#00da3c",t="64px"){if(typeof document>"u")return"";const i=`${y}-${e}-${t}`;if(ft.has(i))return ft.get(i);const s=document.createElement("canvas"),n=s.getContext("2d");if(s.width=32,s.height=32,n){n.font="bold "+t+" Arial",n.fillStyle=e,n.textAlign="center",n.textBaseline="middle",n.fillText(y,16,16);const a=s.toDataURL("image/png");return ft.set(i,a),a}return""}class xt{render(e){const{seriesName:t,xAxisIndex:i,yAxisIndex:s,dataArray:n,colorArray:a,plotOptions:u}=e,p="#2962ff",d=u.style;if(d==="char")return{name:t,type:"scatter",xAxisIndex:i,yAxisIndex:s,symbolSize:0,data:n.map((l,r)=>({value:[r,l],itemStyle:{opacity:0}})),silent:!0};const f=n.map((l,r)=>{if(l===null)return null;const h=a[r]||u.color||p,o={value:[r,l],itemStyle:{color:h}};return d==="cross"?(o.symbol=`image://${Mt("+",h,"24px")}`,o.symbolSize=16):(o.symbol="circle",o.symbolSize=6),o}).filter(l=>l!==null);return{name:t,type:"scatter",xAxisIndex:i,yAxisIndex:s,data:f}}}class vt{render(e){const{seriesName:t,xAxisIndex:i,yAxisIndex:s,dataArray:n,colorArray:a,optionsArray:u,plotOptions:p}=e,d="#2962ff",f=p.style==="candle",l=n.map((r,h)=>{if(r===null||!Array.isArray(r)||r.length!==4)return null;const[o,c,g,w]=r,A=u[h]||{},P=A.color||a[h]||p.color||d,x=A.wickcolor||p.wickcolor||P,b=A.bordercolor||p.bordercolor||x;return[h,o,w,g,c,P,x,b]}).filter(r=>r!==null);return{name:t,type:"custom",xAxisIndex:i,yAxisIndex:s,renderItem:(r,h)=>{const o=h.value(0),c=h.value(1),g=h.value(2),w=h.value(3),A=h.value(4),P=h.value(5),x=h.value(6),b=h.value(7);if(isNaN(c)||isNaN(g)||isNaN(w)||isNaN(A))return null;const C=h.coord([o,0])[0],I=h.coord([o,c])[1],m=h.coord([o,g])[1],M=h.coord([o,w])[1],k=h.coord([o,A])[1],S=h.size([1,0])[0]*.6;if(f){const L=Math.min(I,m),z=Math.max(I,m),O=Math.abs(m-I);return{type:"group",children:[{type:"line",shape:{x1:C,y1:k,x2:C,y2:L},style:{stroke:x,lineWidth:1}},{type:"line",shape:{x1:C,y1:z,x2:C,y2:M},style:{stroke:x,lineWidth:1}},{type:"rect",shape:{x:C-S/2,y:L,width:S,height:O||1},style:{fill:P,stroke:b,lineWidth:1}}]}}else{const L=S*.5;return{type:"group",children:[{type:"line",shape:{x1:C,y1:M,x2:C,y2:k},style:{stroke:P,lineWidth:1}},{type:"line",shape:{x1:C-L,y1:I,x2:C,y2:I},style:{stroke:P,lineWidth:1}},{type:"line",shape:{x1:C,y1:m,x2:C+L,y2:m},style:{stroke:P,lineWidth:1}}]}}},data:l}}}class at{static getShapeSymbol(e){switch(e){case"arrowdown":return"path://M12 24l-12-12h8v-12h8v12h8z";case"arrowup":return"path://M12 0l12 12h-8v12h-8v-12h-8z";case"circle":return"circle";case"cross":return"path://M11 2h2v9h9v2h-9v9h-2v-9h-9v-2h9z";case"diamond":return"diamond";case"flag":return"path://M6 2v20h2v-8h12l-2-6 2-6h-12z";case"labeldown":return"path://M2 1h20a1 1 0 0 1 1 1v14a1 1 0 0 1-1 1h-8l-2 3-2-3h-8a1 1 0 0 1-1-1v-14a1 1 0 0 1 1-1z";case"labelleft":return"path://M0 10l3-3v-5a1 1 0 0 1 1-1h18a1 1 0 0 1 1 1v16a1 1 0 0 1-1 1h-18a1 1 0 0 1-1-1v-5z";case"labelright":return"path://M24 10l-3-3v-5a1 1 0 0 0-1-1h-18a1 1 0 0 0-1 1v16a1 1 0 0 0 1 1h18a1 1 0 0 0 1-1v-5z";case"labelup":return"path://M12 1l2 3h8a1 1 0 0 1 1 1v14a1 1 0 0 1-1 1h-20a1 1 0 0 1-1-1v-14a1 1 0 0 1 1-1h8z";case"square":return"rect";case"triangledown":return"path://M12 21l-10-18h20z";case"triangleup":return"triangle";case"xcross":return"path://M19 6.41L17.59 5 12 10.59 6.41 5 5 6.41 10.59 12 5 17.59 6.41 19 12 13.41 17.59 19 19 17.59 13.41 12z";default:return"circle"}}static getShapeRotation(e){return 0}static getShapeSize(e,t,i){if(t!==void 0&&i!==void 0)return[t,i];let s;switch(e){case"tiny":s=8;break;case"small":s=12;break;case"normal":case"auto":s=16;break;case"large":s=24;break;case"huge":s=32;break;default:s=16}return t!==void 0?[t,t]:i!==void 0?[i,i]:s}static getLabelConfig(e,t){switch(t){case"abovebar":return{position:"top",distance:5};case"belowbar":return{position:"bottom",distance:5};case"top":return{position:"bottom",distance:5};case"bottom":return{position:"top",distance:5};case"absolute":default:return e==="labelup"||e==="labeldown"?{position:"inside",distance:0}:{position:"top",distance:5}}}}class Dt{render(e){const{seriesName:t,xAxisIndex:i,yAxisIndex:s,dataArray:n,colorArray:a,optionsArray:u,plotOptions:p,candlestickData:d}=e,f="#2962ff",l=n.map((r,h)=>{const o=u[h]||{},c=p,g=o.location||c.location||"absolute";if(g!=="absolute"&&!r||r==null)return null;const w=o.color||c.color||f,A=o.shape||c.shape||"circle",P=o.size||c.size||"normal",x=o.text||c.text,b=o.textcolor||c.textcolor||"white",C=o.width||c.width,I=o.height||c.height;let m=r,M=[0,0];g==="abovebar"?(d&&d[h]&&(m=d[h].high),M=[0,"-150%"]):g==="belowbar"?(d&&d[h]&&(m=d[h].low),M=[0,"150%"]):g==="top"?(m=r,M=[0,0]):g==="bottom"&&(m=r,M=[0,0]);const k=at.getShapeSymbol(A),S=at.getShapeSize(P,C,I),L=at.getShapeRotation(A);let z=S;A.includes("label")&&(Array.isArray(S)?z=[S[0]*2.5,S[1]*2.5]:z=S*2.5);const O=at.getLabelConfig(A,g);return{value:[h,m],symbol:k,symbolSize:z,symbolRotate:L,symbolOffset:M,itemStyle:{color:w},label:{show:!!x,position:O.position,distance:O.distance,formatter:x,color:b,fontSize:10,fontWeight:"bold"}}}).filter(r=>r!==null);return{name:t,type:"scatter",xAxisIndex:i,yAxisIndex:s,data:l}}}class zt{render(e){const{seriesName:t,xAxisIndex:i,yAxisIndex:s,dataArray:n,colorArray:a}=e;return{name:t,type:"custom",xAxisIndex:i,yAxisIndex:s,z:-10,renderItem:(u,p)=>{const d=p.value(0);if(isNaN(d))return;const f=p.coord([d,.5]),l=p.size([1,0])[0],r=u.coordSys,h=f[0]-l/2,o=a[u.dataIndex],c=p.value(1);if(!(!o||c===null||c===void 0||isNaN(c)))return{type:"rect",shape:{x:h,y:r.y,width:l,height:r.height},style:{fill:o,opacity:.3},silent:!0}},data:n.map((u,p)=>[p,u!=null&&!isNaN(u)?.5:null])}}}class wt{static parseColor(e){if(!e)return{color:"#888888",opacity:.2};const t=e.match(/rgba?\((\d+),\s*(\d+),\s*(\d+)(?:,\s*([\d.]+))?\)/);if(t){const i=t[1],s=t[2],n=t[3],a=t[4]?parseFloat(t[4]):1;return{color:`rgb(${i},${s},${n})`,opacity:a}}return{color:e,opacity:.3}}}class Lt{render(e){const{seriesName:t,xAxisIndex:i,yAxisIndex:s,plotOptions:n,plotDataArrays:a,indicatorId:u,plotName:p}=e,d=e.dataArray.length,f=n.plot1?`${u}::${n.plot1}`:null,l=n.plot2?`${u}::${n.plot2}`:null;if(!f||!l)return console.warn(`Fill plot "${p}" missing plot1 or plot2 reference`),null;const r=a?.get(f),h=a?.get(l);if(!r||!h)return console.warn(`Fill plot "${p}" references non-existent plots: ${n.plot1}, ${n.plot2}`),null;const{color:o,opacity:c}=wt.parseColor(n.color||"rgba(128, 128, 128, 0.2)"),g=[];for(let w=0;w<d;w++){const A=r[w],P=h[w],x=w>0?r[w-1]:null,b=w>0?h[w-1]:null;g.push([w,A,P,x,b])}return{name:t,type:"custom",xAxisIndex:i,yAxisIndex:s,z:1,renderItem:(w,A)=>{const P=w.dataIndex;if(P===0)return null;const x=A.value(1),b=A.value(2),C=A.value(3),I=A.value(4);if(x===null||b===null||C===null||I===null||isNaN(x)||isNaN(b)||isNaN(C)||isNaN(I))return null;const m=A.coord([P-1,C]),M=A.coord([P,x]),k=A.coord([P,b]),S=A.coord([P-1,I]);return{type:"polygon",shape:{points:[m,M,k,S]},style:{fill:o,opacity:c},silent:!0}},data:g}}}class Et{render(e){const{seriesName:t,xAxisIndex:i,yAxisIndex:s,dataArray:n,candlestickData:a,dataIndexOffset:u}=e,p=u||0,d=[];for(let l=0;l<n.length;l++){const r=n[l];if(!r)continue;const h=Array.isArray(r)?r:[r];for(const o of h)o&&typeof o=="object"&&!o._deleted&&d.push(o)}const f=d.map(l=>{const r=l.text||"",h=l.color||"#2962ff",o=l.textcolor||"#ffffff",c=l.yloc||"price",g=l.style||"style_label_down",w=l.size||"normal",A=l.textalign||"align_center",P=l.tooltip||"",x=this.styleToShape(g),b=l.xloc==="bar_index"?l.x+p:l.x;let C=l.y,I=[0,0];c==="abovebar"?(a&&a[b]&&(C=a[b].high),I=[0,"-150%"]):c==="belowbar"&&(a&&a[b]&&(C=a[b].low),I=[0,"150%"]);const m=at.getShapeSymbol(x),M=at.getShapeSize(w),k=this.getSizePx(w);let S;const L=x==="labeldown"||x==="labelup"||x==="labelleft"||x==="labelright";let z=[0,0];if(L){const B=r.length*k*.65,X=k*2.5,tt=Math.max(X,B+k*1.6),J=k*2.8,v=3/24;if(x==="labelleft"||x==="labelright"){const D=tt/(1-v);S=[D,J];const E=typeof I[0]=="string"?0:I[0];x==="labelleft"?(I=[E+D*.42,I[1]],z=[D*v*.5,0]):(I=[E-D*.42,I[1]],z=[-D*v*.5,0])}else{const D=J/(1-v);S=[tt,D],x==="labeldown"?(I=[I[0],typeof I[1]=="string"?I[1]:I[1]-D*.42],z=[0,-D*v*.5]):(I=[I[0],typeof I[1]=="string"?I[1]:I[1]+D*.42],z=[0,D*v*.5])}}else x==="none"?S=0:Array.isArray(M)?S=[M[0]*1.5,M[1]*1.5]:S=M*1.5;const O=this.getLabelPosition(g,c),U=O==="inside"||O.startsWith("inside"),$={value:[b,C],symbol:m,symbolSize:S,symbolOffset:I,itemStyle:{color:h},label:{show:!!r,position:O,distance:U?0:5,offset:z,formatter:r,color:o,fontSize:k,fontWeight:"bold",align:U?"center":A==="align_left"?"left":A==="align_right"?"right":"center",verticalAlign:"middle",padding:[2,6]}};return P&&($.tooltip={formatter:P}),$}).filter(l=>l!==null);return{name:t,type:"scatter",xAxisIndex:i,yAxisIndex:s,data:f,z:20}}styleToShape(e){switch(e.startsWith("style_")?e.substring(6):e){case"label_down":return"labeldown";case"label_up":return"labelup";case"label_left":return"labelleft";case"label_right":return"labelright";case"label_lower_left":return"labeldown";case"label_lower_right":return"labeldown";case"label_upper_left":return"labelup";case"label_upper_right":return"labelup";case"label_center":return"labeldown";case"circle":return"circle";case"square":return"square";case"diamond":return"diamond";case"flag":return"flag";case"arrowup":return"arrowup";case"arrowdown":return"arrowdown";case"cross":return"cross";case"xcross":return"xcross";case"triangleup":return"triangleup";case"triangledown":return"triangledown";case"text_outline":return"none";case"none":return"none";default:return"labeldown"}}getLabelPosition(e,t){switch(e.startsWith("style_")?e.substring(6):e){case"label_down":case"label_up":case"label_left":case"label_right":case"label_lower_left":case"label_lower_right":case"label_upper_left":case"label_upper_right":case"label_center":return"inside";case"text_outline":case"none":return t==="abovebar"?"top":t==="belowbar"?"bottom":"top";default:return t==="belowbar"?"bottom":"top"}}getSizePx(e){switch(e){case"tiny":return 8;case"small":return 9;case"normal":case"auto":return 10;case"large":return 12;case"huge":return 14;default:return 10}}}class Nt{render(e){const{seriesName:t,xAxisIndex:i,yAxisIndex:s,dataArray:n,dataIndexOffset:a}=e,u=a||0,p="#2962ff",d=[],f=[];for(let l=0;l<n.length;l++){const r=n[l];if(!r)continue;const h=Array.isArray(r)?r:[r];for(const o of h)if(o&&typeof o=="object"&&!o._deleted){d.push(o);const c=o.xloc==="bar_index"?u:0;f.push([o.x1+c,o.y1,o.x2+c,o.y2])}}return f.length===0?{name:t,type:"custom",xAxisIndex:i,yAxisIndex:s,data:[],silent:!0}:{name:t,type:"custom",xAxisIndex:i,yAxisIndex:s,renderItem:(l,r)=>{const h=l.dataIndex,o=d[h];if(!o||o._deleted)return;const c=r.value(0),g=r.value(1),w=r.value(2),A=r.value(3);let P=r.coord([c,g]),x=r.coord([w,A]);const b=o.extend||"none";if(b!=="none"){const k=l.coordSys,S=k.x,L=k.x+k.width,z=k.y,O=k.y+k.height;[P,x]=this.extendLine(P,x,b,S,L,z,O)}const C=[],I=o.color||p,m=o.width||1;C.push({type:"line",shape:{x1:P[0],y1:P[1],x2:x[0],y2:x[1]},style:{stroke:I,lineWidth:m,lineDash:this.getDashPattern(o.style)}});const M=o.style||"style_solid";if(M==="style_arrow_left"||M==="style_arrow_both"){const k=this.arrowHead(x,P,m,I);k&&C.push(k)}if(M==="style_arrow_right"||M==="style_arrow_both"){const k=this.arrowHead(P,x,m,I);k&&C.push(k)}return{type:"group",children:C}},data:f,z:15,silent:!0,emphasis:{disabled:!0}}}getDashPattern(e){switch(e){case"style_dotted":return[2,2];case"style_dashed":return[6,4];default:return}}extendLine(e,t,i,s,n,a,u){const p=t[0]-e[0],d=t[1]-e[1];if(p===0&&d===0)return[e,t];const f=(h,o)=>{let c=1/0;if(o[0]!==0){const g=o[0]>0?(n-h[0])/o[0]:(s-h[0])/o[0];c=Math.min(c,g)}if(o[1]!==0){const g=o[1]>0?(u-h[1])/o[1]:(a-h[1])/o[1];c=Math.min(c,g)}return isFinite(c)||(c=0),[h[0]+c*o[0],h[1]+c*o[1]]};let l=e,r=t;return(i==="right"||i==="both")&&(r=f(e,[p,d])),(i==="left"||i==="both")&&(l=f(t,[-p,-d])),[l,r]}arrowHead(e,t,i,s){const n=t[0]-e[0],a=t[1]-e[1],u=Math.sqrt(n*n+a*a);if(u<1)return null;const p=Math.max(8,i*4),d=n/u,f=a/u,l=t[0]-d*p,r=t[1]-f*p,h=-f*p*.4,o=d*p*.4;return{type:"polygon",shape:{points:[[t[0],t[1]],[l+h,r+o],[l-h,r-o]]},style:{fill:s}}}}class Tt{render(e){const{seriesName:t,xAxisIndex:i,yAxisIndex:s,dataArray:n,dataIndexOffset:a}=e,u=a||0,p=[],d=[];for(let f=0;f<n.length;f++){const l=n[f];if(!l)continue;const r=Array.isArray(l)?l:[l];for(const h of r){if(!h||typeof h!="object"||h._deleted)continue;const o=h.line1,c=h.line2;if(!o||!c||o._deleted||c._deleted)continue;p.push(h);const g=o.xloc==="bar_index"?u:0,w=c.xloc==="bar_index"?u:0;d.push([o.x1+g,o.y1,o.x2+g,o.y2,c.x1+w,c.y1,c.x2+w,c.y2])}}return d.length===0?{name:t,type:"custom",xAxisIndex:i,yAxisIndex:s,data:[],silent:!0}:{name:t,type:"custom",xAxisIndex:i,yAxisIndex:s,renderItem:(f,l)=>{const r=f.dataIndex,h=p[r];if(!h||h._deleted)return;const o=h.line1,c=h.line2;if(!o||!c||o._deleted||c._deleted)return;const g=l.value(0),w=l.value(1),A=l.value(2),P=l.value(3),x=l.value(4),b=l.value(5),C=l.value(6),I=l.value(7);let m=l.coord([g,w]),M=l.coord([A,P]),k=l.coord([x,b]),S=l.coord([C,I]);const L=o.extend||"none",z=c.extend||"none";if(L!=="none"||z!=="none"){const $=f.coordSys,B=$.x,X=$.x+$.width,tt=$.y,J=$.y+$.height;L!=="none"&&([m,M]=this.extendLine(m,M,L,B,X,tt,J)),z!=="none"&&([k,S]=this.extendLine(k,S,z,B,X,tt,J))}const{color:O,opacity:U}=wt.parseColor(h.color||"rgba(128, 128, 128, 0.2)");return{type:"polygon",shape:{points:[m,M,S,k]},style:{fill:O,opacity:U},silent:!0}},data:d,z:10,silent:!0,emphasis:{disabled:!0}}}extendLine(e,t,i,s,n,a,u){const p=t[0]-e[0],d=t[1]-e[1];if(p===0&&d===0)return[e,t];const f=(h,o)=>{let c=1/0;if(o[0]!==0){const g=o[0]>0?(n-h[0])/o[0]:(s-h[0])/o[0];c=Math.min(c,g)}if(o[1]!==0){const g=o[1]>0?(u-h[1])/o[1]:(a-h[1])/o[1];c=Math.min(c,g)}return isFinite(c)||(c=0),[h[0]+c*o[0],h[1]+c*o[1]]};let l=e,r=t;return(i==="right"||i==="both")&&(r=f(e,[p,d])),(i==="left"||i==="both")&&(l=f(t,[-p,-d])),[l,r]}}var $t=Object.defineProperty,Ft=(y,e,t)=>e in y?$t(y,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):y[e]=t,Ot=(y,e,t)=>(Ft(y,typeof e!="symbol"?e+"":e,t),t);const j=class{static register(e,t){this.renderers.set(e,t)}static get(e){return this.renderers.get(e)||this.renderers.get("line")}};Ot(j,"renderers",new Map),j.register("line",new kt),j.register("step",new Pt),j.register("histogram",new bt),j.register("columns",new bt),j.register("circles",new xt),j.register("cross",new xt),j.register("char",new xt),j.register("bar",new vt),j.register("candle",new vt),j.register("shape",new Dt),j.register("background",new zt),j.register("fill",new Lt),j.register("label",new Et),j.register("drawing_line",new Nt),j.register("linefill",new Tt);let _t=j;var Zt=Object.defineProperty,Gt=(y,e,t)=>e in y?Zt(y,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):y[e]=t,Wt=(y,e,t)=>(Gt(y,typeof e!="symbol"?e+"":e,t),t);const Ct=class gt{static buildCandlestickSeries(e,t,i){const s=t.upColor||"#00da3c",n=t.downColor||"#ec0000",a=e.map(p=>[p.open,p.close,p.low,p.high]);if(i&&i>a.length){const p=i-a.length;for(let d=0;d<p;d++)a.push(null)}let u;if(t.lastPriceLine?.visible!==!1&&e.length>0){const p=e[e.length-1],d=p.close,f=p.close>=p.open,l=t.lastPriceLine?.color||(f?s:n);let r=t.lastPriceLine?.lineStyle||"dashed";r.startsWith("linestyle_")&&(r=r.replace("linestyle_",""));const h=t.yAxisDecimalPlaces!==void 0?t.yAxisDecimalPlaces:Z.autoDetectDecimals(e);u={symbol:["none","none"],precision:h,data:[{yAxis:d,label:{show:!0,position:"end",formatter:o=>t.yAxisLabelFormatter?t.yAxisLabelFormatter(o.value):Z.formatValue(o.value,h),color:"#fff",backgroundColor:l,padding:[2,4],borderRadius:2,fontSize:11,fontWeight:"bold"},lineStyle:{color:l,type:r,width:1,opacity:.8}}],animation:!1,silent:!0}}return{type:"candlestick",name:t.title||"Market",data:a,itemStyle:{color:s,color0:n,borderColor:s,borderColor0:n},markLine:u,xAxisIndex:0,yAxisIndex:0,z:5}}static buildIndicatorSeries(e,t,i,s,n=0,a,u,p=1){const d=[],f=new Array(s).fill(null),l=new Map;return e.forEach((r,h)=>{r.collapsed||Object.keys(r.plots).sort((o,c)=>{const g=r.plots[o],w=r.plots[c],A=g.options.style==="fill",P=w.options.style==="fill";return A&&!P?1:!A&&P?-1:0}).forEach(o=>{const c=r.plots[o],g=`${h}::${o}`;let w=0,A=0;const P=c.options.overlay;if(r.paneIndex===0||P===!0)w=0,u&&u.has(g)?A=u.get(g):A=0;else{const m=i.findIndex(M=>M.index===r.paneIndex);m!==-1&&(w=m+1,A=p+m)}const x=new Array(s).fill(null),b=new Array(s).fill(null),C=new Array(s).fill(null);if(c.data?.forEach(m=>{const M=t.get(m.time);if(M!==void 0){const k=m.options?.offset??c.options.offset??0,S=M+n+k;if(S>=0&&S<s){let L=m.value;const z=m.options?.color;(z===null||z==="na"||z==="NaN"||typeof z=="number"&&isNaN(z))&&(L=null),x[S]=L,b[S]=z||c.options.color||gt.DEFAULT_COLOR,C[S]=m.options||{}}}}),l.set(`${h}::${o}`,x),c.options?.style?.startsWith("style_")&&(c.options.style=c.options.style.replace("style_","")),c.options.style==="barcolor"){c.data?.forEach(m=>{const M=t.get(m.time);if(M!==void 0){const k=m.options?.offset??c.options.offset??0,S=M+n+k;if(S>=0&&S<s){const L=m.options?.color||c.options.color||gt.DEFAULT_COLOR;!(L===null||L==="na"||L==="NaN"||typeof L=="number"&&isNaN(L))&&m.value!==null&&m.value!==void 0&&(f[S]=L)}}});return}const I=_t.get(c.options.style).render({seriesName:g,xAxisIndex:w,yAxisIndex:A,dataArray:x,colorArray:b,optionsArray:C,plotOptions:c.options,candlestickData:a,plotDataArrays:l,indicatorId:h,plotName:o,dataIndexOffset:n});I&&d.push(I)})}),{series:d,barColors:f}}};Wt(Ct,"DEFAULT_COLOR","#2962ff");let ct=Ct;class Ht{static build(e,t,i,s=!1,n=null){const a=[],u=e.pixelToPercent,p=e.mainPaneTop;if(!n||n==="main"){const d=10*u;if(a.push({type:"text",left:"8.5%",top:p+d+"%",z:10,style:{text:t.title||"Market",fill:t.titleColor||"#fff",font:`bold 16px ${t.fontFamily||"sans-serif"}`,textVerticalAlign:"top"}}),t.watermark!==!1){const l=e.mainPaneTop+e.mainPaneHeight;a.push({type:"text",right:"11%",top:l-3+"%",z:10,style:{text:"QFChart",fill:t.fontColor||"#cbd5e1",font:"bold 16px sans-serif",opacity:.1},cursor:"pointer",onclick:()=>{window.open("https://quantforge.org","_blank")}})}const f=[];if(t.controls?.collapse&&f.push({type:"group",children:[{type:"rect",shape:{width:20,height:20,r:2},style:{fill:"#334155",stroke:"#475569",lineWidth:1},onclick:()=>i("main","collapse")},{type:"text",style:{text:s?"+":"\u2212",fill:"#cbd5e1",font:`bold 14px ${t.fontFamily}`,x:10,y:10,textAlign:"center",textVerticalAlign:"middle"},silent:!0}]}),t.controls?.maximize){const l=n==="main",r=t.controls?.collapse?25:0;f.push({type:"group",x:r,children:[{type:"rect",shape:{width:20,height:20,r:2},style:{fill:"#334155",stroke:"#475569",lineWidth:1},onclick:()=>i("main","maximize")},{type:"text",style:{text:l?"\u2750":"\u25A1",fill:"#cbd5e1",font:`14px ${t.fontFamily}`,x:10,y:10,textAlign:"center",textVerticalAlign:"middle"},silent:!0}]})}if(t.controls?.fullscreen){let l=0;t.controls?.collapse&&(l+=25),t.controls?.maximize&&(l+=25),f.push({type:"group",x:l,children:[{type:"rect",shape:{width:20,height:20,r:2},style:{fill:"#334155",stroke:"#475569",lineWidth:1},onclick:()=>i("main","fullscreen")},{type:"text",style:{text:"\u26F6",fill:"#cbd5e1",font:`14px ${t.fontFamily}`,x:10,y:10,textAlign:"center",textVerticalAlign:"middle"},silent:!0}]})}f.length>0&&a.push({type:"group",right:"10.5%",top:p+"%",children:f})}return e.paneLayout.forEach(d=>{if(n&&d.indicatorId!==n)return;a.push({type:"text",left:"8.5%",top:d.top+10*u+"%",z:10,style:{text:d.indicatorId||"",fill:d.titleColor||"#fff",font:`bold 12px ${t.fontFamily||"sans-serif"}`,textVerticalAlign:"top"}});const f=[];if(d.controls?.collapse&&f.push({type:"group",children:[{type:"rect",shape:{width:20,height:20,r:2},style:{fill:"#334155",stroke:"#475569",lineWidth:1},onclick:()=>d.indicatorId&&i(d.indicatorId,"collapse")},{type:"text",style:{text:d.isCollapsed?"+":"\u2212",fill:"#cbd5e1",font:`bold 14px ${t.fontFamily}`,x:10,y:10,textAlign:"center",textVerticalAlign:"middle"},silent:!0}]}),d.controls?.maximize){const l=n===d.indicatorId,r=d.controls?.collapse?25:0;f.push({type:"group",x:r,children:[{type:"rect",shape:{width:20,height:20,r:2},style:{fill:"#334155",stroke:"#475569",lineWidth:1},onclick:()=>d.indicatorId&&i(d.indicatorId,"maximize")},{type:"text",style:{text:l?"\u2750":"\u25A1",fill:"#cbd5e1",font:`14px ${t.fontFamily}`,x:10,y:10,textAlign:"center",textVerticalAlign:"middle"},silent:!0}]})}f.length>0&&a.push({type:"group",right:"10.5%",top:d.top+"%",children:f})}),a}}class Rt{static format(e,t){if(!e||e.length===0)return"";const i=t.title||"Market",s=t.upColor||"#00da3c",n=t.downColor||"#ec0000",a=t.fontFamily||"sans-serif",u=e[0].axisValue;let p=`<div style="font-weight: bold; margin-bottom: 5px; color: #cbd5e1; font-family: ${a};">${u}</div>`;const d=e.find(l=>l.seriesType==="candlestick"),f=e.filter(l=>l.seriesType!=="candlestick");if(d){const[l,r,h,o,c]=d.value,g=h>=r?s:n;p+=`
18
- <div style="margin-bottom: 8px; font-family: ${a};">
19
- <div style="display:flex; justify-content:space-between; color:${g}; font-weight:bold;">
17
+ import*as G from"echarts";var kt=Object.defineProperty,Pt=(g,t,e)=>t in g?kt(g,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):g[t]=e,at=(g,t,e)=>(Pt(g,typeof t!="symbol"?t+"":t,e),e);class _t{constructor(t,e,i,s={}){at(this,"id"),at(this,"plots"),at(this,"paneIndex"),at(this,"height"),at(this,"collapsed"),at(this,"titleColor"),at(this,"controls"),this.id=t,this.plots=e,this.paneIndex=i,this.height=s.height,this.collapsed=s.collapsed||!1,this.titleColor=s.titleColor,this.controls=s.controls}toggleCollapse(){this.collapsed=!this.collapsed}isVisible(){return!this.collapsed}updateData(t){Object.keys(t).forEach(e=>{if(!this.plots[e])this.plots[e]=t[e];else{const i=this.plots[e],s=t[e];if(!i.data)return;s.options&&(i.options={...i.options,...s.options});const o=new Map;i.data?.forEach(l=>{o.set(l.time,l)}),s.data?.forEach(l=>{o.set(l.time,l)}),i.data=Array.from(o.values()).sort((l,d)=>l.time-d.time)}})}}class W{static createMinFunction(t){return e=>{const i=(e.max-e.min)*(t/100);return e.min-i}}static createMaxFunction(t){return e=>{const i=(e.max-e.min)*(t/100);return e.max+i}}static autoDetectDecimals(t){if(!t||t.length===0)return 2;const e=t[t.length-1].close;if(e===0||!isFinite(e)||isNaN(e))return 2;const i=Math.abs(e);if(i>=1)return 2;const s=Math.ceil(-Math.log10(i));return Math.min(s+4,10)}static formatValue(t,e){return typeof t=="number"?t.toFixed(e):String(t)}}class Ct{static calculate(t,e,i,s=!1,o=null,l){let d=0;t>0&&(d=1/t*100);const h=i.yAxisPadding!==void 0?i.yAxisPadding:5,p=Array.from(e.values()).map(k=>k.paneIndex).filter(k=>k>0).sort((k,z)=>k-z).filter((k,z,E)=>E.indexOf(k)===z),y=p.length>0,c=i.dataZoom?.visible??!0,u=i.dataZoom?.position??"top",a=i.dataZoom?.height??6,n=i.dataZoom?.start??0,f=i.dataZoom?.end??100;let r=8,x=92,w=-1;if(o)if(o==="main")w=0;else{const k=e.get(o);k&&(w=k.paneIndex)}if(w!==-1){const k=[],z=[],E=[],F=[],H=i.dataZoom?.start??50,Z=i.dataZoom?.end??100;(i.dataZoom?.zoomOnTouch??!0)&&F.push({type:"inside",xAxisIndex:"all",start:H,end:Z,filterMode:"weakFilter"});const Y=y?Math.max(...p):0,j=[];for(let N=0;N<=Y;N++){const T=N===w;k.push({left:"10%",right:"10%",top:T?"5%":"0%",height:T?"90%":"0%",show:T,containLabel:!1}),z.push({type:"category",gridIndex:N,data:[],show:T,axisLabel:{show:T,color:"#94a3b8",fontFamily:i.fontFamily},axisLine:{show:T,lineStyle:{color:"#334155"}},splitLine:{show:T,lineStyle:{color:"#334155",opacity:.5}}});let it,st;if(N===0&&w===0?(it=i.yAxisMin!==void 0&&i.yAxisMin!=="auto"?i.yAxisMin:W.createMinFunction(h),st=i.yAxisMax!==void 0&&i.yAxisMax!=="auto"?i.yAxisMax:W.createMaxFunction(h)):(it=W.createMinFunction(h),st=W.createMaxFunction(h)),E.push({position:"right",gridIndex:N,show:T,scale:!0,min:it,max:st,axisLabel:{show:T,color:"#94a3b8",fontFamily:i.fontFamily,formatter:q=>{if(i.yAxisLabelFormatter)return i.yAxisLabelFormatter(q);const ot=i.yAxisDecimalPlaces!==void 0?i.yAxisDecimalPlaces:W.autoDetectDecimals(l);return W.formatValue(q,ot)}},splitLine:{show:T,lineStyle:{color:"#334155",opacity:.5}}}),N>0){const q=Array.from(e.values()).find(ot=>ot.paneIndex===N);q&&j.push({index:N,height:T?90:0,top:T?5:0,isCollapsed:!1,indicatorId:q.id,titleColor:q.titleColor,controls:q.controls})}}return{grid:k,xAxis:z,yAxis:E,dataZoom:F,paneLayout:j,mainPaneHeight:w===0?90:0,mainPaneTop:w===0?5:0,pixelToPercent:d,overlayYAxisMap:new Map,separatePaneYAxisOffset:1}}c?u==="top"?(r=a+4,x=95):(x=100-a-2,r=8):(r=5,x=95);let S=5;t>0&&(S=20/t*100);let A=75,C=[];if(y){const k=p.map(Z=>{const Y=Array.from(e.values()).find(j=>j.paneIndex===Z);return{index:Z,requestedHeight:Y?.height,isCollapsed:Y?.collapsed??!1,indicatorId:Y?.id,titleColor:Y?.titleColor,controls:Y?.controls}}).map(Z=>({...Z,height:Z.isCollapsed?3:Z.requestedHeight!==void 0?Z.requestedHeight:15})),z=k.reduce((Z,Y)=>Z+Y.height,0),E=k.length*S,F=z+E;A=x-r-F,s?A=3:A<20&&(A=Math.max(A,10));let H=r+A+S;C=k.map(Z=>{const Y={index:Z.index,height:Z.height,top:H,isCollapsed:Z.isCollapsed,indicatorId:Z.indicatorId,titleColor:Z.titleColor,controls:Z.controls};return H+=Z.height+S,Y})}else A=x-r,s&&(A=3);const b=[];b.push({left:"10%",right:"10%",top:r+"%",height:A+"%",containLabel:!1}),C.forEach(k=>{b.push({left:"10%",right:"10%",top:k.top+"%",height:k.height+"%",containLabel:!1})});const v=[0,...C.map((k,z)=>z+1)],I=[],m=C.length===0;I.push({type:"category",data:[],gridIndex:0,scale:!0,axisLine:{onZero:!1,show:!s,lineStyle:{color:"#334155"}},splitLine:{show:!s,lineStyle:{color:"#334155",opacity:.5}},axisLabel:{show:!s,color:"#94a3b8",fontFamily:i.fontFamily||"sans-serif",formatter:k=>{if(i.yAxisLabelFormatter)return i.yAxisLabelFormatter(k);const z=i.yAxisDecimalPlaces!==void 0?i.yAxisDecimalPlaces:W.autoDetectDecimals(l);return W.formatValue(k,z)}},axisTick:{show:!s},axisPointer:{label:{show:m,fontSize:11,backgroundColor:"#475569"}}}),C.forEach((k,z)=>{const E=z===C.length-1;I.push({type:"category",gridIndex:z+1,data:[],axisLabel:{show:!1},axisLine:{show:!k.isCollapsed,lineStyle:{color:"#334155"}},axisTick:{show:!1},splitLine:{show:!1},axisPointer:{label:{show:E,fontSize:11,backgroundColor:"#475569"}}})});const P=[];let D,M;i.yAxisMin!==void 0&&i.yAxisMin!=="auto"?D=i.yAxisMin:D=W.createMinFunction(h),i.yAxisMax!==void 0&&i.yAxisMax!=="auto"?M=i.yAxisMax:M=W.createMaxFunction(h),P.push({position:"right",scale:!0,min:D,max:M,gridIndex:0,splitLine:{show:!s,lineStyle:{color:"#334155",opacity:.5}},axisLine:{show:!s,lineStyle:{color:"#334155"}},axisLabel:{show:!s,color:"#94a3b8",fontFamily:i.fontFamily||"sans-serif",formatter:k=>{if(i.yAxisLabelFormatter)return i.yAxisLabelFormatter(k);const z=i.yAxisDecimalPlaces!==void 0?i.yAxisDecimalPlaces:W.autoDetectDecimals(l);return W.formatValue(k,z)}}});let _=1,L=-1/0,R=1/0;l&&l.length>0&&(L=Math.min(...l.map(k=>k.low)),R=Math.max(...l.map(k=>k.high)));const O=new Map;e.forEach((k,z)=>{k.paneIndex===0&&!k.collapsed&&l&&l.length>0&&Object.entries(k.plots).forEach(([E,F])=>{const H=`${z}::${E}`,Z=["background","barcolor","char"],Y=F.options.style==="shape"&&(F.options.location==="abovebar"||F.options.location==="AboveBar"||F.options.location==="belowbar"||F.options.location==="BelowBar");if(Z.includes(F.options.style)){O.has(H)||(O.set(H,_),_++);return}if(F.options.style==="shape"&&!Y){O.has(H)||(O.set(H,_),_++);return}const j=[];if(F.data&&Object.values(F.data).forEach(N=>{typeof N=="number"&&!isNaN(N)&&isFinite(N)&&j.push(N)}),j.length>0){const N=Math.min(...j),T=Math.max(...j),it=T-N,st=R-L,q=N>=L*.5&&T<=R*1.5,ot=it>st*.01;q&&ot||O.has(H)||(O.set(H,_),_++)}})});const J=O.size>0?_-1:0,U=new Set;O.forEach((k,z)=>{e.forEach(E=>{Object.entries(E.plots).forEach(([F,H])=>{`${E.id}::${F}`===z&&["background","barcolor","char"].includes(H.options.style)&&U.add(k)})})});for(let k=0;k<J;k++){const z=k+1,E=U.has(z);P.push({position:"left",scale:!E,min:E?0:W.createMinFunction(h),max:E?1:W.createMaxFunction(h),gridIndex:0,show:!1,splitLine:{show:!1},axisLine:{show:!1},axisLabel:{show:!1}})}const tt=_;C.forEach((k,z)=>{P.push({position:"right",scale:!0,min:W.createMinFunction(h),max:W.createMaxFunction(h),gridIndex:z+1,splitLine:{show:!k.isCollapsed,lineStyle:{color:"#334155",opacity:.3}},axisLabel:{show:!k.isCollapsed,color:"#94a3b8",fontFamily:i.fontFamily||"sans-serif",fontSize:10,formatter:E=>{if(i.yAxisLabelFormatter)return i.yAxisLabelFormatter(E);const F=i.yAxisDecimalPlaces!==void 0?i.yAxisDecimalPlaces:W.autoDetectDecimals(l);return W.formatValue(E,F)}},axisLine:{show:!k.isCollapsed,lineStyle:{color:"#334155"}}})});const et=[];return c&&((i.dataZoom?.zoomOnTouch??!0)&&et.push({type:"inside",xAxisIndex:v,start:n,end:f,filterMode:"weakFilter"}),u==="top"?et.push({type:"slider",xAxisIndex:v,top:"1%",height:a+"%",start:n,end:f,borderColor:"#334155",textStyle:{color:"#cbd5e1"},brushSelect:!1,filterMode:"weakFilter"}):et.push({type:"slider",xAxisIndex:v,bottom:"1%",height:a+"%",start:n,end:f,borderColor:"#334155",textStyle:{color:"#cbd5e1"},brushSelect:!1,filterMode:"weakFilter"})),{grid:b,xAxis:I,yAxis:P,dataZoom:et,paneLayout:C,mainPaneHeight:A,mainPaneTop:r,pixelToPercent:d,overlayYAxisMap:O,separatePaneYAxisOffset:tt}}static calculateMaximized(t,e,i){return{grid:[],xAxis:[],yAxis:[],dataZoom:[],paneLayout:[],mainPaneHeight:0,mainPaneTop:0,pixelToPercent:0}}}class Mt{render(t){const{seriesName:e,xAxisIndex:i,yAxisIndex:s,dataArray:o,colorArray:l,plotOptions:d}=t,h="#2962ff";return{name:e,type:"custom",xAxisIndex:i,yAxisIndex:s,renderItem:(p,y)=>{const c=p.dataIndex;if(c===0)return;const u=y.value(1),a=y.value(2);if(u===null||isNaN(u)||a===null||isNaN(a))return;const n=y.coord([c-1,a]),f=y.coord([c,u]);return{type:"line",shape:{x1:n[0],y1:n[1],x2:f[0],y2:f[1]},style:{stroke:l[c]||d.color||h,lineWidth:d.linewidth||1},silent:!0}},data:o.map((p,y)=>[y,p,y>0?o[y-1]:null])}}}class Dt{render(t){const{seriesName:e,xAxisIndex:i,yAxisIndex:s,dataArray:o,colorArray:l,plotOptions:d}=t,h="#2962ff";return{name:e,type:"custom",xAxisIndex:i,yAxisIndex:s,renderItem:(p,y)=>{const c=y.value(0),u=y.value(1);if(isNaN(u)||u===null)return;const a=y.coord([c,u]),n=y.size([1,0])[0];return{type:"line",shape:{x1:a[0]-n/2,y1:a[1],x2:a[0]+n/2,y2:a[1]},style:{stroke:l[p.dataIndex]||d.color||h,lineWidth:d.linewidth||1},silent:!0}},data:o.map((p,y)=>[y,p])}}}class At{render(t){const{seriesName:e,xAxisIndex:i,yAxisIndex:s,dataArray:o,colorArray:l,plotOptions:d}=t;return{name:e,type:"bar",xAxisIndex:i,yAxisIndex:s,data:o.map((h,p)=>({value:h,itemStyle:l[p]?{color:l[p]}:void 0})),itemStyle:{color:d.color||"#2962ff"}}}}const mt=new Map;function zt(g,t="#00da3c",e="64px"){if(typeof document>"u")return"";const i=`${g}-${t}-${e}`;if(mt.has(i))return mt.get(i);const s=document.createElement("canvas"),o=s.getContext("2d");if(s.width=32,s.height=32,o){o.font="bold "+e+" Arial",o.fillStyle=t,o.textAlign="center",o.textBaseline="middle",o.fillText(g,16,16);const l=s.toDataURL("image/png");return mt.set(i,l),l}return""}class bt{render(t){const{seriesName:e,xAxisIndex:i,yAxisIndex:s,dataArray:o,colorArray:l,plotOptions:d}=t,h="#2962ff",p=d.style;if(p==="char")return{name:e,type:"scatter",xAxisIndex:i,yAxisIndex:s,symbolSize:0,data:o.map((c,u)=>({value:[u,c],itemStyle:{opacity:0}})),silent:!0};const y=o.map((c,u)=>{if(c===null)return null;const a=l[u]||d.color||h,n={value:[u,c],itemStyle:{color:a}};return p==="cross"?(n.symbol=`image://${zt("+",a,"24px")}`,n.symbolSize=16):(n.symbol="circle",n.symbolSize=6),n}).filter(c=>c!==null);return{name:e,type:"scatter",xAxisIndex:i,yAxisIndex:s,data:y}}}class It{render(t){const{seriesName:e,xAxisIndex:i,yAxisIndex:s,dataArray:o,colorArray:l,optionsArray:d,plotOptions:h}=t,p="#2962ff",y=h.style==="candle",c=o.map((u,a)=>{if(u===null||!Array.isArray(u)||u.length!==4)return null;const[n,f,r,x]=u,w=d[a]||{},S=w.color||l[a]||h.color||p,A=w.wickcolor||h.wickcolor||S,C=w.bordercolor||h.bordercolor||A;return[a,n,x,r,f,S,A,C]}).filter(u=>u!==null);return{name:e,type:"custom",xAxisIndex:i,yAxisIndex:s,renderItem:(u,a)=>{const n=a.value(0),f=a.value(1),r=a.value(2),x=a.value(3),w=a.value(4),S=a.value(5),A=a.value(6),C=a.value(7);if(isNaN(f)||isNaN(r)||isNaN(x)||isNaN(w))return null;const b=a.coord([n,0])[0],v=a.coord([n,f])[1],I=a.coord([n,r])[1],m=a.coord([n,x])[1],P=a.coord([n,w])[1],D=a.size([1,0])[0]*.6;if(y){const M=Math.min(v,I),_=Math.max(v,I),L=Math.abs(I-v);return{type:"group",children:[{type:"line",shape:{x1:b,y1:P,x2:b,y2:M},style:{stroke:A,lineWidth:1}},{type:"line",shape:{x1:b,y1:_,x2:b,y2:m},style:{stroke:A,lineWidth:1}},{type:"rect",shape:{x:b-D/2,y:M,width:D,height:L||1},style:{fill:S,stroke:C,lineWidth:1}}]}}else{const M=D*.5;return{type:"group",children:[{type:"line",shape:{x1:b,y1:m,x2:b,y2:P},style:{stroke:S,lineWidth:1}},{type:"line",shape:{x1:b-M,y1:v,x2:b,y2:v},style:{stroke:S,lineWidth:1}},{type:"line",shape:{x1:b,y1:I,x2:b+M,y2:I},style:{stroke:S,lineWidth:1}}]}}},data:c}}}class lt{static getShapeSymbol(t){switch(t){case"arrowdown":case"shape_arrow_down":return"path://M12 24l-12-12h8v-12h8v12h8z";case"arrowup":case"shape_arrow_up":return"path://M12 0l12 12h-8v12h-8v-12h-8z";case"circle":case"shape_circle":return"circle";case"cross":case"shape_cross":return"path://M11 2h2v9h9v2h-9v9h-2v-9h-9v-2h9z";case"diamond":case"shape_diamond":return"diamond";case"flag":case"shape_flag":return"path://M6 2v20h2v-8h12l-2-6 2-6h-12z";case"labeldown":case"shape_label_down":return"path://M2 1h20a1 1 0 0 1 1 1v14a1 1 0 0 1-1 1h-8l-2 3-2-3h-8a1 1 0 0 1-1-1v-14a1 1 0 0 1 1-1z";case"labelleft":case"shape_label_left":return"path://M0 10l3-3v-5a1 1 0 0 1 1-1h18a1 1 0 0 1 1 1v16a1 1 0 0 1-1 1h-18a1 1 0 0 1-1-1v-5z";case"labelright":case"shape_label_right":return"path://M24 10l-3-3v-5a1 1 0 0 0-1-1h-18a1 1 0 0 0-1 1v16a1 1 0 0 0 1 1h18a1 1 0 0 0 1-1v-5z";case"labelup":case"shape_label_up":return"path://M12 1l2 3h8a1 1 0 0 1 1 1v14a1 1 0 0 1-1 1h-20a1 1 0 0 1-1-1v-14a1 1 0 0 1 1-1h8z";case"square":case"shape_square":return"rect";case"triangledown":case"shape_triangle_down":return"path://M12 21l-10-18h20z";case"triangleup":case"shape_triangle_up":return"triangle";case"xcross":case"shape_xcross":return"path://M19 6.41L17.59 5 12 10.59 6.41 5 5 6.41 10.59 12 5 17.59 6.41 19 12 13.41 17.59 19 19 17.59 13.41 12z";default:return"circle"}}static getShapeRotation(t){return 0}static getShapeSize(t,e,i){if(e!==void 0&&i!==void 0)return[e,i];let s;switch(t){case"tiny":s=8;break;case"small":s=12;break;case"normal":case"auto":s=16;break;case"large":s=24;break;case"huge":s=32;break;default:s=16}return e!==void 0?[e,e]:i!==void 0?[i,i]:s}static getLabelConfig(t,e){switch(e){case"abovebar":case"AboveBar":return{position:"top",distance:5};case"belowbar":case"BelowBar":return{position:"bottom",distance:5};case"top":case"Top":return{position:"bottom",distance:5};case"bottom":case"Bottom":return{position:"top",distance:5};case"absolute":case"Absolute":default:return t==="labelup"||t==="labeldown"||t==="shape_label_up"||t==="shape_label_down"?{position:"inside",distance:0}:{position:"top",distance:5}}}}class $t{render(t){const{seriesName:e,xAxisIndex:i,yAxisIndex:s,dataArray:o,colorArray:l,optionsArray:d,plotOptions:h,candlestickData:p}=t,y="#2962ff",c=o.map((u,a)=>{const n=d[a]||{},f=h,r=n.location||f.location||"absolute";if(r!=="absolute"&&r!=="Absolute"&&!u||u==null)return null;const x=n.color||f.color||y,w=n.shape||f.shape||"circle",S=n.size||f.size||"normal",A=n.text||f.text,C=n.textcolor||f.textcolor||"white",b=n.width||f.width,v=n.height||f.height;let I=u,m=[0,0];r==="abovebar"||r==="AboveBar"||r==="ab"?(p&&p[a]&&(I=p[a].high),m=[0,"-150%"]):r==="belowbar"||r==="BelowBar"||r==="bl"?(p&&p[a]&&(I=p[a].low),m=[0,"150%"]):r==="top"||r==="Top"?(I=u,m=[0,0]):(r==="bottom"||r==="Bottom")&&(I=u,m=[0,0]);const P=lt.getShapeSymbol(w),D=lt.getShapeSize(S,b,v),M=lt.getShapeRotation(w);let _=D;w.includes("label")&&(Array.isArray(D)?_=[D[0]*2.5,D[1]*2.5]:_=D*2.5);const L=lt.getLabelConfig(w,r);return{value:[a,I],symbol:P,symbolSize:_,symbolRotate:M,symbolOffset:m,itemStyle:{color:x},label:{show:!!A,position:L.position,distance:L.distance,formatter:A,color:C,fontSize:10,fontWeight:"bold"}}}).filter(u=>u!==null);return{name:e,type:"scatter",xAxisIndex:i,yAxisIndex:s,data:c}}}class Lt{render(t){const{seriesName:e,xAxisIndex:i,yAxisIndex:s,dataArray:o,colorArray:l}=t;return{name:e,type:"custom",xAxisIndex:i,yAxisIndex:s,z:-10,renderItem:(d,h)=>{const p=h.value(0);if(isNaN(p))return;const y=h.coord([p,.5]),c=h.size([1,0])[0],u=d.coordSys,a=y[0]-c/2,n=l[d.dataIndex],f=h.value(1);if(!(!n||f===null||f===void 0||isNaN(f)))return{type:"rect",shape:{x:a,y:u.y,width:c,height:u.height},style:{fill:n,opacity:.3},silent:!0}},data:o.map((d,h)=>[h,d!=null&&!isNaN(d)?.5:null])}}}class rt{static parseColor(t){if(!t)return{color:"#888888",opacity:.2};const e=t.match(/rgba?\((\d+),\s*(\d+),\s*(\d+)(?:,\s*([\d.]+))?\)/);if(e){const s=e[1],o=e[2],l=e[3],d=e[4]?parseFloat(e[4]):1;return{color:`rgb(${s},${o},${l})`,opacity:d}}const i=t.match(/^#([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})$/);if(i){const s=parseInt(i[1],16),o=parseInt(i[2],16),l=parseInt(i[3],16),d=parseInt(i[4],16)/255;return{color:`rgb(${s},${o},${l})`,opacity:d}}return{color:t,opacity:.3}}static toRgba(t,e){const i=t.match(/rgb\((\d+),\s*(\d+),\s*(\d+)\)/);if(i)return`rgba(${i[1]},${i[2]},${i[3]},${e})`;const s=t.match(/^#([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})$/);if(s){const l=parseInt(s[1],16),d=parseInt(s[2],16),h=parseInt(s[3],16);return`rgba(${l},${d},${h},${e})`}const o=t.match(/^#([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})$/);if(o){const l=parseInt(o[1],16),d=parseInt(o[2],16),h=parseInt(o[3],16);return`rgba(${l},${d},${h},${e})`}return t}}class Et{render(t){const{seriesName:e,xAxisIndex:i,yAxisIndex:s,plotOptions:o,plotDataArrays:l,indicatorId:d,plotName:h,optionsArray:p}=t,y=t.dataArray.length,c=o.plot1?`${d}::${o.plot1}`:null,u=o.plot2?`${d}::${o.plot2}`:null;if(!c||!u)return console.warn(`Fill plot "${h}" missing plot1 or plot2 reference`),null;const a=l?.get(c),n=l?.get(u);if(!a||!n)return console.warn(`Fill plot "${h}" references non-existent plots: ${o.plot1}, ${o.plot2}`),null;if(o.gradient===!0)return this.renderGradientFill(e,i,s,a,n,y,p,o);const{color:f,opacity:r}=rt.parseColor(o.color||"rgba(128, 128, 128, 0.2)"),x=[];for(let w=0;w<y;w++){const S=a[w],A=n[w],C=w>0?a[w-1]:null,b=w>0?n[w-1]:null;x.push([w,S,A,C,b])}return{name:e,type:"custom",xAxisIndex:i,yAxisIndex:s,z:1,renderItem:(w,S)=>{const A=w.dataIndex;if(A===0)return null;const C=S.value(1),b=S.value(2),v=S.value(3),I=S.value(4);if(C===null||b===null||v===null||I===null||isNaN(C)||isNaN(b)||isNaN(v)||isNaN(I))return null;const m=S.coord([A-1,v]),P=S.coord([A,C]),D=S.coord([A,b]),M=S.coord([A-1,I]);return{type:"polygon",shape:{points:[m,P,D,M]},style:{fill:f,opacity:r},silent:!0}},data:x}}renderGradientFill(t,e,i,s,o,l,d,h){const p=[];for(let c=0;c<l;c++){const u=d?.[c];if(u&&u.top_color!==void 0){const a=rt.parseColor(u.top_color),n=rt.parseColor(u.bottom_color);p[c]={topColor:a.color,topOpacity:a.opacity,bottomColor:n.color,bottomOpacity:n.opacity}}else p[c]={topColor:"rgba(128,128,128,0.2)",topOpacity:.2,bottomColor:"rgba(128,128,128,0.2)",bottomOpacity:.2}}const y=[];for(let c=0;c<l;c++){const u=s[c],a=o[c],n=c>0?s[c-1]:null,f=c>0?o[c-1]:null;y.push([c,u,a,n,f])}return{name:t,type:"custom",xAxisIndex:e,yAxisIndex:i,z:1,renderItem:(c,u)=>{const a=c.dataIndex;if(a===0)return null;const n=u.value(1),f=u.value(2),r=u.value(3),x=u.value(4);if(n===null||f===null||r===null||x===null||isNaN(n)||isNaN(f)||isNaN(r)||isNaN(x))return null;const w=u.coord([a-1,r]),S=u.coord([a,n]),A=u.coord([a,f]),C=u.coord([a-1,x]),b=p[a]||p[a-1];if(!b)return null;const v=rt.toRgba(b.topColor,b.topOpacity),I=rt.toRgba(b.bottomColor,b.bottomOpacity),m=n>=f;return{type:"polygon",shape:{points:[w,S,A,C]},style:{fill:{type:"linear",x:0,y:0,x2:0,y2:1,colorStops:[{offset:0,color:m?v:I},{offset:1,color:m?I:v}]}},silent:!0}},data:y}}}class Ft{render(t){const{seriesName:e,xAxisIndex:i,yAxisIndex:s,dataArray:o,candlestickData:l,dataIndexOffset:d}=t,h=d||0,p=[];for(let c=0;c<o.length;c++){const u=o[c];if(!u)continue;const a=Array.isArray(u)?u:[u];for(const n of a)n&&typeof n=="object"&&!n._deleted&&p.push(n)}const y=p.map(c=>{const u=c.text||"",a=c.color||"#2962ff",n=c.textcolor||"#ffffff",f=c.yloc||"price",r=c.style||"style_label_down",x=c.size||"normal",w=c.textalign||"align_center",S=c.tooltip||"",A=this.styleToShape(r),C=c.xloc==="bar_index"||c.xloc==="bi"?c.x+h:c.x;let b=c.y,v=[0,0];f==="abovebar"||f==="AboveBar"||f==="ab"?(l&&l[C]&&(b=l[C].high),v=[0,"-150%"]):(f==="belowbar"||f==="BelowBar"||f==="bl")&&(l&&l[C]&&(b=l[C].low),v=[0,"150%"]);const I=lt.getShapeSymbol(A),m=lt.getShapeSize(x),P=this.getSizePx(x);let D;const M=A==="labeldown"||A==="shape_label_down"||A==="labelup"||A==="shape_label_up"||A==="labelleft"||A==="labelright";let _=[0,0];if(M){const J=u.length*P*.65,U=P*2.5,tt=Math.max(U,J+P*1.6),et=P*2.8,k=3/24;if(A==="labelleft"||A==="labelright"){const z=tt/(1-k);D=[z,et];const E=typeof v[0]=="string"?0:v[0];A==="labelleft"?(v=[E+z*.42,v[1]],_=[z*k*.5,0]):(v=[E-z*.42,v[1]],_=[-z*k*.5,0])}else{const z=et/(1-k);D=[tt,z],A==="labeldown"?(v=[v[0],typeof v[1]=="string"?v[1]:v[1]-z*.42],_=[0,-z*k*.5]):(v=[v[0],typeof v[1]=="string"?v[1]:v[1]+z*.42],_=[0,z*k*.5])}}else A==="none"?D=0:Array.isArray(m)?D=[m[0]*1.5,m[1]*1.5]:D=m*1.5;const L=this.getLabelPosition(r,f),R=L==="inside"||L.startsWith("inside"),O={value:[C,b],symbol:I,symbolSize:D,symbolOffset:v,itemStyle:{color:a},label:{show:!!u,position:L,distance:R?0:5,offset:_,formatter:u,color:n,fontSize:P,fontWeight:"bold",align:R?"center":w==="align_left"||w==="left"?"left":w==="align_right"||w==="right"?"right":"center",verticalAlign:"middle",padding:[2,6]}};return S&&(O.tooltip={formatter:S}),O}).filter(c=>c!==null);return{name:e,type:"scatter",xAxisIndex:i,yAxisIndex:s,data:y,z:20}}styleToShape(t){switch(t.startsWith("style_")?t.substring(6):t){case"label_down":return"labeldown";case"label_up":return"labelup";case"label_left":return"labelleft";case"label_right":return"labelright";case"label_lower_left":return"labeldown";case"label_lower_right":return"labeldown";case"label_upper_left":return"labelup";case"label_upper_right":return"labelup";case"label_center":return"labeldown";case"circle":return"circle";case"square":return"square";case"diamond":return"diamond";case"flag":return"flag";case"arrowup":return"arrowup";case"arrowdown":return"arrowdown";case"cross":return"cross";case"xcross":return"xcross";case"triangleup":return"triangleup";case"triangledown":return"triangledown";case"text_outline":return"none";case"none":return"none";default:return"labeldown"}}getLabelPosition(t,e){switch(t.startsWith("style_")?t.substring(6):t){case"label_down":case"label_up":case"label_left":case"label_right":case"label_lower_left":case"label_lower_right":case"label_upper_left":case"label_upper_right":case"label_center":return"inside";case"text_outline":case"none":return e==="abovebar"||e==="AboveBar"||e==="ab"?"top":e==="belowbar"||e==="BelowBar"||e==="bl"?"bottom":"top";default:return e==="belowbar"||e==="BelowBar"||e==="bl"?"bottom":"top"}}getSizePx(t){switch(t){case"tiny":return 8;case"small":return 9;case"normal":case"auto":return 10;case"large":return 12;case"huge":return 14;default:return 10}}}class Nt{render(t){const{seriesName:e,xAxisIndex:i,yAxisIndex:s,dataArray:o,dataIndexOffset:l}=t,d=l||0,h="#2962ff",p=[];for(let n=0;n<o.length;n++){const f=o[n];if(!f)continue;const r=Array.isArray(f)?f:[f];for(const x of r)x&&typeof x=="object"&&!x._deleted&&p.push(x)}if(p.length===0)return{name:e,type:"custom",xAxisIndex:i,yAxisIndex:s,data:[],silent:!0};let y=1/0,c=-1/0;for(const n of p)n.y1<y&&(y=n.y1),n.y1>c&&(c=n.y1),n.y2<y&&(y=n.y2),n.y2>c&&(c=n.y2);const u=(t.candlestickData?.length||0)+d,a=Math.max(0,u-1);return{name:e,type:"custom",xAxisIndex:i,yAxisIndex:s,renderItem:(n,f)=>{const r=[];for(const x of p){if(x._deleted)continue;const w=x.xloc==="bar_index"||x.xloc==="bi"?d:0;let S=f.coord([x.x1+w,x.y1]),A=f.coord([x.x2+w,x.y2]);const C=x.extend||"none";if(C!=="none"){const m=n.coordSys;[S,A]=this.extendLine(S,A,C,m.x,m.x+m.width,m.y,m.y+m.height)}const b=x.color||h,v=x.width||1;r.push({type:"line",shape:{x1:S[0],y1:S[1],x2:A[0],y2:A[1]},style:{stroke:b,lineWidth:v,lineDash:this.getDashPattern(x.style)}});const I=x.style||"style_solid";if(I==="style_arrow_left"||I==="style_arrow_both"){const m=this.arrowHead(A,S,v,b);m&&r.push(m)}if(I==="style_arrow_right"||I==="style_arrow_both"){const m=this.arrowHead(S,A,v,b);m&&r.push(m)}}return{type:"group",children:r}},data:[[0,a,y,c]],clip:!0,encode:{x:[0,1],y:[2,3]},z:15,silent:!0,emphasis:{disabled:!0}}}getDashPattern(t){switch(t){case"style_dotted":return[2,2];case"style_dashed":return[6,4];default:return}}extendLine(t,e,i,s,o,l,d){const h=e[0]-t[0],p=e[1]-t[1];if(h===0&&p===0)return[t,e];const y=(a,n)=>{let f=1/0;if(n[0]!==0){const r=n[0]>0?(o-a[0])/n[0]:(s-a[0])/n[0];f=Math.min(f,r)}if(n[1]!==0){const r=n[1]>0?(d-a[1])/n[1]:(l-a[1])/n[1];f=Math.min(f,r)}return isFinite(f)||(f=0),[a[0]+f*n[0],a[1]+f*n[1]]};let c=t,u=e;return(i==="right"||i==="both")&&(u=y(t,[h,p])),(i==="left"||i==="both")&&(c=y(e,[-h,-p])),[c,u]}arrowHead(t,e,i,s){const o=e[0]-t[0],l=e[1]-t[1],d=Math.sqrt(o*o+l*l);if(d<1)return null;const h=Math.max(8,i*4),p=o/d,y=l/d,c=e[0]-p*h,u=e[1]-y*h,a=-y*h*.4,n=p*h*.4;return{type:"polygon",shape:{points:[[e[0],e[1]],[c+a,u+n],[c-a,u-n]]},style:{fill:s}}}}class Tt{render(t){const{seriesName:e,xAxisIndex:i,yAxisIndex:s,dataArray:o,dataIndexOffset:l}=t,d=l||0,h=[];for(let a=0;a<o.length;a++){const n=o[a];if(!n)continue;const f=Array.isArray(n)?n:[n];for(const r of f){if(!r||typeof r!="object"||r._deleted)continue;const x=r.line1,w=r.line2;!x||!w||x._deleted||w._deleted||h.push(r)}}if(h.length===0)return{name:e,type:"custom",xAxisIndex:i,yAxisIndex:s,data:[],silent:!0};let p=1/0,y=-1/0;for(const a of h)for(const n of[a.line1.y1,a.line1.y2,a.line2.y1,a.line2.y2])n<p&&(p=n),n>y&&(y=n);const c=(t.candlestickData?.length||0)+d,u=Math.max(0,c-1);return{name:e,type:"custom",xAxisIndex:i,yAxisIndex:s,renderItem:(a,n)=>{const f=[];for(const r of h){if(r._deleted)continue;const x=r.line1,w=r.line2;if(!x||!w||x._deleted||w._deleted)continue;const S=x.xloc==="bar_index"||x.xloc==="bi"?d:0,A=w.xloc==="bar_index"||w.xloc==="bi"?d:0;let C=n.coord([x.x1+S,x.y1]),b=n.coord([x.x2+S,x.y2]),v=n.coord([w.x1+A,w.y1]),I=n.coord([w.x2+A,w.y2]);const m=x.extend||"none",P=w.extend||"none";if(m!=="none"||P!=="none"){const _=a.coordSys,L=_.x,R=_.x+_.width,O=_.y,J=_.y+_.height;m!=="none"&&([C,b]=this.extendLine(C,b,m,L,R,O,J)),P!=="none"&&([v,I]=this.extendLine(v,I,P,L,R,O,J))}const{color:D,opacity:M}=rt.parseColor(r.color||"rgba(128, 128, 128, 0.2)");f.push({type:"polygon",shape:{points:[C,b,I,v]},style:{fill:D,opacity:M},silent:!0})}return{type:"group",children:f}},data:[[0,u,p,y]],clip:!0,encode:{x:[0,1],y:[2,3]},z:10,silent:!0,emphasis:{disabled:!0}}}extendLine(t,e,i,s,o,l,d){const h=e[0]-t[0],p=e[1]-t[1];if(h===0&&p===0)return[t,e];const y=(a,n)=>{let f=1/0;if(n[0]!==0){const r=n[0]>0?(o-a[0])/n[0]:(s-a[0])/n[0];f=Math.min(f,r)}if(n[1]!==0){const r=n[1]>0?(d-a[1])/n[1]:(l-a[1])/n[1];f=Math.min(f,r)}return isFinite(f)||(f=0),[a[0]+f*n[0],a[1]+f*n[1]]};let c=t,u=e;return(i==="right"||i==="both")&&(u=y(t,[h,p])),(i==="left"||i==="both")&&(c=y(e,[-h,-p])),[c,u]}}class Ot{render(t){const{seriesName:e,xAxisIndex:i,yAxisIndex:s,dataArray:o,dataIndexOffset:l}=t,d=l||0,h=[];for(let a=0;a<o.length;a++){const n=o[a];if(!n)continue;const f=Array.isArray(n)?n:[n];for(const r of f)r&&typeof r=="object"&&!r._deleted&&r.points&&r.points.length>=2&&h.push(r)}if(h.length===0)return{name:e,type:"custom",xAxisIndex:i,yAxisIndex:s,data:[],silent:!0};let p=1/0,y=-1/0;for(const a of h)for(const n of a.points){const f=n.price??0;f<p&&(p=f),f>y&&(y=f)}const c=(t.candlestickData?.length||0)+d,u=Math.max(0,c-1);return{name:e,type:"custom",xAxisIndex:i,yAxisIndex:s,renderItem:(a,n)=>{const f=[];for(const r of h){if(r._deleted)continue;const x=r.points;if(!x||x.length<2)continue;const w=r.xloc==="bi"||r.xloc==="bar_index",S=w?d:0,A=[];for(const I of x){const m=w?(I.index??0)+S:I.time??0,P=I.price??0;A.push(n.coord([m,P]))}if(A.length<2)continue;const C=r.line_color||"#2962ff",b=r.line_width||1,v=this.getDashPattern(r.line_style);if(r.fill_color&&r.fill_color!==""&&r.fill_color!=="na"){const{color:I,opacity:m}=rt.parseColor(r.fill_color);if(r.curved){const P=this.buildCurvedPath(A,r.closed);f.push({type:"path",shape:{pathData:P+" Z"},style:{fill:I,opacity:m,stroke:"none"},silent:!0})}else f.push({type:"polygon",shape:{points:A},style:{fill:I,opacity:m,stroke:"none"},silent:!0})}if(r.curved){const I=this.buildCurvedPath(A,r.closed);f.push({type:"path",shape:{pathData:I},style:{fill:"none",stroke:C,lineWidth:b,lineDash:v},silent:!0})}else{const I=r.closed?[...A,A[0]]:A;f.push({type:"polyline",shape:{points:I},style:{fill:"none",stroke:C,lineWidth:b,lineDash:v},silent:!0})}}return{type:"group",children:f}},data:[[0,u,p,y]],clip:!0,encode:{x:[0,1],y:[2,3]},z:12,silent:!0,emphasis:{disabled:!0}}}buildCurvedPath(t,e){const i=t.length;if(i<2)return"";if(i===2)return`M ${t[0][0]} ${t[0][1]} L ${t[1][0]} ${t[1][1]}`;const s=.5;let o=`M ${t[0][0]} ${t[0][1]}`;const l=h=>e?t[(h%i+i)%i]:h<0?t[0]:h>=i?t[i-1]:t[h],d=e?i:i-1;for(let h=0;h<d;h++){const p=l(h-1),y=l(h),c=l(h+1),u=l(h+2),a=y[0]+(c[0]-p[0])*s/3,n=y[1]+(c[1]-p[1])*s/3,f=c[0]-(u[0]-y[0])*s/3,r=c[1]-(u[1]-y[1])*s/3;o+=` C ${a} ${n}, ${f} ${r}, ${c[0]} ${c[1]}`}return e&&(o+=" Z"),o}getDashPattern(t){switch(t){case"style_dotted":return[2,2];case"style_dashed":return[6,4];default:return}}}function wt(g){if(!g||typeof g!="string")return g;if(g.startsWith("#")){const t=g.slice(1);if(t.length===8){const e=parseInt(t.slice(0,2),16),i=parseInt(t.slice(2,4),16),s=parseInt(t.slice(4,6),16),o=parseInt(t.slice(6,8),16)/255;return`rgba(${e},${i},${s},${o.toFixed(3)})`}}return g}class Zt{render(t){const{seriesName:e,xAxisIndex:i,yAxisIndex:s,dataArray:o,dataIndexOffset:l}=t,d=l||0,h=[];for(let a=0;a<o.length;a++){const n=o[a];if(!n)continue;const f=Array.isArray(n)?n:[n];for(const r of f)r&&typeof r=="object"&&!r._deleted&&h.push(r)}if(h.length===0)return{name:e,type:"custom",xAxisIndex:i,yAxisIndex:s,data:[],silent:!0};let p=1/0,y=-1/0;for(const a of h)a.top<p&&(p=a.top),a.top>y&&(y=a.top),a.bottom<p&&(p=a.bottom),a.bottom>y&&(y=a.bottom);const c=(t.candlestickData?.length||0)+d,u=Math.max(0,c-1);return{name:e,type:"custom",xAxisIndex:i,yAxisIndex:s,renderItem:(a,n)=>{const f=[];for(const r of h){if(r._deleted)continue;const x=r.xloc==="bar_index"||r.xloc==="bi"?d:0,w=n.coord([r.left+x,r.top]),S=n.coord([r.right+x,r.bottom]);let A=w[0],C=w[1],b=S[0]-w[0],v=S[1]-w[1];const I=r.extend||"none";if(I!=="none"){const M=a.coordSys;(I==="left"||I==="both")&&(A=M.x,b=I==="both"?M.width:S[0]-M.x),(I==="right"||I==="both")&&I==="right"&&(b=M.x+M.width-w[0])}const m=wt(r.bgcolor)||"#2962ff";f.push({type:"rect",shape:{x:A,y:C,width:b,height:v},style:{fill:m}});const P=wt(r.border_color)||"#2962ff",D=r.border_width??1;if(D>0&&f.push({type:"rect",shape:{x:A,y:C,width:b,height:v},style:{fill:"none",stroke:P,lineWidth:D,lineDash:this.getDashPattern(r.border_style)}}),r.text){const M=this.getTextX(A,b,r.text_halign),_=this.getTextY(C,v,r.text_valign);f.push({type:"text",style:{x:M,y:_,text:r.text,fill:wt(r.text_color)||"#000000",fontSize:this.getSizePixels(r.text_size),fontFamily:r.text_font_family==="monospace"?"monospace":"sans-serif",fontWeight:r.text_formatting==="format_bold"?"bold":"normal",fontStyle:r.text_formatting==="format_italic"?"italic":"normal",textAlign:this.mapHAlign(r.text_halign),textVerticalAlign:this.mapVAlign(r.text_valign)}})}}return{type:"group",children:f}},data:[[0,u,p,y]],clip:!0,encode:{x:[0,1],y:[2,3]},z:14,silent:!0,emphasis:{disabled:!0}}}getDashPattern(t){switch(t){case"style_dotted":return[2,2];case"style_dashed":return[6,4];default:return}}getSizePixels(t){if(typeof t=="number"&&t>0)return t;switch(t){case"auto":case"size.auto":return 12;case"tiny":case"size.tiny":return 8;case"small":case"size.small":return 10;case"normal":case"size.normal":return 14;case"large":case"size.large":return 20;case"huge":case"size.huge":return 36;default:return 12}}mapHAlign(t){switch(t){case"left":case"text.align_left":return"left";case"right":case"text.align_right":return"right";case"center":case"text.align_center":default:return"center"}}mapVAlign(t){switch(t){case"top":case"text.align_top":return"top";case"bottom":case"text.align_bottom":return"bottom";case"center":case"text.align_center":default:return"middle"}}getTextX(t,e,i){switch(i){case"left":case"text.align_left":return t+4;case"right":case"text.align_right":return t+e-4;case"center":case"text.align_center":default:return t+e/2}}getTextY(t,e,i){switch(i){case"top":case"text.align_top":return t+4;case"bottom":case"text.align_bottom":return t+e-4;case"center":case"text.align_center":default:return t+e/2}}}var Wt=Object.defineProperty,Gt=(g,t,e)=>t in g?Wt(g,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):g[t]=e,Ht=(g,t,e)=>(Gt(g,typeof t!="symbol"?t+"":t,e),e);const B=class{static register(t,e){this.renderers.set(t,e)}static get(t){return this.renderers.get(t)||this.renderers.get("line")}};Ht(B,"renderers",new Map),B.register("line",new Mt),B.register("step",new Dt),B.register("histogram",new At),B.register("columns",new At),B.register("circles",new bt),B.register("cross",new bt),B.register("char",new bt),B.register("bar",new It),B.register("candle",new It),B.register("shape",new $t),B.register("background",new Lt),B.register("fill",new Et),B.register("label",new Ft),B.register("drawing_line",new Nt),B.register("linefill",new Tt),B.register("drawing_polyline",new Ot),B.register("drawing_box",new Zt);let Bt=B;var Rt=Object.defineProperty,Yt=(g,t,e)=>t in g?Rt(g,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):g[t]=e,jt=(g,t,e)=>(Yt(g,typeof t!="symbol"?t+"":t,e),e);const St=class vt{static buildCandlestickSeries(t,e,i){const s=e.upColor||"#00da3c",o=e.downColor||"#ec0000",l=t.map(h=>[h.open,h.close,h.low,h.high]);if(i&&i>l.length){const h=i-l.length;for(let p=0;p<h;p++)l.push(null)}let d;if(e.lastPriceLine?.visible!==!1&&t.length>0){const h=t[t.length-1],p=h.close,y=h.close>=h.open,c=e.lastPriceLine?.color||(y?s:o);let u=e.lastPriceLine?.lineStyle||"dashed";u.startsWith("linestyle_")&&(u=u.replace("linestyle_",""));const a=e.yAxisDecimalPlaces!==void 0?e.yAxisDecimalPlaces:W.autoDetectDecimals(t);d={symbol:["none","none"],precision:a,data:[{yAxis:p,label:{show:!0,position:"end",formatter:n=>e.yAxisLabelFormatter?e.yAxisLabelFormatter(n.value):W.formatValue(n.value,a),color:"#fff",backgroundColor:c,padding:[2,4],borderRadius:2,fontSize:11,fontWeight:"bold"},lineStyle:{color:c,type:u,width:1,opacity:.8}}],animation:!1,silent:!0}}return{type:"candlestick",name:e.title||"Market",data:l,itemStyle:{color:s,color0:o,borderColor:s,borderColor0:o},markLine:d,xAxisIndex:0,yAxisIndex:0,z:5}}static buildIndicatorSeries(t,e,i,s,o=0,l,d,h=1){const p=[],y=new Array(s).fill(null),c=new Map;return t.forEach((u,a)=>{u.collapsed||Object.keys(u.plots).sort((n,f)=>{const r=u.plots[n],x=u.plots[f],w=r.options.style==="fill",S=x.options.style==="fill";return w&&!S?1:!w&&S?-1:0}).forEach(n=>{const f=u.plots[n],r=`${a}::${n}`;let x=0,w=0;const S=f.options.overlay;if(u.paneIndex===0||S===!0)x=0,d&&d.has(r)?w=d.get(r):w=0;else{const m=i.findIndex(P=>P.index===u.paneIndex);m!==-1&&(x=m+1,w=h+m)}const A=new Array(s).fill(null),C=new Array(s).fill(null),b=new Array(s).fill(null),v=new Array(s).fill(null);if(f.data?.forEach(m=>{const P=e.get(m.time);if(P!==void 0){const D=m.options?.offset??f.options.offset??0,M=P+o+D;if(M>=0&&M<s){let _=m.value;const L=m.options?.color;C[M]=_;const R=m.options!=null&&"color"in m.options,O=L===null||L==="na"||L==="NaN"||typeof L=="number"&&isNaN(L)||R&&L===void 0;O&&(_=null),A[M]=_,b[M]=O?null:L||f.options.color||vt.DEFAULT_COLOR,v[M]=m.options||{}}}}),c.set(`${a}::${n}`,C),f.options?.style?.startsWith("style_")&&(f.options.style=f.options.style.replace("style_","")),f.options.style==="barcolor"){f.data?.forEach(m=>{const P=e.get(m.time);if(P!==void 0){const D=m.options?.offset??f.options.offset??0,M=P+o+D;if(M>=0&&M<s){const _=m.options?.color||f.options.color||vt.DEFAULT_COLOR;!(_===null||_==="na"||_==="NaN"||typeof _=="number"&&isNaN(_))&&m.value!==null&&m.value!==void 0&&(y[M]=_)}}});return}if(f.options.style==="table")return;const I=Bt.get(f.options.style).render({seriesName:r,xAxisIndex:x,yAxisIndex:w,dataArray:A,colorArray:b,optionsArray:v,plotOptions:f.options,candlestickData:l,plotDataArrays:c,indicatorId:a,plotName:n,dataIndexOffset:o});I&&p.push(I)})}),{series:p,barColors:y}}};jt(St,"DEFAULT_COLOR","#2962ff");let pt=St;class Vt{static build(t,e,i,s=!1,o=null){const l=[],d=t.pixelToPercent,h=t.mainPaneTop;if(!o||o==="main"){const p=10*d;if(l.push({type:"text",left:"8.5%",top:h+p+"%",z:10,style:{text:e.title||"Market",fill:e.titleColor||"#fff",font:`bold 16px ${e.fontFamily||"sans-serif"}`,textVerticalAlign:"top"}}),e.watermark!==!1){const c=t.mainPaneTop+t.mainPaneHeight;l.push({type:"text",right:"11%",top:c-3+"%",z:10,style:{text:"QFChart",fill:e.fontColor||"#cbd5e1",font:"bold 16px sans-serif",opacity:.1},cursor:"pointer",onclick:()=>{window.open("https://quantforge.org","_blank")}})}const y=[];if(e.controls?.collapse&&y.push({type:"group",children:[{type:"rect",shape:{width:20,height:20,r:2},style:{fill:"#334155",stroke:"#475569",lineWidth:1},onclick:()=>i("main","collapse")},{type:"text",style:{text:s?"+":"\u2212",fill:"#cbd5e1",font:`bold 14px ${e.fontFamily}`,x:10,y:10,textAlign:"center",textVerticalAlign:"middle"},silent:!0}]}),e.controls?.maximize){const c=o==="main",u=e.controls?.collapse?25:0;y.push({type:"group",x:u,children:[{type:"rect",shape:{width:20,height:20,r:2},style:{fill:"#334155",stroke:"#475569",lineWidth:1},onclick:()=>i("main","maximize")},{type:"text",style:{text:c?"\u2750":"\u25A1",fill:"#cbd5e1",font:`14px ${e.fontFamily}`,x:10,y:10,textAlign:"center",textVerticalAlign:"middle"},silent:!0}]})}if(e.controls?.fullscreen){let c=0;e.controls?.collapse&&(c+=25),e.controls?.maximize&&(c+=25),y.push({type:"group",x:c,children:[{type:"rect",shape:{width:20,height:20,r:2},style:{fill:"#334155",stroke:"#475569",lineWidth:1},onclick:()=>i("main","fullscreen")},{type:"text",style:{text:"\u26F6",fill:"#cbd5e1",font:`14px ${e.fontFamily}`,x:10,y:10,textAlign:"center",textVerticalAlign:"middle"},silent:!0}]})}y.length>0&&l.push({type:"group",right:"10.5%",top:h+"%",children:y})}return t.paneLayout.forEach(p=>{if(o&&p.indicatorId!==o)return;l.push({type:"text",left:"8.5%",top:p.top+10*d+"%",z:10,style:{text:p.indicatorId||"",fill:p.titleColor||"#fff",font:`bold 12px ${e.fontFamily||"sans-serif"}`,textVerticalAlign:"top"}});const y=[];if(p.controls?.collapse&&y.push({type:"group",children:[{type:"rect",shape:{width:20,height:20,r:2},style:{fill:"#334155",stroke:"#475569",lineWidth:1},onclick:()=>p.indicatorId&&i(p.indicatorId,"collapse")},{type:"text",style:{text:p.isCollapsed?"+":"\u2212",fill:"#cbd5e1",font:`bold 14px ${e.fontFamily}`,x:10,y:10,textAlign:"center",textVerticalAlign:"middle"},silent:!0}]}),p.controls?.maximize){const c=o===p.indicatorId,u=p.controls?.collapse?25:0;y.push({type:"group",x:u,children:[{type:"rect",shape:{width:20,height:20,r:2},style:{fill:"#334155",stroke:"#475569",lineWidth:1},onclick:()=>p.indicatorId&&i(p.indicatorId,"maximize")},{type:"text",style:{text:c?"\u2750":"\u25A1",fill:"#cbd5e1",font:`14px ${e.fontFamily}`,x:10,y:10,textAlign:"center",textVerticalAlign:"middle"},silent:!0}]})}y.length>0&&l.push({type:"group",right:"10.5%",top:p.top+"%",children:y})}),l}}class Xt{static format(t,e){if(!t||t.length===0)return"";const i=e.title||"Market",s=e.upColor||"#00da3c",o=e.downColor||"#ec0000",l=e.fontFamily||"sans-serif",d=t[0].axisValue;let h=`<div style="font-weight: bold; margin-bottom: 5px; color: #cbd5e1; font-family: ${l};">${d}</div>`;const p=t.find(c=>c.seriesType==="candlestick"),y=t.filter(c=>c.seriesType!=="candlestick");if(p){const[c,u,a,n,f]=p.value,r=a>=u?s:o;h+=`
18
+ <div style="margin-bottom: 8px; font-family: ${l};">
19
+ <div style="display:flex; justify-content:space-between; color:${r}; font-weight:bold;">
20
20
  <span>${i}</span>
21
21
  </div>
22
22
  <div style="display: grid; grid-template-columns: auto auto; gap: 2px 15px; font-size: 0.9em; color: #cbd5e1;">
23
- <span>Open:</span> <span style="text-align: right; color: ${h>=r?s:n}">${r}</span>
24
- <span>High:</span> <span style="text-align: right; color: ${s}">${c}</span>
25
- <span>Low:</span> <span style="text-align: right; color: ${n}">${o}</span>
26
- <span>Close:</span> <span style="text-align: right; color: ${h>=r?s:n}">${h}</span>
23
+ <span>Open:</span> <span style="text-align: right; color: ${a>=u?s:o}">${u}</span>
24
+ <span>High:</span> <span style="text-align: right; color: ${s}">${f}</span>
25
+ <span>Low:</span> <span style="text-align: right; color: ${o}">${n}</span>
26
+ <span>Close:</span> <span style="text-align: right; color: ${a>=u?s:o}">${a}</span>
27
27
  </div>
28
28
  </div>
29
- `}if(f.length>0){p+='<div style="border-top: 1px solid #334155; margin: 5px 0; padding-top: 5px;"></div>';const l={};f.forEach(r=>{const h=r.seriesName.split("::"),o=h.length>1?h[0]:"Unknown",c=h.length>1?h[1]:r.seriesName;l[o]||(l[o]=[]),l[o].push({...r,displayName:c})}),Object.keys(l).forEach(r=>{p+=`
30
- <div style="margin-top: 8px; font-family: ${a};">
31
- <div style="font-weight:bold; color: #fff; margin-bottom: 2px;">${r}</div>
32
- `,l[r].forEach(h=>{let o=h.value;if(Array.isArray(o)&&(o=o[1]),o==null)return;const c=typeof o=="number"?o.toLocaleString(void 0,{maximumFractionDigits:4}):o;p+=`
29
+ `}if(y.length>0){h+='<div style="border-top: 1px solid #334155; margin: 5px 0; padding-top: 5px;"></div>';const c={};y.forEach(u=>{const a=u.seriesName.split("::"),n=a.length>1?a[0]:"Unknown",f=a.length>1?a[1]:u.seriesName;c[n]||(c[n]=[]),c[n].push({...u,displayName:f})}),Object.keys(c).forEach(u=>{h+=`
30
+ <div style="margin-top: 8px; font-family: ${l};">
31
+ <div style="font-weight:bold; color: #fff; margin-bottom: 2px;">${u}</div>
32
+ `,c[u].forEach(a=>{let n=a.value;if(Array.isArray(n)&&(n=n[1]),n==null)return;const f=typeof n=="number"?n.toLocaleString(void 0,{maximumFractionDigits:4}):n;h+=`
33
33
  <div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 2px; padding-left: 8px;">
34
- <div>${h.marker} <span style="color: #cbd5e1;">${h.displayName}</span></div>
35
- <div style="font-size: 10px; color: #fff;padding-left:10px;">${c}</div>
36
- </div>`}),p+="</div>"})}return p}}var jt=Object.defineProperty,Yt=(y,e,t)=>e in y?jt(y,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):y[e]=t,rt=(y,e,t)=>(Yt(y,typeof e!="symbol"?e+"":e,t),t);class Bt{constructor(e,t){rt(this,"plugins",new Map),rt(this,"activePluginId",null),rt(this,"context"),rt(this,"toolbarContainer"),rt(this,"tooltipElement",null),rt(this,"hideTimeout",null),this.context=e,this.toolbarContainer=t,this.createTooltip(),this.renderToolbar()}createTooltip(){this.tooltipElement=document.createElement("div"),Object.assign(this.tooltipElement.style,{position:"fixed",display:"none",backgroundColor:"#1e293b",color:"#e2e8f0",padding:"6px 10px",borderRadius:"6px",fontSize:"13px",lineHeight:"1.4",fontWeight:"500",border:"1px solid #334155",zIndex:"9999",pointerEvents:"none",whiteSpace:"nowrap",boxShadow:"0 4px 6px -1px rgba(0, 0, 0, 0.3), 0 2px 4px -1px rgba(0, 0, 0, 0.15)",fontFamily:this.context.getOptions().fontFamily||"sans-serif",transition:"opacity 0.15s ease-in-out, transform 0.15s ease-in-out",opacity:"0",transform:"translateX(-5px)"}),document.body.appendChild(this.tooltipElement)}destroy(){this.tooltipElement&&this.tooltipElement.parentNode&&this.tooltipElement.parentNode.removeChild(this.tooltipElement),this.tooltipElement=null}showTooltip(e,t){if(!this.tooltipElement)return;this.hideTimeout&&(clearTimeout(this.hideTimeout),this.hideTimeout=null);const i=e.getBoundingClientRect();this.tooltipElement.textContent=t,this.tooltipElement.style.display="block";const s=this.tooltipElement.getBoundingClientRect(),n=i.top+(i.height-s.height)/2,a=i.right+10;this.tooltipElement.style.top=`${n}px`,this.tooltipElement.style.left=`${a}px`,requestAnimationFrame(()=>{this.tooltipElement&&(this.tooltipElement.style.opacity="1",this.tooltipElement.style.transform="translateX(0)")})}hideTooltip(){this.tooltipElement&&(this.tooltipElement.style.opacity="0",this.tooltipElement.style.transform="translateX(-5px)",this.hideTimeout&&clearTimeout(this.hideTimeout),this.hideTimeout=setTimeout(()=>{this.tooltipElement&&(this.tooltipElement.style.display="none"),this.hideTimeout=null},150))}register(e){if(this.plugins.has(e.id)){console.warn(`Plugin with id ${e.id} is already registered.`);return}this.plugins.set(e.id,e),e.init(this.context),this.addButton(e)}unregister(e){const t=this.plugins.get(e);t&&(this.activePluginId===e&&this.deactivatePlugin(),t.destroy?.(),this.plugins.delete(e),this.removeButton(e))}activatePlugin(e){if(this.activePluginId===e){this.deactivatePlugin();return}this.activePluginId&&this.deactivatePlugin();const t=this.plugins.get(e);t&&(this.activePluginId=e,this.setButtonActive(e,!0),t.activate?.())}deactivatePlugin(){this.activePluginId&&(this.plugins.get(this.activePluginId)?.deactivate?.(),this.setButtonActive(this.activePluginId,!1),this.activePluginId=null)}renderToolbar(){this.toolbarContainer.innerHTML="",this.toolbarContainer.classList.add("qfchart-toolbar"),this.toolbarContainer.style.display="flex",this.toolbarContainer.style.flexDirection="column",this.toolbarContainer.style.width="40px",this.toolbarContainer.style.backgroundColor=this.context.getOptions().backgroundColor||"#1e293b",this.toolbarContainer.style.borderRight="1px solid #334155",this.toolbarContainer.style.padding="5px",this.toolbarContainer.style.boxSizing="border-box",this.toolbarContainer.style.gap="5px",this.toolbarContainer.style.flexShrink="0"}addButton(e){const t=document.createElement("button");t.id=`qfchart-plugin-btn-${e.id}`,t.style.width="30px",t.style.height="30px",t.style.padding="4px",t.style.border="1px solid transparent",t.style.borderRadius="4px",t.style.backgroundColor="transparent",t.style.cursor="pointer",t.style.color=this.context.getOptions().fontColor||"#cbd5e1",t.style.display="flex",t.style.alignItems="center",t.style.justifyContent="center",e.icon?t.innerHTML=e.icon:t.innerText=(e.name||e.id).substring(0,2).toUpperCase(),t.addEventListener("mouseenter",()=>{this.activePluginId!==e.id&&(t.style.backgroundColor="rgba(255, 255, 255, 0.1)"),this.showTooltip(t,e.name||e.id)}),t.addEventListener("mouseleave",()=>{this.activePluginId!==e.id&&(t.style.backgroundColor="transparent"),this.hideTooltip()}),t.onclick=()=>this.activatePlugin(e.id),this.toolbarContainer.appendChild(t)}removeButton(e){const t=this.toolbarContainer.querySelector(`#qfchart-plugin-btn-${e}`);t&&t.remove()}setButtonActive(e,t){const i=this.toolbarContainer.querySelector(`#qfchart-plugin-btn-${e}`);i&&(t?(i.style.backgroundColor="#2563eb",i.style.color="#ffffff"):(i.style.backgroundColor="transparent",i.style.color=this.context.getOptions().fontColor||"#cbd5e1"))}}var Vt=Object.defineProperty,qt=(y,e,t)=>e in y?Vt(y,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):y[e]=t,q=(y,e,t)=>(qt(y,typeof e!="symbol"?e+"":e,t),t);class Xt{constructor(e){q(this,"context"),q(this,"isEditing",!1),q(this,"currentDrawing",null),q(this,"editingPointIndex",null),q(this,"zr"),q(this,"editGroup",null),q(this,"editLine",null),q(this,"editStartPoint",null),q(this,"editEndPoint",null),q(this,"isMovingShape",!1),q(this,"dragStart",null),q(this,"initialPixelPoints",[]),q(this,"onDrawingMouseDown",t=>{if(this.isEditing)return;const i=this.context.getDrawing(t.id);i&&(this.isEditing=!0,this.isMovingShape=!0,this.currentDrawing=JSON.parse(JSON.stringify(i)),this.dragStart={x:t.x,y:t.y},this.initialPixelPoints=i.points.map(s=>{const n=this.context.coordinateConversion.dataToPixel(s);return n?{x:n.x,y:n.y}:{x:0,y:0}}),this.context.lockChart(),this.createEditGraphic(),this.zr.on("mousemove",this.onMouseMove),this.zr.on("mouseup",this.onMouseUp))}),q(this,"onPointMouseDown",t=>{if(this.isEditing)return;const i=this.context.getDrawing(t.id);i&&(this.isEditing=!0,this.currentDrawing=JSON.parse(JSON.stringify(i)),this.editingPointIndex=t.pointIndex,this.context.lockChart(),this.createEditGraphic(),this.zr.on("mousemove",this.onMouseMove),this.zr.on("mouseup",this.onMouseUp))}),q(this,"onMouseMove",t=>{if(!this.isEditing||!this.currentDrawing)return;const i=t.offsetX,s=t.offsetY;if(this.isMovingShape&&this.dragStart){const n=i-this.dragStart.x,a=s-this.dragStart.y,u={x:this.initialPixelPoints[0].x+n,y:this.initialPixelPoints[0].y+a},p={x:this.initialPixelPoints[1].x+n,y:this.initialPixelPoints[1].y+a};this.editLine.setShape({x1:u.x,y1:u.y,x2:p.x,y2:p.y}),this.editStartPoint.setShape({cx:u.x,cy:u.y}),this.editEndPoint.setShape({cx:p.x,cy:p.y})}else this.editingPointIndex!==null&&(this.editingPointIndex===0?(this.editLine.setShape({x1:i,y1:s}),this.editStartPoint.setShape({cx:i,cy:s})):(this.editLine.setShape({x2:i,y2:s}),this.editEndPoint.setShape({cx:i,cy:s})))}),q(this,"onMouseUp",t=>{this.isEditing&&this.finishEditing(t.offsetX,t.offsetY)}),this.context=e,this.zr=this.context.getChart().getZr(),this.bindEvents()}bindEvents(){this.context.events.on("drawing:point:mousedown",this.onPointMouseDown),this.context.events.on("drawing:mousedown",this.onDrawingMouseDown)}createEditGraphic(){if(!this.currentDrawing)return;this.editGroup=new H.graphic.Group;const e=this.currentDrawing.points[0],t=this.currentDrawing.points[1],i=this.context.coordinateConversion.dataToPixel(e),s=this.context.coordinateConversion.dataToPixel(t);!i||!s||(this.editLine=new H.graphic.Line({shape:{x1:i.x,y1:i.y,x2:s.x,y2:s.y},style:{stroke:this.currentDrawing.style?.color||"#3b82f6",lineWidth:this.currentDrawing.style?.lineWidth||2,lineDash:[4,4]},silent:!0}),this.editStartPoint=new H.graphic.Circle({shape:{cx:i.x,cy:i.y,r:5},style:{fill:"#fff",stroke:"#3b82f6",lineWidth:2},z:1e3}),this.editEndPoint=new H.graphic.Circle({shape:{cx:s.x,cy:s.y,r:5},style:{fill:"#fff",stroke:"#3b82f6",lineWidth:2},z:1e3}),this.editGroup.add(this.editLine),this.editGroup.add(this.editStartPoint),this.editGroup.add(this.editEndPoint),this.zr.add(this.editGroup))}finishEditing(e,t){if(this.currentDrawing){if(this.isMovingShape&&this.dragStart){const i=e-this.dragStart.x,s=t-this.dragStart.y,n=this.initialPixelPoints.map((a,u)=>{const p=a.x+i,d=a.y+s;return this.context.coordinateConversion.pixelToData({x:p,y:d})});n.every(a=>a!==null)&&n[0]&&n[1]&&(this.currentDrawing.points[0]=n[0],this.currentDrawing.points[1]=n[1],n[0].paneIndex!==void 0&&(this.currentDrawing.paneIndex=n[0].paneIndex),this.context.updateDrawing(this.currentDrawing))}else if(this.editingPointIndex!==null){const i=this.context.coordinateConversion.pixelToData({x:e,y:t});i&&(this.currentDrawing.points[this.editingPointIndex]=i,this.editingPointIndex===0&&i.paneIndex!==void 0&&(this.currentDrawing.paneIndex=i.paneIndex),this.context.updateDrawing(this.currentDrawing))}this.isEditing=!1,this.isMovingShape=!1,this.dragStart=null,this.initialPixelPoints=[],this.currentDrawing=null,this.editingPointIndex=null,this.editGroup&&(this.zr.remove(this.editGroup),this.editGroup=null),this.zr.off("mousemove",this.onMouseMove),this.zr.off("mouseup",this.onMouseUp),this.context.unlockChart()}}}var Ut=Object.defineProperty,Jt=(y,e,t)=>e in y?Ut(y,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):y[e]=t,Kt=(y,e,t)=>(Jt(y,typeof e!="symbol"?e+"":e,t),t);class Qt{constructor(){Kt(this,"handlers",new Map)}on(e,t){this.handlers.has(e)||this.handlers.set(e,new Set),this.handlers.get(e).add(t)}off(e,t){const i=this.handlers.get(e);i&&i.delete(t)}emit(e,t){const i=this.handlers.get(e);i&&i.forEach(s=>{try{s(t)}catch(n){console.error(`Error in EventBus handler for ${e}:`,n)}})}clear(){this.handlers.clear()}}var te=Object.defineProperty,ee=(y,e,t)=>e in y?te(y,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):y[e]=t,T=(y,e,t)=>(ee(y,typeof e!="symbol"?e+"":e,t),t);class ie{constructor(e,t={}){T(this,"chart"),T(this,"options"),T(this,"marketData",[]),T(this,"indicators",new Map),T(this,"timeToIndex",new Map),T(this,"pluginManager"),T(this,"drawingEditor"),T(this,"events",new Qt),T(this,"isMainCollapsed",!1),T(this,"maximizedPaneId",null),T(this,"countdownInterval",null),T(this,"selectedDrawingId",null),T(this,"drawings",[]),T(this,"coordinateConversion",{pixelToData:n=>{const a=this.chart.getOption();if(!a||!a.grid)return null;const u=a.grid.length;for(let p=0;p<u;p++)if(this.chart.containPixel({gridIndex:p},[n.x,n.y])){this.chart.convertFromPixel({seriesIndex:p},[n.x,n.y]);const d=this.chart.convertFromPixel({gridIndex:p},[n.x,n.y]);if(d)return{timeIndex:Math.round(d[0]),value:d[1],paneIndex:p}}return null},dataToPixel:n=>{const a=n.paneIndex||0,u=this.chart.convertToPixel({gridIndex:a},[n.timeIndex,n.value]);return u?{x:u[0],y:u[1]}:null}}),T(this,"upColor","#00da3c"),T(this,"downColor","#ec0000"),T(this,"defaultPadding",0),T(this,"padding"),T(this,"dataIndexOffset",0),T(this,"rootContainer"),T(this,"layoutContainer"),T(this,"toolbarContainer"),T(this,"leftSidebar"),T(this,"rightSidebar"),T(this,"chartContainer"),T(this,"onKeyDown",n=>{(n.key==="Delete"||n.key==="Backspace")&&this.selectedDrawingId&&(this.removeDrawing(this.selectedDrawingId),this.selectedDrawingId=null,this.render())}),T(this,"onFullscreenChange",()=>{this.render()}),T(this,"isLocked",!1),T(this,"lockedState",null),this.rootContainer=e,this.options={title:"Market",height:"600px",backgroundColor:"#1e293b",upColor:"#00da3c",downColor:"#ec0000",fontColor:"#cbd5e1",fontFamily:"sans-serif",padding:.01,dataZoom:{visible:!0,position:"top",height:6},layout:{mainPaneHeight:"50%",gap:13},watermark:!0,...t},this.options.upColor&&(this.upColor=this.options.upColor),this.options.downColor&&(this.downColor=this.options.downColor),this.padding=this.options.padding!==void 0?this.options.padding:this.defaultPadding,this.options.height&&(typeof this.options.height=="number"?this.rootContainer.style.height=`${this.options.height}px`:this.rootContainer.style.height=this.options.height),this.rootContainer.innerHTML="",this.layoutContainer=document.createElement("div"),this.layoutContainer.style.display="flex",this.layoutContainer.style.width="100%",this.layoutContainer.style.height="100%",this.layoutContainer.style.overflow="hidden",this.rootContainer.appendChild(this.layoutContainer),this.leftSidebar=document.createElement("div"),this.leftSidebar.style.display="none",this.leftSidebar.style.width="250px",this.leftSidebar.style.flexShrink="0",this.leftSidebar.style.overflowY="auto",this.leftSidebar.style.backgroundColor=this.options.backgroundColor||"#1e293b",this.leftSidebar.style.borderRight="1px solid #334155",this.leftSidebar.style.padding="10px",this.leftSidebar.style.boxSizing="border-box",this.leftSidebar.style.color="#cbd5e1",this.leftSidebar.style.fontSize="12px",this.leftSidebar.style.fontFamily=this.options.fontFamily||"sans-serif",this.layoutContainer.appendChild(this.leftSidebar),this.toolbarContainer=document.createElement("div"),this.layoutContainer.appendChild(this.toolbarContainer),this.chartContainer=document.createElement("div"),this.chartContainer.style.flexGrow="1",this.chartContainer.style.height="100%",this.chartContainer.style.overflow="hidden",this.layoutContainer.appendChild(this.chartContainer),this.rightSidebar=document.createElement("div"),this.rightSidebar.style.display="none",this.rightSidebar.style.width="250px",this.rightSidebar.style.flexShrink="0",this.rightSidebar.style.overflowY="auto",this.rightSidebar.style.backgroundColor=this.options.backgroundColor||"#1e293b",this.rightSidebar.style.borderLeft="1px solid #334155",this.rightSidebar.style.padding="10px",this.rightSidebar.style.boxSizing="border-box",this.rightSidebar.style.color="#cbd5e1",this.rightSidebar.style.fontSize="12px",this.rightSidebar.style.fontFamily=this.options.fontFamily||"sans-serif",this.layoutContainer.appendChild(this.rightSidebar),this.chart=H.init(this.chartContainer),this.pluginManager=new Bt(this,this.toolbarContainer),this.drawingEditor=new Xt(this),this.chart.on("dataZoom",n=>{this.events.emit("chart:dataZoom",n);const a=this.options.databox?.triggerOn,u=this.options.databox?.position;a==="click"&&u==="floating"&&this.chart.dispatchAction({type:"hideTip"})}),this.chart.on("finished",n=>this.events.emit("chart:updated",n)),this.chart.getZr().on("mousedown",n=>this.events.emit("mouse:down",n)),this.chart.getZr().on("mousemove",n=>this.events.emit("mouse:move",n)),this.chart.getZr().on("mouseup",n=>this.events.emit("mouse:up",n)),this.chart.getZr().on("click",n=>this.events.emit("mouse:click",n));const i=this.chart.getZr(),s=i.setCursorStyle;i.setCursorStyle=function(n){n==="grab"&&(n="crosshair"),s.call(this,n)},this.bindDrawingEvents(),window.addEventListener("resize",this.resize.bind(this)),document.addEventListener("fullscreenchange",this.onFullscreenChange),document.addEventListener("keydown",this.onKeyDown)}bindDrawingEvents(){let e=null;const t=i=>{if(!i||i.componentType!=="series"||!i.seriesName?.startsWith("drawings"))return null;i.seriesIndex;const s=i.seriesName.match(/drawings-pane-(\d+)/);if(!s)return null;const n=parseInt(s[1]),a=this.drawings.filter(p=>(p.paneIndex||0)===n)[i.dataIndex];if(!a)return null;const u=i.event?.target?.name;return{drawing:a,targetName:u,paneIdx:n}};this.chart.on("mouseover",i=>{const s=t(i);if(!s)return;const n=i.event?.target?.parent;if(n){const a=s.drawing.id===this.selectedDrawingId;e&&(clearTimeout(e),e=null),a||n.children().forEach(u=>{u.name&&u.name.startsWith("point")&&u.attr("style",{opacity:1})})}if(s.targetName==="line")this.events.emit("drawing:hover",{id:s.drawing.id,type:s.drawing.type}),this.chart.getZr().setCursorStyle("move");else if(s.targetName?.startsWith("point")){const a=s.targetName==="point-start"?0:1;this.events.emit("drawing:point:hover",{id:s.drawing.id,pointIndex:a}),this.chart.getZr().setCursorStyle("pointer")}}),this.chart.on("mouseout",i=>{const s=t(i);if(!s)return;const n=i.event?.target?.parent;if(s.drawing.id!==this.selectedDrawingId){if(e=setTimeout(()=>{if(n){if(this.selectedDrawingId===s.drawing.id)return;n.children().forEach(a=>{a.name&&a.name.startsWith("point")&&a.attr("style",{opacity:0})})}},50),s.targetName==="line")this.events.emit("drawing:mouseout",{id:s.drawing.id});else if(s.targetName?.startsWith("point")){const a=s.targetName==="point-start"?0:1;this.events.emit("drawing:point:mouseout",{id:s.drawing.id,pointIndex:a})}this.chart.getZr().setCursorStyle("default")}}),this.chart.on("mousedown",i=>{const s=t(i);if(!s)return;const n=i.event?.event||i.event,a=n?.offsetX,u=n?.offsetY;if(s.targetName==="line")this.events.emit("drawing:mousedown",{id:s.drawing.id,x:a,y:u});else if(s.targetName?.startsWith("point")){const p=s.targetName==="point-start"?0:1;this.events.emit("drawing:point:mousedown",{id:s.drawing.id,pointIndex:p,x:a,y:u})}}),this.chart.on("click",i=>{const s=t(i);if(s){if(this.selectedDrawingId!==s.drawing.id&&(this.selectedDrawingId=s.drawing.id,this.events.emit("drawing:selected",{id:s.drawing.id}),this.render()),s.targetName==="line")this.events.emit("drawing:click",{id:s.drawing.id});else if(s.targetName?.startsWith("point")){const n=s.targetName==="point-start"?0:1;this.events.emit("drawing:point:click",{id:s.drawing.id,pointIndex:n})}}}),this.chart.getZr().on("click",i=>{i.target||this.selectedDrawingId&&(this.events.emit("drawing:deselected",{id:this.selectedDrawingId}),this.selectedDrawingId=null,this.render())})}getChart(){return this.chart}getMarketData(){return this.marketData}getTimeToIndex(){return this.timeToIndex}getOptions(){return this.options}disableTools(){this.pluginManager.deactivatePlugin()}registerPlugin(e){this.pluginManager.register(e)}addDrawing(e){this.drawings.push(e),this.render()}removeDrawing(e){const t=this.drawings.findIndex(i=>i.id===e);if(t!==-1){const i=this.drawings[t];this.drawings.splice(t,1),this.events.emit("drawing:deleted",{id:i.id}),this.render()}}getDrawing(e){return this.drawings.find(t=>t.id===e)}updateDrawing(e){const t=this.drawings.findIndex(i=>i.id===e.id);t!==-1&&(this.drawings[t]=e,this.render())}lockChart(){if(this.isLocked)return;this.isLocked=!0;const e=this.chart.getOption();this.chart.setOption({dataZoom:e.dataZoom.map(t=>({...t,disabled:!0})),tooltip:{show:!1}})}unlockChart(){if(!this.isLocked)return;this.isLocked=!1;const e=this.chart.getOption();(this.options.dataZoom||{}).visible,e.dataZoom&&this.chart.setOption({dataZoom:e.dataZoom.map(t=>({...t,disabled:!1})),tooltip:{show:!0}})}setZoom(e,t){this.chart.dispatchAction({type:"dataZoom",start:e,end:t})}setMarketData(e){this.marketData=e,this.rebuildTimeIndex(),this.render()}updateData(e){if(e.length===0)return;const t=new Map;this.marketData.forEach(c=>{t.set(c.time,c)}),e.forEach(c=>{t.has(c.time),t.set(c.time,c)}),this.marketData=Array.from(t.values()).sort((c,g)=>c.time-g.time),this.rebuildTimeIndex();const i=this.dataIndexOffset,s=ct.buildCandlestickSeries(this.marketData,this.options),n={value:[NaN,NaN,NaN,NaN],itemStyle:{opacity:0}},a=[...Array(i).fill(n),...s.data,...Array(i).fill(n)],u=[...Array(i).fill(""),...this.marketData.map(c=>new Date(c.time).toLocaleString()),...Array(i).fill("")],p=this.chart.getOption(),d=mt.calculate(this.chart.getHeight(),this.indicators,this.options,this.isMainCollapsed,this.maximizedPaneId,this.marketData),f=[...Array(i).fill(null),...this.marketData,...Array(i).fill(null)],{series:l,barColors:r}=ct.buildIndicatorSeries(this.indicators,this.timeToIndex,d.paneLayout,u.length,i,f,d.overlayYAxisMap,d.separatePaneYAxisOffset),h=a.map((c,g)=>r[g]?{value:c.value||c,itemStyle:{color:r[g],color0:r[g],borderColor:r[g],borderColor0:r[g]}}:c),o={xAxis:p.xAxis.map((c,g)=>({data:u})),series:[{data:h,markLine:s.markLine},...l.map(c=>{const g={data:c.data};return c.renderItem&&(g.renderItem=c.renderItem),g})]};this.chart.setOption(o,{notMerge:!1}),this.startCountdown()}startCountdown(){if(this.stopCountdown(),!this.options.lastPriceLine?.showCountdown||!this.options.interval||this.marketData.length===0)return;const e=()=>{if(this.marketData.length===0)return;const t=this.marketData[this.marketData.length-1].time+(this.options.interval||0),i=Date.now(),s=t-i;if(s<=0)return;const n=Math.abs(s),a=Math.floor(n/36e5),u=Math.floor(n%36e5/6e4),p=Math.floor(n%6e4/1e3),d=`${a>0?a.toString().padStart(2,"0")+":":""}${u.toString().padStart(2,"0")}:${p.toString().padStart(2,"0")}`,f=this.chart.getOption();if(!f||!f.series)return;const l=f.series.findIndex(w=>w.type==="candlestick");if(l===-1)return;const r=f.series[l];if(!r.markLine||!r.markLine.data||!r.markLine.data[0])return;const h=r.markLine.data[0];h.label.formatter;const o=h.yAxis;let c="";if(this.options.yAxisLabelFormatter)c=this.options.yAxisLabelFormatter(o);else{const w=this.options.yAxisDecimalPlaces!==void 0?this.options.yAxisDecimalPlaces:Z.autoDetectDecimals(this.marketData);c=Z.formatValue(o,w)}const g=`${c}
37
- ${d}`;this.chart.setOption({series:[{name:this.options.title||"Market",markLine:{data:[{...h,label:{...h.label,formatter:g}}]}}]})};e(),this.countdownInterval=setInterval(e,1e3)}stopCountdown(){this.countdownInterval&&(clearInterval(this.countdownInterval),this.countdownInterval=null)}addIndicator(e,t,i={}){const s=i.overlay!==void 0?i.overlay:i.isOverlay??!1;let n=0;if(!s){let u=0;this.indicators.forEach(p=>{p.paneIndex>u&&(u=p.paneIndex)}),n=u+1}const a=new St(e,t,n,{height:i.height,collapsed:!1,titleColor:i.titleColor,controls:i.controls});return this.indicators.set(e,a),this.render(),a}setIndicator(e,t,i=!1){this.addIndicator(e,{[e]:t},{overlay:i})}removeIndicator(e){this.indicators.delete(e),this.render()}toggleIndicator(e,t="collapse"){if(t==="fullscreen"){document.fullscreenElement?document.exitFullscreen():this.rootContainer.requestFullscreen();return}if(t==="maximize"){this.maximizedPaneId===e?this.maximizedPaneId=null:this.maximizedPaneId=e,this.render();return}if(e==="main"){this.isMainCollapsed=!this.isMainCollapsed,this.render();return}const i=this.indicators.get(e);i&&(i.toggleCollapse(),this.render())}resize(){this.chart.resize()}destroy(){this.stopCountdown(),window.removeEventListener("resize",this.resize.bind(this)),document.removeEventListener("fullscreenchange",this.onFullscreenChange),document.removeEventListener("keydown",this.onKeyDown),this.pluginManager.deactivatePlugin(),this.pluginManager.destroy(),this.chart.dispose()}rebuildTimeIndex(){this.timeToIndex.clear(),this.marketData.forEach((i,s)=>{this.timeToIndex.set(i.time,s)});const e=this.marketData.length,t=Math.ceil(e*this.padding);this.dataIndexOffset=t}render(){if(this.marketData.length===0)return;let e=null;try{const x=this.chart.getOption();if(x&&x.dataZoom&&x.dataZoom.length>0){const b=x.dataZoom.find(C=>C.type==="slider"||C.type==="inside");b&&(e={start:b.start,end:b.end})}}catch{}const t=this.options.databox?.position,i=this.leftSidebar.style.display,s=this.rightSidebar.style.display,n=t==="left"?"block":"none",a=t==="right"?"block":"none";(i!==n||s!==a)&&(this.leftSidebar.style.display=n,this.rightSidebar.style.display=a,this.chart.resize());const u=this.dataIndexOffset,p=[...Array(u).fill(""),...this.marketData.map(x=>new Date(x.time).toLocaleString()),...Array(u).fill("")],d=mt.calculate(this.chart.getHeight(),this.indicators,this.options,this.isMainCollapsed,this.maximizedPaneId,this.marketData);if(!e&&d.dataZoom&&this.marketData.length>0){const x=this.marketData.length,b=p.length,C=u/b,I=x/b;d.dataZoom.forEach(m=>{if(m.start!==void 0){const M=m.start/100,k=C+M*I;m.start=k*100}if(m.end!==void 0){const M=m.end/100,k=C+M*I;m.end=k*100}})}e&&d.dataZoom&&d.dataZoom.forEach(x=>{x.start=e.start,x.end=e.end}),d.xAxis.forEach(x=>{x.data=p,x.boundaryGap=!1});const f=ct.buildCandlestickSeries(this.marketData,this.options),l={value:[NaN,NaN,NaN,NaN],itemStyle:{opacity:0}};f.data=[...Array(u).fill(l),...f.data,...Array(u).fill(l)];const r=[...Array(u).fill(null),...this.marketData,...Array(u).fill(null)],{series:h,barColors:o}=ct.buildIndicatorSeries(this.indicators,this.timeToIndex,d.paneLayout,p.length,u,r,d.overlayYAxisMap,d.separatePaneYAxisOffset);f.data=f.data.map((x,b)=>o[b]?{value:x.value||x,itemStyle:{color:o[b],color0:o[b],borderColor:o[b],borderColor0:o[b]}}:x);const c=Ht.build(d,this.options,this.toggleIndicator.bind(this),this.isMainCollapsed,this.maximizedPaneId),g=new Map;this.drawings.forEach(x=>{const b=x.paneIndex||0;g.has(b)||g.set(b,[]),g.get(b).push(x)});const w=[];g.forEach((x,b)=>{w.push({type:"custom",name:`drawings-pane-${b}`,xAxisIndex:b,yAxisIndex:b,clip:!0,renderItem:(C,I)=>{const m=x[C.dataIndex];if(!m)return;const M=m.points[0],k=m.points[1];if(!M||!k)return;const S=I.coord([M.timeIndex,M.value]),L=I.coord([k.timeIndex,k.value]),z=m.id===this.selectedDrawingId;if(m.type==="line")return{type:"group",children:[{type:"line",name:"line",shape:{x1:S[0],y1:S[1],x2:L[0],y2:L[1]},style:{stroke:m.style?.color||"#3b82f6",lineWidth:m.style?.lineWidth||2}},{type:"circle",name:"point-start",shape:{cx:S[0],cy:S[1],r:4},style:{fill:"#fff",stroke:m.style?.color||"#3b82f6",lineWidth:1,opacity:z?1:0}},{type:"circle",name:"point-end",shape:{cx:L[0],cy:L[1],r:4},style:{fill:"#fff",stroke:m.style?.color||"#3b82f6",lineWidth:1,opacity:z?1:0}}]};if(m.type==="fibonacci"){const O=S[0],U=S[1],$=L[0],B=L[1],X=Math.min(O,$),tt=Math.max(O,$),J=tt-X,v=B-U,D=[0,.236,.382,.5,.618,.786,1],E=["#787b86","#f44336","#ff9800","#4caf50","#2196f3","#00bcd4","#787b86"],_=[];_.push({type:"line",name:"line",shape:{x1:O,y1:U,x2:$,y2:B},style:{stroke:"#999",lineWidth:1,lineDash:[4,4]}}),_.push({type:"circle",name:"point-start",shape:{cx:O,cy:U,r:4},style:{fill:"#fff",stroke:m.style?.color||"#3b82f6",lineWidth:1,opacity:z?1:0},z:100}),_.push({type:"circle",name:"point-end",shape:{cx:$,cy:B,r:4},style:{fill:"#fff",stroke:m.style?.color||"#3b82f6",lineWidth:1,opacity:z?1:0},z:100}),D.forEach((G,R)=>{const N=B-v*G,W=E[R%E.length];_.push({type:"line",name:"fib-line",shape:{x1:X,y1:N,x2:tt,y2:N},style:{stroke:W,lineWidth:1},silent:!0});const it=m.points[0].value,et=m.points[1].value,K=et-it,st=et-K*G;if(_.push({type:"text",style:{text:`${G} (${st.toFixed(2)})`,x:X+5,y:N-10,fill:W,fontSize:10},silent:!0}),R<D.length-1){const pt=D[R+1],lt=B-v*pt,ut=Math.abs(lt-N),yt=Math.min(N,lt);_.push({type:"rect",shape:{x:X,y:yt,width:J,height:ut},style:{fill:E[(R+1)%E.length],opacity:.1},silent:!0})}});const V=[],F=[];return D.forEach((G,R)=>{const N=B-v*G,W=E[R%E.length];F.push({type:"line",shape:{x1:X,y1:N,x2:tt,y2:N},style:{stroke:W,lineWidth:1},silent:!0});const it=m.points[0].value,et=m.points[1].value,K=et-it,st=et-K*G;if(F.push({type:"text",style:{text:`${G} (${st.toFixed(2)})`,x:X+5,y:N-10,fill:W,fontSize:10},silent:!0}),R<D.length-1){const pt=D[R+1],lt=B-v*pt,ut=Math.abs(lt-N),yt=Math.min(N,lt);V.push({type:"rect",name:"line",shape:{x:X,y:yt,width:J,height:ut},style:{fill:E[(R+1)%E.length],opacity:.1}})}}),{type:"group",children:[...V,...F,{type:"line",name:"line",shape:{x1:O,y1:U,x2:$,y2:B},style:{stroke:"#999",lineWidth:1,lineDash:[4,4]}},{type:"circle",name:"point-start",shape:{cx:O,cy:U,r:4},style:{fill:"#fff",stroke:m.style?.color||"#3b82f6",lineWidth:1,opacity:z?1:0},z:100},{type:"circle",name:"point-end",shape:{cx:$,cy:B,r:4},style:{fill:"#fff",stroke:m.style?.color||"#3b82f6",lineWidth:1,opacity:z?1:0},z:100}]}}},data:x.map(C=>[C.points[0].timeIndex,C.points[0].value,C.points[1].timeIndex,C.points[1].value]),z:100,silent:!1})});const A=x=>{const b=Rt.format(x,this.options),C=this.options.databox?.position;return C==="left"?(this.leftSidebar.innerHTML=b,""):C==="right"?(this.rightSidebar.innerHTML=b,""):this.options.databox?`<div style="min-width: 200px;">${b}</div>`:""},P={backgroundColor:this.options.backgroundColor,animation:!1,legend:{show:!1},tooltip:{show:!0,showContent:!!this.options.databox,trigger:"axis",triggerOn:this.options.databox?.triggerOn??"mousemove",axisPointer:{type:"cross",label:{backgroundColor:"#475569"}},backgroundColor:"rgba(30, 41, 59, 0.9)",borderWidth:1,borderColor:"#334155",padding:10,textStyle:{color:"#fff",fontFamily:this.options.fontFamily||"sans-serif"},formatter:A,extraCssText:t!=="floating"&&t!==void 0?"display: none !important;":void 0,position:(x,b,C,I,m)=>{if(this.options.databox?.position==="floating"){const M={top:10};return M[["left","right"][+(x[0]<m.viewSize[0]/2)]]=30,M}return null}},axisPointer:{link:{xAxisIndex:"all"},label:{backgroundColor:"#475569"}},graphic:c,grid:d.grid,xAxis:d.xAxis,yAxis:d.yAxis,dataZoom:d.dataZoom,series:[f,...h,...w]};this.chart.setOption(P,!0)}}var se=Object.defineProperty,ne=(y,e,t)=>e in y?se(y,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):y[e]=t,ht=(y,e,t)=>(ne(y,typeof e!="symbol"?e+"":e,t),t);class dt{constructor(e){ht(this,"id"),ht(this,"name"),ht(this,"icon"),ht(this,"context"),ht(this,"eventListeners",[]),this.id=e.id,this.name=e.name,this.icon=e.icon}init(e){this.context=e,this.onInit()}onInit(){}activate(){this.onActivate(),this.context.events.emit("plugin:activated",this.id)}onActivate(){}deactivate(){this.onDeactivate(),this.context.events.emit("plugin:deactivated",this.id)}onDeactivate(){}destroy(){this.removeAllListeners(),this.onDestroy()}onDestroy(){}on(e,t){this.context.events.on(e,t),this.eventListeners.push({event:e,handler:t})}off(e,t){this.context.events.off(e,t),this.eventListeners=this.eventListeners.filter(i=>i.event!==e||i.handler!==t)}removeAllListeners(){this.eventListeners.forEach(({event:e,handler:t})=>{this.context.events.off(e,t)}),this.eventListeners=[]}get chart(){return this.context.getChart()}get marketData(){return this.context.getMarketData()}}var oe=Object.defineProperty,ae=(y,e,t)=>e in y?oe(y,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):y[e]=t,Y=(y,e,t)=>(ae(y,typeof e!="symbol"?e+"":e,t),t);class re extends dt{constructor(e){super({id:"measure",name:e?.name||"Measure",icon:e?.icon||'<svg xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 -960 960 960" width="24px" fill="#e3e3e3"><path d="M160-240q-33 0-56.5-23.5T80-320v-320q0-33 23.5-56.5T160-720h640q33 0 56.5 23.5T880-640v320q0 33-23.5 56.5T800-240H160Zm0-80h640v-320H680v160h-80v-160h-80v160h-80v-160h-80v160h-80v-160H160v320Zm120-160h80-80Zm160 0h80-80Zm160 0h80-80Zm-120 0Z"/></svg>'}),Y(this,"zr"),Y(this,"state","idle"),Y(this,"startPoint",null),Y(this,"endPoint",null),Y(this,"group",null),Y(this,"rect",null),Y(this,"labelRect",null),Y(this,"labelText",null),Y(this,"lineV",null),Y(this,"lineH",null),Y(this,"arrowStart",null),Y(this,"arrowEnd",null),Y(this,"onMouseDown",()=>{this.state==="finished"&&this.removeGraphic()}),Y(this,"onChartInteraction",()=>{this.group&&this.removeGraphic()}),Y(this,"onClick",t=>{this.state==="idle"?(this.state="drawing",this.startPoint=[t.offsetX,t.offsetY],this.endPoint=[t.offsetX,t.offsetY],this.initGraphic(),this.updateGraphic()):this.state==="drawing"&&(this.state="finished",this.endPoint=[t.offsetX,t.offsetY],this.updateGraphic(),this.context.disableTools(),this.enableClearListeners())}),Y(this,"clearHandlers",{}),Y(this,"onMouseMove",t=>{this.state==="drawing"&&(this.endPoint=[t.offsetX,t.offsetY],this.updateGraphic())})}onInit(){this.zr=this.chart.getZr()}onActivate(){this.state="idle",this.chart.getZr().setCursorStyle("crosshair"),this.zr.on("click",this.onClick),this.zr.on("mousemove",this.onMouseMove)}onDeactivate(){this.state="idle",this.chart.getZr().setCursorStyle("default"),this.zr.off("click",this.onClick),this.zr.off("mousemove",this.onMouseMove),this.disableClearListeners(),this.state==="drawing"&&this.removeGraphic()}onDestroy(){this.removeGraphic()}enableClearListeners(){const e=()=>{this.removeGraphic()};setTimeout(()=>{this.zr.on("click",e)},10),this.zr.on("mousedown",this.onMouseDown),this.context.events.on("chart:dataZoom",this.onChartInteraction),this.clearHandlers={click:e,mousedown:this.onMouseDown,dataZoom:this.onChartInteraction}}disableClearListeners(){this.clearHandlers.click&&this.zr.off("click",this.clearHandlers.click),this.clearHandlers.mousedown&&this.zr.off("mousedown",this.clearHandlers.mousedown),this.clearHandlers.dataZoom&&this.context.events.off("chart:dataZoom",this.clearHandlers.dataZoom),this.clearHandlers={}}initGraphic(){this.group||(this.group=new H.graphic.Group,this.rect=new H.graphic.Rect({shape:{x:0,y:0,width:0,height:0},style:{fill:"rgba(0,0,0,0)",stroke:"transparent",lineWidth:0},z:100}),this.lineV=new H.graphic.Line({shape:{x1:0,y1:0,x2:0,y2:0},style:{stroke:"#fff",lineWidth:1,lineDash:[4,4]},z:101}),this.lineH=new H.graphic.Line({shape:{x1:0,y1:0,x2:0,y2:0},style:{stroke:"#fff",lineWidth:1,lineDash:[4,4]},z:101}),this.arrowStart=new H.graphic.Polygon({shape:{points:[[0,0],[-5,10],[5,10]]},style:{fill:"#fff"},z:102}),this.arrowEnd=new H.graphic.Polygon({shape:{points:[[0,0],[-5,-10],[5,-10]]},style:{fill:"#fff"},z:102}),this.labelRect=new H.graphic.Rect({shape:{x:0,y:0,width:0,height:0,r:4},style:{fill:"transparent",stroke:"transparent",lineWidth:0,shadowBlur:5,shadowColor:"rgba(0,0,0,0.3)"},z:102}),this.labelText=new H.graphic.Text({style:{x:0,y:0,text:"",fill:"#fff",font:"12px sans-serif",align:"center",verticalAlign:"middle"},z:103}),this.group.add(this.rect),this.group.add(this.lineV),this.group.add(this.lineH),this.group.add(this.arrowStart),this.group.add(this.arrowEnd),this.group.add(this.labelRect),this.group.add(this.labelText),this.zr.add(this.group))}removeGraphic(){this.group&&(this.zr.remove(this.group),this.group=null,this.disableClearListeners())}updateGraphic(){if(!this.startPoint||!this.endPoint||!this.group)return;const[e,t]=this.startPoint,[i,s]=this.endPoint,n=this.context.coordinateConversion.pixelToData({x:e,y:t}),a=this.context.coordinateConversion.pixelToData({x:i,y:s});if(!n||!a)return;const u=Math.round(n.timeIndex),p=Math.round(a.timeIndex),d=n.value,f=a.value,l=p-u,r=f-d,h=r/d*100,o=r>=0,c=o?"rgba(33, 150, 243, 0.2)":"rgba(236, 0, 0, 0.2)",g=o?"#2196F3":"#ec0000";this.rect.setShape({x:Math.min(e,i),y:Math.min(t,s),width:Math.abs(i-e),height:Math.abs(s-t)}),this.rect.setStyle({fill:c});const w=(e+i)/2,A=(t+s)/2;this.lineV.setShape({x1:w,y1:t,x2:w,y2:s}),this.lineV.setStyle({stroke:g}),this.lineH.setShape({x1:e,y1:A,x2:i,y2:A}),this.lineH.setStyle({stroke:g});const P=Math.min(t,s),x=Math.max(t,s);this.arrowStart.setStyle({fill:"none"}),this.arrowEnd.setStyle({fill:"none"}),o?(this.arrowStart.setShape({points:[[w,P],[w-4,P+6],[w+4,P+6]]}),this.arrowStart.setStyle({fill:g})):(this.arrowEnd.setShape({points:[[w,x],[w-4,x-6],[w+4,x-6]]}),this.arrowEnd.setStyle({fill:g}));const b=[`${r.toFixed(2)} (${h.toFixed(2)}%)`,`${l} bars, ${(l*0).toFixed(0)}d`].join(`
38
- `),C=140,I=40,m=Math.max(t,s),M=Math.min(t,s);let k=(e+i)/2-C/2,S=m+10;const L=this.chart.getHeight();S+I>L&&(S=M-I-10),this.labelRect.setShape({x:k,y:S,width:C,height:I}),this.labelRect.setStyle({fill:"#1e293b",stroke:g,lineWidth:1}),this.labelText.setStyle({x:k+C/2,y:S+I/2,text:b,fill:"#fff"})}}var le=Object.defineProperty,he=(y,e,t)=>e in y?le(y,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):y[e]=t,Q=(y,e,t)=>(he(y,typeof e!="symbol"?e+"":e,t),t);class ce extends dt{constructor(e){super({id:"trend-line",name:e?.name||"Trend Line",icon:e?.icon||'<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><line x1="2" y1="22" x2="22" y2="2" /></svg>'}),Q(this,"zr"),Q(this,"state","idle"),Q(this,"startPoint",null),Q(this,"endPoint",null),Q(this,"group",null),Q(this,"line",null),Q(this,"startCircle",null),Q(this,"endCircle",null),Q(this,"onMouseDown",()=>{}),Q(this,"onChartInteraction",()=>{}),Q(this,"onClick",t=>{if(this.state==="idle")this.state="drawing",this.startPoint=[t.offsetX,t.offsetY],this.endPoint=[t.offsetX,t.offsetY],this.initGraphic(),this.updateGraphic();else if(this.state==="drawing"){if(this.state="finished",this.endPoint=[t.offsetX,t.offsetY],this.updateGraphic(),this.startPoint&&this.endPoint){const i=this.context.coordinateConversion.pixelToData({x:this.startPoint[0],y:this.startPoint[1]}),s=this.context.coordinateConversion.pixelToData({x:this.endPoint[0],y:this.endPoint[1]});if(i&&s){const n=i.paneIndex||0;this.context.addDrawing({id:`line-${Date.now()}`,type:"line",points:[i,s],paneIndex:n,style:{color:"#3b82f6",lineWidth:2}})}}this.removeGraphic(),this.context.disableTools()}}),Q(this,"clearHandlers",{}),Q(this,"onMouseMove",t=>{this.state==="drawing"&&(this.endPoint=[t.offsetX,t.offsetY],this.updateGraphic())})}onInit(){this.zr=this.chart.getZr()}onActivate(){this.state="idle",this.chart.getZr().setCursorStyle("crosshair"),this.zr.on("click",this.onClick),this.zr.on("mousemove",this.onMouseMove)}onDeactivate(){this.state="idle",this.chart.getZr().setCursorStyle("default"),this.zr.off("click",this.onClick),this.zr.off("mousemove",this.onMouseMove),this.disableClearListeners(),this.state==="drawing"&&this.removeGraphic()}onDestroy(){this.removeGraphic()}saveDataCoordinates(){}updateGraphicFromData(){}enableClearListeners(){}disableClearListeners(){}initGraphic(){this.group||(this.group=new H.graphic.Group,this.line=new H.graphic.Line({shape:{x1:0,y1:0,x2:0,y2:0},style:{stroke:"#3b82f6",lineWidth:2},z:100}),this.startCircle=new H.graphic.Circle({shape:{cx:0,cy:0,r:4},style:{fill:"#fff",stroke:"#3b82f6",lineWidth:1},z:101}),this.endCircle=new H.graphic.Circle({shape:{cx:0,cy:0,r:4},style:{fill:"#fff",stroke:"#3b82f6",lineWidth:1},z:101}),this.group.add(this.line),this.group.add(this.startCircle),this.group.add(this.endCircle),this.zr.add(this.group))}removeGraphic(){this.group&&(this.zr.remove(this.group),this.group=null,this.disableClearListeners())}updateGraphic(){if(!this.startPoint||!this.endPoint||!this.group)return;const[e,t]=this.startPoint,[i,s]=this.endPoint;this.line.setShape({x1:e,y1:t,x2:i,y2:s}),this.startCircle.setShape({cx:e,cy:t}),this.endCircle.setShape({cx:i,cy:s})}}var de=Object.defineProperty,pe=(y,e,t)=>e in y?de(y,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):y[e]=t,nt=(y,e,t)=>(pe(y,typeof e!="symbol"?e+"":e,t),t);class ue extends dt{constructor(e={}){super({id:"fibonacci-tool",name:e.name||"Fibonacci Retracement",icon:e.icon||'<svg xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 -960 960 960" width="24px" fill="#e3e3e3"><path d="M120-80v-80h720v80H120Zm0-240v-80h720v80H120Zm0-240v-80h720v80H120Zm0-240v-80h720v80H120Z"/></svg>'}),nt(this,"startPoint",null),nt(this,"endPoint",null),nt(this,"state","idle"),nt(this,"graphicGroup",null),nt(this,"levels",[0,.236,.382,.5,.618,.786,1]),nt(this,"colors",["#787b86","#f44336","#ff9800","#4caf50","#2196f3","#00bcd4","#787b86"]),nt(this,"onClick",t=>{this.state==="idle"?(this.state="drawing",this.startPoint=[t.offsetX,t.offsetY],this.endPoint=[t.offsetX,t.offsetY],this.initGraphic(),this.updateGraphic()):this.state==="drawing"&&(this.state="finished",this.endPoint=[t.offsetX,t.offsetY],this.updateGraphic(),this.saveDrawing(),this.removeGraphic(),this.context.disableTools())}),nt(this,"onMouseMove",t=>{this.state==="drawing"&&(this.endPoint=[t.offsetX,t.offsetY],this.updateGraphic())})}onActivate(){this.state="idle",this.startPoint=null,this.endPoint=null,this.context.getChart().getZr().setCursorStyle("crosshair"),this.bindEvents()}onDeactivate(){this.state="idle",this.startPoint=null,this.endPoint=null,this.removeGraphic(),this.unbindEvents(),this.context.getChart().getZr().setCursorStyle("default")}bindEvents(){const e=this.context.getChart().getZr();e.on("click",this.onClick),e.on("mousemove",this.onMouseMove)}unbindEvents(){const e=this.context.getChart().getZr();e.off("click",this.onClick),e.off("mousemove",this.onMouseMove)}initGraphic(){this.graphicGroup=new H.graphic.Group,this.context.getChart().getZr().add(this.graphicGroup)}removeGraphic(){this.graphicGroup&&(this.context.getChart().getZr().remove(this.graphicGroup),this.graphicGroup=null)}updateGraphic(){if(!this.graphicGroup||!this.startPoint||!this.endPoint)return;this.graphicGroup.removeAll();const e=this.startPoint[0],t=this.startPoint[1],i=this.endPoint[0],s=this.endPoint[1],n=new H.graphic.Line({shape:{x1:e,y1:t,x2:i,y2:s},style:{stroke:"#999",lineWidth:1,lineDash:[4,4]},silent:!0});this.graphicGroup.add(n);const a=Math.min(e,i),u=Math.max(e,i),p=u-a,d=s-t;this.levels.forEach((f,l)=>{const r=s-d*f,h=this.colors[l%this.colors.length],o=new H.graphic.Line({shape:{x1:a,y1:r,x2:u,y2:r},style:{stroke:h,lineWidth:1},silent:!0});if(this.graphicGroup.add(o),l<this.levels.length-1){const c=this.levels[l+1],g=s-d*c,w=Math.abs(g-r),A=Math.min(r,g),P=new H.graphic.Rect({shape:{x:a,y:A,width:p,height:w},style:{fill:this.colors[(l+1)%this.colors.length],opacity:.1},silent:!0});this.graphicGroup.add(P)}})}saveDrawing(){if(!this.startPoint||!this.endPoint)return;const e=this.context.coordinateConversion.pixelToData({x:this.startPoint[0],y:this.startPoint[1]}),t=this.context.coordinateConversion.pixelToData({x:this.endPoint[0],y:this.endPoint[1]});if(e&&t){const i=e.paneIndex||0;this.context.addDrawing({id:`fib-${Date.now()}`,type:"fibonacci",points:[e,t],paneIndex:i,style:{color:"#3b82f6",lineWidth:1}})}}}export{dt as AbstractPlugin,ue as FibonacciTool,ce as LineTool,re as MeasureTool,ie as QFChart};
34
+ <div>${a.marker} <span style="color: #cbd5e1;">${a.displayName}</span></div>
35
+ <div style="font-size: 10px; color: #fff;padding-left:10px;">${f}</div>
36
+ </div>`}),h+="</div>"})}return h}}var qt=Object.defineProperty,Ut=(g,t,e)=>t in g?qt(g,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):g[t]=e,ht=(g,t,e)=>(Ut(g,typeof t!="symbol"?t+"":t,e),e);class Jt{constructor(t,e){ht(this,"plugins",new Map),ht(this,"activePluginId",null),ht(this,"context"),ht(this,"toolbarContainer"),ht(this,"tooltipElement",null),ht(this,"hideTimeout",null),this.context=t,this.toolbarContainer=e,this.createTooltip(),this.renderToolbar()}createTooltip(){this.tooltipElement=document.createElement("div"),Object.assign(this.tooltipElement.style,{position:"fixed",display:"none",backgroundColor:"#1e293b",color:"#e2e8f0",padding:"6px 10px",borderRadius:"6px",fontSize:"13px",lineHeight:"1.4",fontWeight:"500",border:"1px solid #334155",zIndex:"9999",pointerEvents:"none",whiteSpace:"nowrap",boxShadow:"0 4px 6px -1px rgba(0, 0, 0, 0.3), 0 2px 4px -1px rgba(0, 0, 0, 0.15)",fontFamily:this.context.getOptions().fontFamily||"sans-serif",transition:"opacity 0.15s ease-in-out, transform 0.15s ease-in-out",opacity:"0",transform:"translateX(-5px)"}),document.body.appendChild(this.tooltipElement)}destroy(){this.tooltipElement&&this.tooltipElement.parentNode&&this.tooltipElement.parentNode.removeChild(this.tooltipElement),this.tooltipElement=null}showTooltip(t,e){if(!this.tooltipElement)return;this.hideTimeout&&(clearTimeout(this.hideTimeout),this.hideTimeout=null);const i=t.getBoundingClientRect();this.tooltipElement.textContent=e,this.tooltipElement.style.display="block";const s=this.tooltipElement.getBoundingClientRect(),o=i.top+(i.height-s.height)/2,l=i.right+10;this.tooltipElement.style.top=`${o}px`,this.tooltipElement.style.left=`${l}px`,requestAnimationFrame(()=>{this.tooltipElement&&(this.tooltipElement.style.opacity="1",this.tooltipElement.style.transform="translateX(0)")})}hideTooltip(){this.tooltipElement&&(this.tooltipElement.style.opacity="0",this.tooltipElement.style.transform="translateX(-5px)",this.hideTimeout&&clearTimeout(this.hideTimeout),this.hideTimeout=setTimeout(()=>{this.tooltipElement&&(this.tooltipElement.style.display="none"),this.hideTimeout=null},150))}register(t){if(this.plugins.has(t.id)){console.warn(`Plugin with id ${t.id} is already registered.`);return}this.plugins.set(t.id,t),t.init(this.context),this.addButton(t)}unregister(t){const e=this.plugins.get(t);e&&(this.activePluginId===t&&this.deactivatePlugin(),e.destroy?.(),this.plugins.delete(t),this.removeButton(t))}activatePlugin(t){if(this.activePluginId===t){this.deactivatePlugin();return}this.activePluginId&&this.deactivatePlugin();const e=this.plugins.get(t);e&&(this.activePluginId=t,this.setButtonActive(t,!0),e.activate?.())}deactivatePlugin(){this.activePluginId&&(this.plugins.get(this.activePluginId)?.deactivate?.(),this.setButtonActive(this.activePluginId,!1),this.activePluginId=null)}renderToolbar(){this.toolbarContainer.innerHTML="",this.toolbarContainer.classList.add("qfchart-toolbar"),this.toolbarContainer.style.display="flex",this.toolbarContainer.style.flexDirection="column",this.toolbarContainer.style.width="40px",this.toolbarContainer.style.backgroundColor=this.context.getOptions().backgroundColor||"#1e293b",this.toolbarContainer.style.borderRight="1px solid #334155",this.toolbarContainer.style.padding="5px",this.toolbarContainer.style.boxSizing="border-box",this.toolbarContainer.style.gap="5px",this.toolbarContainer.style.flexShrink="0"}addButton(t){const e=document.createElement("button");e.id=`qfchart-plugin-btn-${t.id}`,e.style.width="30px",e.style.height="30px",e.style.padding="4px",e.style.border="1px solid transparent",e.style.borderRadius="4px",e.style.backgroundColor="transparent",e.style.cursor="pointer",e.style.color=this.context.getOptions().fontColor||"#cbd5e1",e.style.display="flex",e.style.alignItems="center",e.style.justifyContent="center",t.icon?e.innerHTML=t.icon:e.innerText=(t.name||t.id).substring(0,2).toUpperCase(),e.addEventListener("mouseenter",()=>{this.activePluginId!==t.id&&(e.style.backgroundColor="rgba(255, 255, 255, 0.1)"),this.showTooltip(e,t.name||t.id)}),e.addEventListener("mouseleave",()=>{this.activePluginId!==t.id&&(e.style.backgroundColor="transparent"),this.hideTooltip()}),e.onclick=()=>this.activatePlugin(t.id),this.toolbarContainer.appendChild(e)}removeButton(t){const e=this.toolbarContainer.querySelector(`#qfchart-plugin-btn-${t}`);e&&e.remove()}setButtonActive(t,e){const i=this.toolbarContainer.querySelector(`#qfchart-plugin-btn-${t}`);i&&(e?(i.style.backgroundColor="#2563eb",i.style.color="#ffffff"):(i.style.backgroundColor="transparent",i.style.color=this.context.getOptions().fontColor||"#cbd5e1"))}}var Kt=Object.defineProperty,Qt=(g,t,e)=>t in g?Kt(g,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):g[t]=e,X=(g,t,e)=>(Qt(g,typeof t!="symbol"?t+"":t,e),e);class te{constructor(t){X(this,"context"),X(this,"isEditing",!1),X(this,"currentDrawing",null),X(this,"editingPointIndex",null),X(this,"zr"),X(this,"editGroup",null),X(this,"editLine",null),X(this,"editStartPoint",null),X(this,"editEndPoint",null),X(this,"isMovingShape",!1),X(this,"dragStart",null),X(this,"initialPixelPoints",[]),X(this,"onDrawingMouseDown",e=>{if(this.isEditing)return;const i=this.context.getDrawing(e.id);i&&(this.isEditing=!0,this.isMovingShape=!0,this.currentDrawing=JSON.parse(JSON.stringify(i)),this.dragStart={x:e.x,y:e.y},this.initialPixelPoints=i.points.map(s=>{const o=this.context.coordinateConversion.dataToPixel(s);return o?{x:o.x,y:o.y}:{x:0,y:0}}),this.context.lockChart(),this.createEditGraphic(),this.zr.on("mousemove",this.onMouseMove),this.zr.on("mouseup",this.onMouseUp))}),X(this,"onPointMouseDown",e=>{if(this.isEditing)return;const i=this.context.getDrawing(e.id);i&&(this.isEditing=!0,this.currentDrawing=JSON.parse(JSON.stringify(i)),this.editingPointIndex=e.pointIndex,this.context.lockChart(),this.createEditGraphic(),this.zr.on("mousemove",this.onMouseMove),this.zr.on("mouseup",this.onMouseUp))}),X(this,"onMouseMove",e=>{if(!this.isEditing||!this.currentDrawing)return;const i=e.offsetX,s=e.offsetY;if(this.isMovingShape&&this.dragStart){const o=i-this.dragStart.x,l=s-this.dragStart.y,d={x:this.initialPixelPoints[0].x+o,y:this.initialPixelPoints[0].y+l},h={x:this.initialPixelPoints[1].x+o,y:this.initialPixelPoints[1].y+l};this.editLine.setShape({x1:d.x,y1:d.y,x2:h.x,y2:h.y}),this.editStartPoint.setShape({cx:d.x,cy:d.y}),this.editEndPoint.setShape({cx:h.x,cy:h.y})}else this.editingPointIndex!==null&&(this.editingPointIndex===0?(this.editLine.setShape({x1:i,y1:s}),this.editStartPoint.setShape({cx:i,cy:s})):(this.editLine.setShape({x2:i,y2:s}),this.editEndPoint.setShape({cx:i,cy:s})))}),X(this,"onMouseUp",e=>{this.isEditing&&this.finishEditing(e.offsetX,e.offsetY)}),this.context=t,this.zr=this.context.getChart().getZr(),this.bindEvents()}bindEvents(){this.context.events.on("drawing:point:mousedown",this.onPointMouseDown),this.context.events.on("drawing:mousedown",this.onDrawingMouseDown)}createEditGraphic(){if(!this.currentDrawing)return;this.editGroup=new G.graphic.Group;const t=this.currentDrawing.points[0],e=this.currentDrawing.points[1],i=this.context.coordinateConversion.dataToPixel(t),s=this.context.coordinateConversion.dataToPixel(e);!i||!s||(this.editLine=new G.graphic.Line({shape:{x1:i.x,y1:i.y,x2:s.x,y2:s.y},style:{stroke:this.currentDrawing.style?.color||"#3b82f6",lineWidth:this.currentDrawing.style?.lineWidth||2,lineDash:[4,4]},silent:!0}),this.editStartPoint=new G.graphic.Circle({shape:{cx:i.x,cy:i.y,r:5},style:{fill:"#fff",stroke:"#3b82f6",lineWidth:2},z:1e3}),this.editEndPoint=new G.graphic.Circle({shape:{cx:s.x,cy:s.y,r:5},style:{fill:"#fff",stroke:"#3b82f6",lineWidth:2},z:1e3}),this.editGroup.add(this.editLine),this.editGroup.add(this.editStartPoint),this.editGroup.add(this.editEndPoint),this.zr.add(this.editGroup))}finishEditing(t,e){if(this.currentDrawing){if(this.isMovingShape&&this.dragStart){const i=t-this.dragStart.x,s=e-this.dragStart.y,o=this.initialPixelPoints.map((l,d)=>{const h=l.x+i,p=l.y+s;return this.context.coordinateConversion.pixelToData({x:h,y:p})});o.every(l=>l!==null)&&o[0]&&o[1]&&(this.currentDrawing.points[0]=o[0],this.currentDrawing.points[1]=o[1],o[0].paneIndex!==void 0&&(this.currentDrawing.paneIndex=o[0].paneIndex),this.context.updateDrawing(this.currentDrawing))}else if(this.editingPointIndex!==null){const i=this.context.coordinateConversion.pixelToData({x:t,y:e});i&&(this.currentDrawing.points[this.editingPointIndex]=i,this.editingPointIndex===0&&i.paneIndex!==void 0&&(this.currentDrawing.paneIndex=i.paneIndex),this.context.updateDrawing(this.currentDrawing))}this.isEditing=!1,this.isMovingShape=!1,this.dragStart=null,this.initialPixelPoints=[],this.currentDrawing=null,this.editingPointIndex=null,this.editGroup&&(this.zr.remove(this.editGroup),this.editGroup=null),this.zr.off("mousemove",this.onMouseMove),this.zr.off("mouseup",this.onMouseUp),this.context.unlockChart()}}}var ee=Object.defineProperty,ie=(g,t,e)=>t in g?ee(g,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):g[t]=e,se=(g,t,e)=>(ie(g,typeof t!="symbol"?t+"":t,e),e);class oe{constructor(){se(this,"handlers",new Map)}on(t,e){this.handlers.has(t)||this.handlers.set(t,new Set),this.handlers.get(t).add(e)}off(t,e){const i=this.handlers.get(t);i&&i.delete(e)}emit(t,e){const i=this.handlers.get(t);i&&i.forEach(s=>{try{s(e)}catch(o){console.error(`Error in EventBus handler for ${t}:`,o)}})}clear(){this.handlers.clear()}}class Q{static safeParseColor(t){if(!t||typeof t!="string")return{color:"#888888",opacity:1};const e=t.match(/rgba?\((\d+),\s*(\d+),\s*(\d+)(?:,\s*([\d.]+))?\)/);if(e){const i=e[4]?parseFloat(e[4]):1;return{color:`rgb(${e[1]},${e[2]},${e[3]})`,opacity:i}}return{color:t,opacity:1}}static render(t,e,i){Q.clearAll(t);const s=new Map;for(const o of e)o&&!o._deleted&&s.set(o.position,o);s.forEach(o=>{const l=Q.buildTable(o);Q.positionTable(l,o.position,i),t.appendChild(l)})}static clearAll(t){for(;t.firstChild;)t.removeChild(t.firstChild)}static buildTable(t){const e=document.createElement("table");if(e.style.borderCollapse="separate",e.style.borderSpacing="0",e.style.pointerEvents="auto",e.style.fontSize="14px",e.style.lineHeight="1.4",e.style.fontFamily="sans-serif",e.style.margin="4px",t.bgcolor){const{color:d,opacity:h}=Q.safeParseColor(t.bgcolor);e.style.backgroundColor=d,h<1&&(e.style.opacity=String(h))}if(t.frame_width>0&&t.frame_color){const{color:d}=Q.safeParseColor(t.frame_color);e.style.border=`${t.frame_width}px solid ${d}`}else t.frame_width>0&&(e.style.border=`${t.frame_width}px solid #999`);const i=new Map,s=new Set;if(t.merges)for(const d of t.merges){const h=`${d.startCol},${d.startRow}`;i.set(h,{colspan:d.endCol-d.startCol+1,rowspan:d.endRow-d.startRow+1});for(let p=d.startRow;p<=d.endRow;p++)for(let y=d.startCol;y<=d.endCol;y++)p===d.startRow&&y===d.startCol||s.add(`${y},${p}`)}const o=t.rows||0,l=t.columns||0;for(let d=0;d<o;d++){const h=document.createElement("tr");for(let p=0;p<l;p++){const y=`${p},${d}`;if(s.has(y))continue;const c=document.createElement("td"),u=i.get(y);if(u&&(u.colspan>1&&(c.colSpan=u.colspan),u.rowspan>1&&(c.rowSpan=u.rowspan)),t.border_width>0){const n=t.border_color?Q.safeParseColor(t.border_color).color:"#999";c.style.border=`${t.border_width}px solid ${n}`}const a=t.cells?.[d]?.[p];if(a&&!a._merged){if(c.textContent=a.text||"",a.bgcolor){const{color:n,opacity:f}=Q.safeParseColor(a.bgcolor);c.style.backgroundColor=n,f<1&&(c.style.backgroundColor=a.bgcolor)}if(a.text_color){const{color:n}=Q.safeParseColor(a.text_color);c.style.color=n}c.style.fontSize=Q.getSizePixels(a.text_size)+"px",c.style.textAlign=Q.mapHAlign(a.text_halign),c.style.verticalAlign=Q.mapVAlign(a.text_valign),a.text_font_family==="monospace"&&(c.style.fontFamily="monospace"),a.width>0&&(c.style.width=a.width+"%"),a.height>0&&(c.style.height=a.height+"%"),a.tooltip&&(c.title=a.tooltip)}c.style.padding="4px 6px",c.style.whiteSpace="nowrap",h.appendChild(c)}e.appendChild(h)}return e}static positionTable(t,e,i){t.style.position="absolute";const s=8,o=i?i.y+"px":"0",l=i?i.x+"px":"0",d=i?i.y+i.height-s+"px":"0",h=i?i.x+i.width-s+"px":"0",p=i?i.x+i.width/2+"px":"50%",y=i?i.y+i.height/2+"px":"50%";switch(e){case"top_left":t.style.top=o,t.style.left=l;break;case"top_center":t.style.top=o,t.style.left=p,t.style.transform="translateX(-50%)";break;case"top_right":t.style.top=o,t.style.left=h,t.style.transform="translateX(-100%)";break;case"middle_left":t.style.top=y,t.style.left=l,t.style.transform="translateY(-50%)";break;case"middle_center":t.style.top=y,t.style.left=p,t.style.transform="translate(-50%, -50%)";break;case"middle_right":t.style.top=y,t.style.left=h,t.style.transform="translate(-100%, -50%)";break;case"bottom_left":t.style.top=d,t.style.left=l,t.style.transform="translateY(-100%)";break;case"bottom_center":t.style.top=d,t.style.left=p,t.style.transform="translate(-50%, -100%)";break;case"bottom_right":t.style.top=d,t.style.left=h,t.style.transform="translate(-100%, -100%)";break;default:t.style.top=o,t.style.left=h,t.style.transform="translateX(-100%)";break}}static getSizePixels(t){if(typeof t=="number"&&t>0)return t;switch(t){case"auto":case"size.auto":return 12;case"tiny":case"size.tiny":return 8;case"small":case"size.small":return 10;case"normal":case"size.normal":return 14;case"large":case"size.large":return 20;case"huge":case"size.huge":return 36;default:return 14}}static mapHAlign(t){switch(t){case"left":case"text.align_left":return"left";case"right":case"text.align_right":return"right";case"center":case"text.align_center":default:return"center"}}static mapVAlign(t){switch(t){case"top":case"text.align_top":return"top";case"bottom":case"text.align_bottom":return"bottom";case"center":case"text.align_center":default:return"middle"}}}var ne=Object.defineProperty,ae=(g,t,e)=>t in g?ne(g,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):g[t]=e,$=(g,t,e)=>(ae(g,typeof t!="symbol"?t+"":t,e),e);class re{constructor(t,e={}){$(this,"chart"),$(this,"options"),$(this,"marketData",[]),$(this,"indicators",new Map),$(this,"timeToIndex",new Map),$(this,"pluginManager"),$(this,"drawingEditor"),$(this,"events",new oe),$(this,"isMainCollapsed",!1),$(this,"maximizedPaneId",null),$(this,"countdownInterval",null),$(this,"selectedDrawingId",null),$(this,"drawings",[]),$(this,"coordinateConversion",{pixelToData:o=>{const l=this.chart.getOption();if(!l||!l.grid)return null;const d=l.grid.length;for(let h=0;h<d;h++)if(this.chart.containPixel({gridIndex:h},[o.x,o.y])){this.chart.convertFromPixel({seriesIndex:h},[o.x,o.y]);const p=this.chart.convertFromPixel({gridIndex:h},[o.x,o.y]);if(p)return{timeIndex:Math.round(p[0]),value:p[1],paneIndex:h}}return null},dataToPixel:o=>{const l=o.paneIndex||0,d=this.chart.convertToPixel({gridIndex:l},[o.timeIndex,o.value]);return d?{x:d[0],y:d[1]}:null}}),$(this,"upColor","#00da3c"),$(this,"downColor","#ec0000"),$(this,"defaultPadding",0),$(this,"padding"),$(this,"dataIndexOffset",0),$(this,"rootContainer"),$(this,"layoutContainer"),$(this,"toolbarContainer"),$(this,"leftSidebar"),$(this,"rightSidebar"),$(this,"chartContainer"),$(this,"overlayContainer"),$(this,"_lastTables",[]),$(this,"onKeyDown",o=>{(o.key==="Delete"||o.key==="Backspace")&&this.selectedDrawingId&&(this.removeDrawing(this.selectedDrawingId),this.selectedDrawingId=null,this.render())}),$(this,"onFullscreenChange",()=>{this.render()}),$(this,"isLocked",!1),$(this,"lockedState",null),this.rootContainer=t,this.options={title:"Market",height:"600px",backgroundColor:"#1e293b",upColor:"#00da3c",downColor:"#ec0000",fontColor:"#cbd5e1",fontFamily:"sans-serif",padding:.01,dataZoom:{visible:!0,position:"top",height:6},layout:{mainPaneHeight:"50%",gap:13},watermark:!0,...e},this.options.upColor&&(this.upColor=this.options.upColor),this.options.downColor&&(this.downColor=this.options.downColor),this.padding=this.options.padding!==void 0?this.options.padding:this.defaultPadding,this.options.height&&(typeof this.options.height=="number"?this.rootContainer.style.height=`${this.options.height}px`:this.rootContainer.style.height=this.options.height),this.rootContainer.innerHTML="",this.layoutContainer=document.createElement("div"),this.layoutContainer.style.display="flex",this.layoutContainer.style.width="100%",this.layoutContainer.style.height="100%",this.layoutContainer.style.overflow="hidden",this.rootContainer.appendChild(this.layoutContainer),this.leftSidebar=document.createElement("div"),this.leftSidebar.style.display="none",this.leftSidebar.style.width="250px",this.leftSidebar.style.flexShrink="0",this.leftSidebar.style.overflowY="auto",this.leftSidebar.style.backgroundColor=this.options.backgroundColor||"#1e293b",this.leftSidebar.style.borderRight="1px solid #334155",this.leftSidebar.style.padding="10px",this.leftSidebar.style.boxSizing="border-box",this.leftSidebar.style.color="#cbd5e1",this.leftSidebar.style.fontSize="12px",this.leftSidebar.style.fontFamily=this.options.fontFamily||"sans-serif",this.layoutContainer.appendChild(this.leftSidebar),this.toolbarContainer=document.createElement("div"),this.layoutContainer.appendChild(this.toolbarContainer),this.chartContainer=document.createElement("div"),this.chartContainer.style.flexGrow="1",this.chartContainer.style.height="100%",this.chartContainer.style.overflow="hidden",this.layoutContainer.appendChild(this.chartContainer),this.rightSidebar=document.createElement("div"),this.rightSidebar.style.display="none",this.rightSidebar.style.width="250px",this.rightSidebar.style.flexShrink="0",this.rightSidebar.style.overflowY="auto",this.rightSidebar.style.backgroundColor=this.options.backgroundColor||"#1e293b",this.rightSidebar.style.borderLeft="1px solid #334155",this.rightSidebar.style.padding="10px",this.rightSidebar.style.boxSizing="border-box",this.rightSidebar.style.color="#cbd5e1",this.rightSidebar.style.fontSize="12px",this.rightSidebar.style.fontFamily=this.options.fontFamily||"sans-serif",this.layoutContainer.appendChild(this.rightSidebar),this.chart=G.init(this.chartContainer),this.chartContainer.style.position="relative",this.overlayContainer=document.createElement("div"),this.overlayContainer.style.cssText="position:absolute;top:0;left:0;width:100%;height:100%;pointer-events:none;z-index:100;overflow:hidden;",this.chartContainer.appendChild(this.overlayContainer),this.pluginManager=new Jt(this,this.toolbarContainer),this.drawingEditor=new te(this),this.chart.on("dataZoom",o=>{this.events.emit("chart:dataZoom",o);const l=this.options.databox?.triggerOn,d=this.options.databox?.position;l==="click"&&d==="floating"&&this.chart.dispatchAction({type:"hideTip"})}),this.chart.on("finished",o=>this.events.emit("chart:updated",o)),this.chart.getZr().on("mousedown",o=>this.events.emit("mouse:down",o)),this.chart.getZr().on("mousemove",o=>this.events.emit("mouse:move",o)),this.chart.getZr().on("mouseup",o=>this.events.emit("mouse:up",o)),this.chart.getZr().on("click",o=>this.events.emit("mouse:click",o));const i=this.chart.getZr(),s=i.setCursorStyle;i.setCursorStyle=function(o){o==="grab"&&(o="crosshair"),s.call(this,o)},this.bindDrawingEvents(),window.addEventListener("resize",this.resize.bind(this)),document.addEventListener("fullscreenchange",this.onFullscreenChange),document.addEventListener("keydown",this.onKeyDown)}bindDrawingEvents(){let t=null;const e=i=>{if(!i||i.componentType!=="series"||!i.seriesName?.startsWith("drawings"))return null;i.seriesIndex;const s=i.seriesName.match(/drawings-pane-(\d+)/);if(!s)return null;const o=parseInt(s[1]),l=this.drawings.filter(h=>(h.paneIndex||0)===o)[i.dataIndex];if(!l)return null;const d=i.event?.target?.name;return{drawing:l,targetName:d,paneIdx:o}};this.chart.on("mouseover",i=>{const s=e(i);if(!s)return;const o=i.event?.target?.parent;if(o){const l=s.drawing.id===this.selectedDrawingId;t&&(clearTimeout(t),t=null),l||o.children().forEach(d=>{d.name&&d.name.startsWith("point")&&d.attr("style",{opacity:1})})}if(s.targetName==="line")this.events.emit("drawing:hover",{id:s.drawing.id,type:s.drawing.type}),this.chart.getZr().setCursorStyle("move");else if(s.targetName?.startsWith("point")){const l=s.targetName==="point-start"?0:1;this.events.emit("drawing:point:hover",{id:s.drawing.id,pointIndex:l}),this.chart.getZr().setCursorStyle("pointer")}}),this.chart.on("mouseout",i=>{const s=e(i);if(!s)return;const o=i.event?.target?.parent;if(s.drawing.id!==this.selectedDrawingId){if(t=setTimeout(()=>{if(o){if(this.selectedDrawingId===s.drawing.id)return;o.children().forEach(l=>{l.name&&l.name.startsWith("point")&&l.attr("style",{opacity:0})})}},50),s.targetName==="line")this.events.emit("drawing:mouseout",{id:s.drawing.id});else if(s.targetName?.startsWith("point")){const l=s.targetName==="point-start"?0:1;this.events.emit("drawing:point:mouseout",{id:s.drawing.id,pointIndex:l})}this.chart.getZr().setCursorStyle("default")}}),this.chart.on("mousedown",i=>{const s=e(i);if(!s)return;const o=i.event?.event||i.event,l=o?.offsetX,d=o?.offsetY;if(s.targetName==="line")this.events.emit("drawing:mousedown",{id:s.drawing.id,x:l,y:d});else if(s.targetName?.startsWith("point")){const h=s.targetName==="point-start"?0:1;this.events.emit("drawing:point:mousedown",{id:s.drawing.id,pointIndex:h,x:l,y:d})}}),this.chart.on("click",i=>{const s=e(i);if(s){if(this.selectedDrawingId!==s.drawing.id&&(this.selectedDrawingId=s.drawing.id,this.events.emit("drawing:selected",{id:s.drawing.id}),this.render()),s.targetName==="line")this.events.emit("drawing:click",{id:s.drawing.id});else if(s.targetName?.startsWith("point")){const o=s.targetName==="point-start"?0:1;this.events.emit("drawing:point:click",{id:s.drawing.id,pointIndex:o})}}}),this.chart.getZr().on("click",i=>{i.target||this.selectedDrawingId&&(this.events.emit("drawing:deselected",{id:this.selectedDrawingId}),this.selectedDrawingId=null,this.render())})}getChart(){return this.chart}getMarketData(){return this.marketData}getTimeToIndex(){return this.timeToIndex}getOptions(){return this.options}disableTools(){this.pluginManager.deactivatePlugin()}registerPlugin(t){this.pluginManager.register(t)}addDrawing(t){this.drawings.push(t),this.render()}removeDrawing(t){const e=this.drawings.findIndex(i=>i.id===t);if(e!==-1){const i=this.drawings[e];this.drawings.splice(e,1),this.events.emit("drawing:deleted",{id:i.id}),this.render()}}getDrawing(t){return this.drawings.find(e=>e.id===t)}updateDrawing(t){const e=this.drawings.findIndex(i=>i.id===t.id);e!==-1&&(this.drawings[e]=t,this.render())}lockChart(){if(this.isLocked)return;this.isLocked=!0;const t=this.chart.getOption();this.chart.setOption({dataZoom:t.dataZoom.map(e=>({...e,disabled:!0})),tooltip:{show:!1}})}unlockChart(){if(!this.isLocked)return;this.isLocked=!1;const t=this.chart.getOption();(this.options.dataZoom||{}).visible,t.dataZoom&&this.chart.setOption({dataZoom:t.dataZoom.map(e=>({...e,disabled:!1})),tooltip:{show:!0}})}setZoom(t,e){this.chart.dispatchAction({type:"dataZoom",start:t,end:e})}setMarketData(t){this.marketData=t,this.rebuildTimeIndex(),this.render()}updateData(t){if(t.length===0)return;const e=new Map;this.marketData.forEach(r=>{e.set(r.time,r)}),t.forEach(r=>{e.has(r.time),e.set(r.time,r)}),this.marketData=Array.from(e.values()).sort((r,x)=>r.time-x.time),this.rebuildTimeIndex();const i=this.dataIndexOffset,s=pt.buildCandlestickSeries(this.marketData,this.options),o={value:[NaN,NaN,NaN,NaN],itemStyle:{opacity:0}},l=[...Array(i).fill(o),...s.data,...Array(i).fill(o)],d=[...Array(i).fill(""),...this.marketData.map(r=>new Date(r.time).toLocaleString()),...Array(i).fill("")],h=this.chart.getOption(),p=Ct.calculate(this.chart.getHeight(),this.indicators,this.options,this.isMainCollapsed,this.maximizedPaneId,this.marketData),y=[...Array(i).fill(null),...this.marketData,...Array(i).fill(null)],{series:c,barColors:u}=pt.buildIndicatorSeries(this.indicators,this.timeToIndex,p.paneLayout,d.length,i,y,p.overlayYAxisMap,p.separatePaneYAxisOffset),a=l.map((r,x)=>u[x]?{value:r.value||r,itemStyle:{color:u[x],color0:u[x],borderColor:u[x],borderColor0:u[x]}}:r),n={xAxis:h.xAxis.map((r,x)=>({data:d})),series:[{data:a,markLine:s.markLine},...c.map(r=>{const x={data:r.data};return r.renderItem&&(x.renderItem=r.renderItem),x})]};this.chart.setOption(n,{notMerge:!1});const f=[];this.indicators.forEach(r=>{Object.values(r.plots).forEach(x=>{x.options?.style==="table"&&x.data?.forEach(w=>{(Array.isArray(w.value)?w.value:[w.value]).forEach(S=>{S&&!S._deleted&&f.push(S)})})})}),this._lastTables=f,this._renderTableOverlays(),this.startCountdown()}startCountdown(){if(this.stopCountdown(),!this.options.lastPriceLine?.showCountdown||!this.options.interval||this.marketData.length===0)return;const t=()=>{if(this.marketData.length===0)return;const e=this.marketData[this.marketData.length-1].time+(this.options.interval||0),i=Date.now(),s=e-i;if(s<=0)return;const o=Math.abs(s),l=Math.floor(o/36e5),d=Math.floor(o%36e5/6e4),h=Math.floor(o%6e4/1e3),p=`${l>0?l.toString().padStart(2,"0")+":":""}${d.toString().padStart(2,"0")}:${h.toString().padStart(2,"0")}`,y=this.chart.getOption();if(!y||!y.series)return;const c=y.series.findIndex(x=>x.type==="candlestick");if(c===-1)return;const u=y.series[c];if(!u.markLine||!u.markLine.data||!u.markLine.data[0])return;const a=u.markLine.data[0];a.label.formatter;const n=a.yAxis;let f="";if(this.options.yAxisLabelFormatter)f=this.options.yAxisLabelFormatter(n);else{const x=this.options.yAxisDecimalPlaces!==void 0?this.options.yAxisDecimalPlaces:W.autoDetectDecimals(this.marketData);f=W.formatValue(n,x)}const r=`${f}
37
+ ${p}`;this.chart.setOption({series:[{name:this.options.title||"Market",markLine:{data:[{...a,label:{...a.label,formatter:r}}]}}]})};t(),this.countdownInterval=setInterval(t,1e3)}stopCountdown(){this.countdownInterval&&(clearInterval(this.countdownInterval),this.countdownInterval=null)}addIndicator(t,e,i={}){const s=i.overlay!==void 0?i.overlay:i.isOverlay??!1;let o=0;if(!s){let d=0;this.indicators.forEach(h=>{h.paneIndex>d&&(d=h.paneIndex)}),o=d+1}const l=new _t(t,e,o,{height:i.height,collapsed:!1,titleColor:i.titleColor,controls:i.controls});return this.indicators.set(t,l),this.render(),l}setIndicator(t,e,i=!1){this.addIndicator(t,{[t]:e},{overlay:i})}removeIndicator(t){this.indicators.delete(t),this.render()}toggleIndicator(t,e="collapse"){if(e==="fullscreen"){document.fullscreenElement?document.exitFullscreen():this.rootContainer.requestFullscreen();return}if(e==="maximize"){this.maximizedPaneId===t?this.maximizedPaneId=null:this.maximizedPaneId=t,this.render();return}if(t==="main"){this.isMainCollapsed=!this.isMainCollapsed,this.render();return}const i=this.indicators.get(t);i&&(i.toggleCollapse(),this.render())}resize(){this.chart.resize(),this._renderTableOverlays()}_renderTableOverlays(){const t=this.chart.getModel().getComponent("grid",0)?.coordinateSystem?.getRect();Q.render(this.overlayContainer,this._lastTables,t)}destroy(){this.stopCountdown(),window.removeEventListener("resize",this.resize.bind(this)),document.removeEventListener("fullscreenchange",this.onFullscreenChange),document.removeEventListener("keydown",this.onKeyDown),this.pluginManager.deactivatePlugin(),this.pluginManager.destroy(),this.chart.dispose()}rebuildTimeIndex(){this.timeToIndex.clear(),this.marketData.forEach((i,s)=>{this.timeToIndex.set(i.time,s)});const t=this.marketData.length,e=Math.ceil(t*this.padding);this.dataIndexOffset=e}render(){if(this.marketData.length===0)return;let t=null;try{const C=this.chart.getOption();if(C&&C.dataZoom&&C.dataZoom.length>0){const b=C.dataZoom.find(v=>v.type==="slider"||v.type==="inside");b&&(t={start:b.start,end:b.end})}}catch{}const e=this.options.databox?.position,i=this.leftSidebar.style.display,s=this.rightSidebar.style.display,o=e==="left"?"block":"none",l=e==="right"?"block":"none";(i!==o||s!==l)&&(this.leftSidebar.style.display=o,this.rightSidebar.style.display=l,this.chart.resize());const d=this.dataIndexOffset,h=[...Array(d).fill(""),...this.marketData.map(C=>new Date(C.time).toLocaleString()),...Array(d).fill("")],p=Ct.calculate(this.chart.getHeight(),this.indicators,this.options,this.isMainCollapsed,this.maximizedPaneId,this.marketData);if(!t&&p.dataZoom&&this.marketData.length>0){const C=this.marketData.length,b=h.length,v=d/b,I=C/b;p.dataZoom.forEach(m=>{if(m.start!==void 0){const P=m.start/100,D=v+P*I;m.start=D*100}if(m.end!==void 0){const P=m.end/100,D=v+P*I;m.end=D*100}})}t&&p.dataZoom&&p.dataZoom.forEach(C=>{C.start=t.start,C.end=t.end}),p.xAxis.forEach(C=>{C.data=h,C.boundaryGap=!1});const y=pt.buildCandlestickSeries(this.marketData,this.options),c={value:[NaN,NaN,NaN,NaN],itemStyle:{opacity:0}};y.data=[...Array(d).fill(c),...y.data,...Array(d).fill(c)];const u=[...Array(d).fill(null),...this.marketData,...Array(d).fill(null)],{series:a,barColors:n}=pt.buildIndicatorSeries(this.indicators,this.timeToIndex,p.paneLayout,h.length,d,u,p.overlayYAxisMap,p.separatePaneYAxisOffset);y.data=y.data.map((C,b)=>n[b]?{value:C.value||C,itemStyle:{color:n[b],color0:n[b],borderColor:n[b],borderColor0:n[b]}}:C);const f=Vt.build(p,this.options,this.toggleIndicator.bind(this),this.isMainCollapsed,this.maximizedPaneId),r=new Map;this.drawings.forEach(C=>{const b=C.paneIndex||0;r.has(b)||r.set(b,[]),r.get(b).push(C)});const x=[];r.forEach((C,b)=>{x.push({type:"custom",name:`drawings-pane-${b}`,xAxisIndex:b,yAxisIndex:b,clip:!0,renderItem:(v,I)=>{const m=C[v.dataIndex];if(!m)return;const P=m.points[0],D=m.points[1];if(!P||!D)return;const M=I.coord([P.timeIndex,P.value]),_=I.coord([D.timeIndex,D.value]),L=m.id===this.selectedDrawingId;if(m.type==="line")return{type:"group",children:[{type:"line",name:"line",shape:{x1:M[0],y1:M[1],x2:_[0],y2:_[1]},style:{stroke:m.style?.color||"#3b82f6",lineWidth:m.style?.lineWidth||2}},{type:"circle",name:"point-start",shape:{cx:M[0],cy:M[1],r:4},style:{fill:"#fff",stroke:m.style?.color||"#3b82f6",lineWidth:1,opacity:L?1:0}},{type:"circle",name:"point-end",shape:{cx:_[0],cy:_[1],r:4},style:{fill:"#fff",stroke:m.style?.color||"#3b82f6",lineWidth:1,opacity:L?1:0}}]};if(m.type==="fibonacci"){const R=M[0],O=M[1],J=_[0],U=_[1],tt=Math.min(R,J),et=Math.max(R,J),k=et-tt,z=U-O,E=[0,.236,.382,.5,.618,.786,1],F=["#787b86","#f44336","#ff9800","#4caf50","#2196f3","#00bcd4","#787b86"],H=[];H.push({type:"line",name:"line",shape:{x1:R,y1:O,x2:J,y2:U},style:{stroke:"#999",lineWidth:1,lineDash:[4,4]}}),H.push({type:"circle",name:"point-start",shape:{cx:R,cy:O,r:4},style:{fill:"#fff",stroke:m.style?.color||"#3b82f6",lineWidth:1,opacity:L?1:0},z:100}),H.push({type:"circle",name:"point-end",shape:{cx:J,cy:U,r:4},style:{fill:"#fff",stroke:m.style?.color||"#3b82f6",lineWidth:1,opacity:L?1:0},z:100}),E.forEach((j,N)=>{const T=U-z*j,it=F[N%F.length];H.push({type:"line",name:"fib-line",shape:{x1:tt,y1:T,x2:et,y2:T},style:{stroke:it,lineWidth:1},silent:!0});const st=m.points[0].value,q=m.points[1].value,ot=q-st,ft=q-ot*j;if(H.push({type:"text",style:{text:`${j} (${ft.toFixed(2)})`,x:tt+5,y:T-10,fill:it,fontSize:10},silent:!0}),N<E.length-1){const yt=E[N+1],ct=U-z*yt,gt=Math.abs(ct-T),xt=Math.min(T,ct);H.push({type:"rect",shape:{x:tt,y:xt,width:k,height:gt},style:{fill:F[(N+1)%F.length],opacity:.1},silent:!0})}});const Z=[],Y=[];return E.forEach((j,N)=>{const T=U-z*j,it=F[N%F.length];Y.push({type:"line",shape:{x1:tt,y1:T,x2:et,y2:T},style:{stroke:it,lineWidth:1},silent:!0});const st=m.points[0].value,q=m.points[1].value,ot=q-st,ft=q-ot*j;if(Y.push({type:"text",style:{text:`${j} (${ft.toFixed(2)})`,x:tt+5,y:T-10,fill:it,fontSize:10},silent:!0}),N<E.length-1){const yt=E[N+1],ct=U-z*yt,gt=Math.abs(ct-T),xt=Math.min(T,ct);Z.push({type:"rect",name:"line",shape:{x:tt,y:xt,width:k,height:gt},style:{fill:F[(N+1)%F.length],opacity:.1}})}}),{type:"group",children:[...Z,...Y,{type:"line",name:"line",shape:{x1:R,y1:O,x2:J,y2:U},style:{stroke:"#999",lineWidth:1,lineDash:[4,4]}},{type:"circle",name:"point-start",shape:{cx:R,cy:O,r:4},style:{fill:"#fff",stroke:m.style?.color||"#3b82f6",lineWidth:1,opacity:L?1:0},z:100},{type:"circle",name:"point-end",shape:{cx:J,cy:U,r:4},style:{fill:"#fff",stroke:m.style?.color||"#3b82f6",lineWidth:1,opacity:L?1:0},z:100}]}}},data:C.map(v=>[v.points[0].timeIndex,v.points[0].value,v.points[1].timeIndex,v.points[1].value]),encode:{x:[0,2],y:[1,3]},z:100,silent:!1})});const w=C=>{const b=Xt.format(C,this.options),v=this.options.databox?.position;return v==="left"?(this.leftSidebar.innerHTML=b,""):v==="right"?(this.rightSidebar.innerHTML=b,""):this.options.databox?`<div style="min-width: 200px;">${b}</div>`:""},S=[];this.indicators.forEach(C=>{Object.values(C.plots).forEach(b=>{b.options?.style==="table"&&b.data?.forEach(v=>{(Array.isArray(v.value)?v.value:[v.value]).forEach(I=>{I&&!I._deleted&&S.push(I)})})})});const A={backgroundColor:this.options.backgroundColor,animation:!1,legend:{show:!1},tooltip:{show:!0,showContent:!!this.options.databox,trigger:"axis",triggerOn:this.options.databox?.triggerOn??"mousemove",axisPointer:{type:"cross",label:{backgroundColor:"#475569"}},backgroundColor:"rgba(30, 41, 59, 0.9)",borderWidth:1,borderColor:"#334155",padding:10,textStyle:{color:"#fff",fontFamily:this.options.fontFamily||"sans-serif"},formatter:w,extraCssText:e!=="floating"&&e!==void 0?"display: none !important;":void 0,position:(C,b,v,I,m)=>{if(this.options.databox?.position==="floating"){const P={top:10};return P[["left","right"][+(C[0]<m.viewSize[0]/2)]]=30,P}return null}},axisPointer:{link:{xAxisIndex:"all"},label:{backgroundColor:"#475569"}},graphic:f,grid:p.grid,xAxis:p.xAxis,yAxis:p.yAxis,dataZoom:p.dataZoom,series:[y,...a,...x]};this.chart.setOption(A,!0),this._lastTables=S,this._renderTableOverlays()}}var le=Object.defineProperty,he=(g,t,e)=>t in g?le(g,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):g[t]=e,dt=(g,t,e)=>(he(g,typeof t!="symbol"?t+"":t,e),e);class ut{constructor(t){dt(this,"id"),dt(this,"name"),dt(this,"icon"),dt(this,"context"),dt(this,"eventListeners",[]),this.id=t.id,this.name=t.name,this.icon=t.icon}init(t){this.context=t,this.onInit()}onInit(){}activate(){this.onActivate(),this.context.events.emit("plugin:activated",this.id)}onActivate(){}deactivate(){this.onDeactivate(),this.context.events.emit("plugin:deactivated",this.id)}onDeactivate(){}destroy(){this.removeAllListeners(),this.onDestroy()}onDestroy(){}on(t,e){this.context.events.on(t,e),this.eventListeners.push({event:t,handler:e})}off(t,e){this.context.events.off(t,e),this.eventListeners=this.eventListeners.filter(i=>i.event!==t||i.handler!==e)}removeAllListeners(){this.eventListeners.forEach(({event:t,handler:e})=>{this.context.events.off(t,e)}),this.eventListeners=[]}get chart(){return this.context.getChart()}get marketData(){return this.context.getMarketData()}}var ce=Object.defineProperty,de=(g,t,e)=>t in g?ce(g,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):g[t]=e,V=(g,t,e)=>(de(g,typeof t!="symbol"?t+"":t,e),e);class pe extends ut{constructor(t){super({id:"measure",name:t?.name||"Measure",icon:t?.icon||'<svg xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 -960 960 960" width="24px" fill="#e3e3e3"><path d="M160-240q-33 0-56.5-23.5T80-320v-320q0-33 23.5-56.5T160-720h640q33 0 56.5 23.5T880-640v320q0 33-23.5 56.5T800-240H160Zm0-80h640v-320H680v160h-80v-160h-80v160h-80v-160h-80v160h-80v-160H160v320Zm120-160h80-80Zm160 0h80-80Zm160 0h80-80Zm-120 0Z"/></svg>'}),V(this,"zr"),V(this,"state","idle"),V(this,"startPoint",null),V(this,"endPoint",null),V(this,"group",null),V(this,"rect",null),V(this,"labelRect",null),V(this,"labelText",null),V(this,"lineV",null),V(this,"lineH",null),V(this,"arrowStart",null),V(this,"arrowEnd",null),V(this,"onMouseDown",()=>{this.state==="finished"&&this.removeGraphic()}),V(this,"onChartInteraction",()=>{this.group&&this.removeGraphic()}),V(this,"onClick",e=>{this.state==="idle"?(this.state="drawing",this.startPoint=[e.offsetX,e.offsetY],this.endPoint=[e.offsetX,e.offsetY],this.initGraphic(),this.updateGraphic()):this.state==="drawing"&&(this.state="finished",this.endPoint=[e.offsetX,e.offsetY],this.updateGraphic(),this.context.disableTools(),this.enableClearListeners())}),V(this,"clearHandlers",{}),V(this,"onMouseMove",e=>{this.state==="drawing"&&(this.endPoint=[e.offsetX,e.offsetY],this.updateGraphic())})}onInit(){this.zr=this.chart.getZr()}onActivate(){this.state="idle",this.chart.getZr().setCursorStyle("crosshair"),this.zr.on("click",this.onClick),this.zr.on("mousemove",this.onMouseMove)}onDeactivate(){this.state="idle",this.chart.getZr().setCursorStyle("default"),this.zr.off("click",this.onClick),this.zr.off("mousemove",this.onMouseMove),this.disableClearListeners(),this.state==="drawing"&&this.removeGraphic()}onDestroy(){this.removeGraphic()}enableClearListeners(){const t=()=>{this.removeGraphic()};setTimeout(()=>{this.zr.on("click",t)},10),this.zr.on("mousedown",this.onMouseDown),this.context.events.on("chart:dataZoom",this.onChartInteraction),this.clearHandlers={click:t,mousedown:this.onMouseDown,dataZoom:this.onChartInteraction}}disableClearListeners(){this.clearHandlers.click&&this.zr.off("click",this.clearHandlers.click),this.clearHandlers.mousedown&&this.zr.off("mousedown",this.clearHandlers.mousedown),this.clearHandlers.dataZoom&&this.context.events.off("chart:dataZoom",this.clearHandlers.dataZoom),this.clearHandlers={}}initGraphic(){this.group||(this.group=new G.graphic.Group,this.rect=new G.graphic.Rect({shape:{x:0,y:0,width:0,height:0},style:{fill:"rgba(0,0,0,0)",stroke:"transparent",lineWidth:0},z:100}),this.lineV=new G.graphic.Line({shape:{x1:0,y1:0,x2:0,y2:0},style:{stroke:"#fff",lineWidth:1,lineDash:[4,4]},z:101}),this.lineH=new G.graphic.Line({shape:{x1:0,y1:0,x2:0,y2:0},style:{stroke:"#fff",lineWidth:1,lineDash:[4,4]},z:101}),this.arrowStart=new G.graphic.Polygon({shape:{points:[[0,0],[-5,10],[5,10]]},style:{fill:"#fff"},z:102}),this.arrowEnd=new G.graphic.Polygon({shape:{points:[[0,0],[-5,-10],[5,-10]]},style:{fill:"#fff"},z:102}),this.labelRect=new G.graphic.Rect({shape:{x:0,y:0,width:0,height:0,r:4},style:{fill:"transparent",stroke:"transparent",lineWidth:0,shadowBlur:5,shadowColor:"rgba(0,0,0,0.3)"},z:102}),this.labelText=new G.graphic.Text({style:{x:0,y:0,text:"",fill:"#fff",font:"12px sans-serif",align:"center",verticalAlign:"middle"},z:103}),this.group.add(this.rect),this.group.add(this.lineV),this.group.add(this.lineH),this.group.add(this.arrowStart),this.group.add(this.arrowEnd),this.group.add(this.labelRect),this.group.add(this.labelText),this.zr.add(this.group))}removeGraphic(){this.group&&(this.zr.remove(this.group),this.group=null,this.disableClearListeners())}updateGraphic(){if(!this.startPoint||!this.endPoint||!this.group)return;const[t,e]=this.startPoint,[i,s]=this.endPoint,o=this.context.coordinateConversion.pixelToData({x:t,y:e}),l=this.context.coordinateConversion.pixelToData({x:i,y:s});if(!o||!l)return;const d=Math.round(o.timeIndex),h=Math.round(l.timeIndex),p=o.value,y=l.value,c=h-d,u=y-p,a=u/p*100,n=u>=0,f=n?"rgba(33, 150, 243, 0.2)":"rgba(236, 0, 0, 0.2)",r=n?"#2196F3":"#ec0000";this.rect.setShape({x:Math.min(t,i),y:Math.min(e,s),width:Math.abs(i-t),height:Math.abs(s-e)}),this.rect.setStyle({fill:f});const x=(t+i)/2,w=(e+s)/2;this.lineV.setShape({x1:x,y1:e,x2:x,y2:s}),this.lineV.setStyle({stroke:r}),this.lineH.setShape({x1:t,y1:w,x2:i,y2:w}),this.lineH.setStyle({stroke:r});const S=Math.min(e,s),A=Math.max(e,s);this.arrowStart.setStyle({fill:"none"}),this.arrowEnd.setStyle({fill:"none"}),n?(this.arrowStart.setShape({points:[[x,S],[x-4,S+6],[x+4,S+6]]}),this.arrowStart.setStyle({fill:r})):(this.arrowEnd.setShape({points:[[x,A],[x-4,A-6],[x+4,A-6]]}),this.arrowEnd.setStyle({fill:r}));const C=[`${u.toFixed(2)} (${a.toFixed(2)}%)`,`${c} bars, ${(c*0).toFixed(0)}d`].join(`
38
+ `),b=140,v=40,I=Math.max(e,s),m=Math.min(e,s);let P=(t+i)/2-b/2,D=I+10;const M=this.chart.getHeight();D+v>M&&(D=m-v-10),this.labelRect.setShape({x:P,y:D,width:b,height:v}),this.labelRect.setStyle({fill:"#1e293b",stroke:r,lineWidth:1}),this.labelText.setStyle({x:P+b/2,y:D+v/2,text:C,fill:"#fff"})}}var ue=Object.defineProperty,fe=(g,t,e)=>t in g?ue(g,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):g[t]=e,K=(g,t,e)=>(fe(g,typeof t!="symbol"?t+"":t,e),e);class ye extends ut{constructor(t){super({id:"trend-line",name:t?.name||"Trend Line",icon:t?.icon||'<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><line x1="2" y1="22" x2="22" y2="2" /></svg>'}),K(this,"zr"),K(this,"state","idle"),K(this,"startPoint",null),K(this,"endPoint",null),K(this,"group",null),K(this,"line",null),K(this,"startCircle",null),K(this,"endCircle",null),K(this,"onMouseDown",()=>{}),K(this,"onChartInteraction",()=>{}),K(this,"onClick",e=>{if(this.state==="idle")this.state="drawing",this.startPoint=[e.offsetX,e.offsetY],this.endPoint=[e.offsetX,e.offsetY],this.initGraphic(),this.updateGraphic();else if(this.state==="drawing"){if(this.state="finished",this.endPoint=[e.offsetX,e.offsetY],this.updateGraphic(),this.startPoint&&this.endPoint){const i=this.context.coordinateConversion.pixelToData({x:this.startPoint[0],y:this.startPoint[1]}),s=this.context.coordinateConversion.pixelToData({x:this.endPoint[0],y:this.endPoint[1]});if(i&&s){const o=i.paneIndex||0;this.context.addDrawing({id:`line-${Date.now()}`,type:"line",points:[i,s],paneIndex:o,style:{color:"#3b82f6",lineWidth:2}})}}this.removeGraphic(),this.context.disableTools()}}),K(this,"clearHandlers",{}),K(this,"onMouseMove",e=>{this.state==="drawing"&&(this.endPoint=[e.offsetX,e.offsetY],this.updateGraphic())})}onInit(){this.zr=this.chart.getZr()}onActivate(){this.state="idle",this.chart.getZr().setCursorStyle("crosshair"),this.zr.on("click",this.onClick),this.zr.on("mousemove",this.onMouseMove)}onDeactivate(){this.state="idle",this.chart.getZr().setCursorStyle("default"),this.zr.off("click",this.onClick),this.zr.off("mousemove",this.onMouseMove),this.disableClearListeners(),this.state==="drawing"&&this.removeGraphic()}onDestroy(){this.removeGraphic()}saveDataCoordinates(){}updateGraphicFromData(){}enableClearListeners(){}disableClearListeners(){}initGraphic(){this.group||(this.group=new G.graphic.Group,this.line=new G.graphic.Line({shape:{x1:0,y1:0,x2:0,y2:0},style:{stroke:"#3b82f6",lineWidth:2},z:100}),this.startCircle=new G.graphic.Circle({shape:{cx:0,cy:0,r:4},style:{fill:"#fff",stroke:"#3b82f6",lineWidth:1},z:101}),this.endCircle=new G.graphic.Circle({shape:{cx:0,cy:0,r:4},style:{fill:"#fff",stroke:"#3b82f6",lineWidth:1},z:101}),this.group.add(this.line),this.group.add(this.startCircle),this.group.add(this.endCircle),this.zr.add(this.group))}removeGraphic(){this.group&&(this.zr.remove(this.group),this.group=null,this.disableClearListeners())}updateGraphic(){if(!this.startPoint||!this.endPoint||!this.group)return;const[t,e]=this.startPoint,[i,s]=this.endPoint;this.line.setShape({x1:t,y1:e,x2:i,y2:s}),this.startCircle.setShape({cx:t,cy:e}),this.endCircle.setShape({cx:i,cy:s})}}var ge=Object.defineProperty,xe=(g,t,e)=>t in g?ge(g,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):g[t]=e,nt=(g,t,e)=>(xe(g,typeof t!="symbol"?t+"":t,e),e);class me extends ut{constructor(t={}){super({id:"fibonacci-tool",name:t.name||"Fibonacci Retracement",icon:t.icon||'<svg xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 -960 960 960" width="24px" fill="#e3e3e3"><path d="M120-80v-80h720v80H120Zm0-240v-80h720v80H120Zm0-240v-80h720v80H120Zm0-240v-80h720v80H120Z"/></svg>'}),nt(this,"startPoint",null),nt(this,"endPoint",null),nt(this,"state","idle"),nt(this,"graphicGroup",null),nt(this,"levels",[0,.236,.382,.5,.618,.786,1]),nt(this,"colors",["#787b86","#f44336","#ff9800","#4caf50","#2196f3","#00bcd4","#787b86"]),nt(this,"onClick",e=>{this.state==="idle"?(this.state="drawing",this.startPoint=[e.offsetX,e.offsetY],this.endPoint=[e.offsetX,e.offsetY],this.initGraphic(),this.updateGraphic()):this.state==="drawing"&&(this.state="finished",this.endPoint=[e.offsetX,e.offsetY],this.updateGraphic(),this.saveDrawing(),this.removeGraphic(),this.context.disableTools())}),nt(this,"onMouseMove",e=>{this.state==="drawing"&&(this.endPoint=[e.offsetX,e.offsetY],this.updateGraphic())})}onActivate(){this.state="idle",this.startPoint=null,this.endPoint=null,this.context.getChart().getZr().setCursorStyle("crosshair"),this.bindEvents()}onDeactivate(){this.state="idle",this.startPoint=null,this.endPoint=null,this.removeGraphic(),this.unbindEvents(),this.context.getChart().getZr().setCursorStyle("default")}bindEvents(){const t=this.context.getChart().getZr();t.on("click",this.onClick),t.on("mousemove",this.onMouseMove)}unbindEvents(){const t=this.context.getChart().getZr();t.off("click",this.onClick),t.off("mousemove",this.onMouseMove)}initGraphic(){this.graphicGroup=new G.graphic.Group,this.context.getChart().getZr().add(this.graphicGroup)}removeGraphic(){this.graphicGroup&&(this.context.getChart().getZr().remove(this.graphicGroup),this.graphicGroup=null)}updateGraphic(){if(!this.graphicGroup||!this.startPoint||!this.endPoint)return;this.graphicGroup.removeAll();const t=this.startPoint[0],e=this.startPoint[1],i=this.endPoint[0],s=this.endPoint[1],o=new G.graphic.Line({shape:{x1:t,y1:e,x2:i,y2:s},style:{stroke:"#999",lineWidth:1,lineDash:[4,4]},silent:!0});this.graphicGroup.add(o);const l=Math.min(t,i),d=Math.max(t,i),h=d-l,p=s-e;this.levels.forEach((y,c)=>{const u=s-p*y,a=this.colors[c%this.colors.length],n=new G.graphic.Line({shape:{x1:l,y1:u,x2:d,y2:u},style:{stroke:a,lineWidth:1},silent:!0});if(this.graphicGroup.add(n),c<this.levels.length-1){const f=this.levels[c+1],r=s-p*f,x=Math.abs(r-u),w=Math.min(u,r),S=new G.graphic.Rect({shape:{x:l,y:w,width:h,height:x},style:{fill:this.colors[(c+1)%this.colors.length],opacity:.1},silent:!0});this.graphicGroup.add(S)}})}saveDrawing(){if(!this.startPoint||!this.endPoint)return;const t=this.context.coordinateConversion.pixelToData({x:this.startPoint[0],y:this.startPoint[1]}),e=this.context.coordinateConversion.pixelToData({x:this.endPoint[0],y:this.endPoint[1]});if(t&&e){const i=t.paneIndex||0;this.context.addDrawing({id:`fib-${Date.now()}`,type:"fibonacci",points:[t,e],paneIndex:i,style:{color:"#3b82f6",lineWidth:1}})}}}export{ut as AbstractPlugin,me as FibonacciTool,ye as LineTool,pe as MeasureTool,re as QFChart};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@qfo/qfchart",
3
- "version": "0.6.8",
3
+ "version": "0.7.2",
4
4
  "description": "Professional financial charting library built on Apache ECharts with candlestick charts, technical indicators, and interactive drawing tools",
5
5
  "keywords": [
6
6
  "chart",
@@ -19,7 +19,7 @@
19
19
  "fibonacci",
20
20
  "typescript"
21
21
  ],
22
- "homepage": "https://github.com/QuantForgeOrg/QFChart#readme",
22
+ "homepage": "https://quantforge.org/qfchart/",
23
23
  "bugs": {
24
24
  "url": "https://github.com/QuantForgeOrg/QFChart/issues"
25
25
  },
package/src/QFChart.ts CHANGED
@@ -9,6 +9,7 @@ import { PluginManager } from './components/PluginManager';
9
9
  import { DrawingEditor } from './components/DrawingEditor';
10
10
  import { EventBus } from './utils/EventBus';
11
11
  import { AxisUtils } from './utils/AxisUtils';
12
+ import { TableOverlayRenderer } from './components/TableOverlayRenderer';
12
13
 
13
14
  export class QFChart implements ChartContext {
14
15
  private chart: echarts.ECharts;
@@ -86,6 +87,8 @@ export class QFChart implements ChartContext {
86
87
  private leftSidebar: HTMLElement;
87
88
  private rightSidebar: HTMLElement;
88
89
  private chartContainer: HTMLElement;
90
+ private overlayContainer: HTMLElement;
91
+ private _lastTables: any[] = [];
89
92
 
90
93
  constructor(container: HTMLElement, options: QFChartOptions = {}) {
91
94
  this.rootContainer = container;
@@ -176,6 +179,13 @@ export class QFChart implements ChartContext {
176
179
  this.layoutContainer.appendChild(this.rightSidebar);
177
180
 
178
181
  this.chart = echarts.init(this.chartContainer);
182
+
183
+ // Overlay container for table rendering (positioned above ECharts canvas)
184
+ this.chartContainer.style.position = 'relative';
185
+ this.overlayContainer = document.createElement('div');
186
+ this.overlayContainer.style.cssText = 'position:absolute;top:0;left:0;width:100%;height:100%;pointer-events:none;z-index:100;overflow:hidden;';
187
+ this.chartContainer.appendChild(this.overlayContainer);
188
+
179
189
  this.pluginManager = new PluginManager(this, this.toolbarContainer);
180
190
  this.drawingEditor = new DrawingEditor(this);
181
191
 
@@ -727,6 +737,23 @@ export class QFChart implements ChartContext {
727
737
  // Merge the update (don't replace entire config)
728
738
  this.chart.setOption(updateOption, { notMerge: false });
729
739
 
740
+ // Re-render table overlays (indicators may have updated table data)
741
+ const allTables: any[] = [];
742
+ this.indicators.forEach((indicator) => {
743
+ Object.values(indicator.plots).forEach((plot: any) => {
744
+ if (plot.options?.style === 'table') {
745
+ plot.data?.forEach((entry: any) => {
746
+ const tables = Array.isArray(entry.value) ? entry.value : [entry.value];
747
+ tables.forEach((t: any) => {
748
+ if (t && !t._deleted) allTables.push(t);
749
+ });
750
+ });
751
+ }
752
+ });
753
+ });
754
+ this._lastTables = allTables;
755
+ this._renderTableOverlays();
756
+
730
757
  // Update countdown if needed
731
758
  this.startCountdown();
732
759
  }
@@ -926,6 +953,12 @@ export class QFChart implements ChartContext {
926
953
 
927
954
  public resize(): void {
928
955
  this.chart.resize();
956
+ this._renderTableOverlays();
957
+ }
958
+
959
+ private _renderTableOverlays(): void {
960
+ const gridRect = (this.chart.getModel() as any).getComponent('grid', 0)?.coordinateSystem?.getRect();
961
+ TableOverlayRenderer.render(this.overlayContainer, this._lastTables, gridRect);
929
962
  }
930
963
 
931
964
  public destroy(): void {
@@ -1358,6 +1391,7 @@ export class QFChart implements ChartContext {
1358
1391
  }
1359
1392
  },
1360
1393
  data: drawings.map((d) => [d.points[0].timeIndex, d.points[0].value, d.points[1].timeIndex, d.points[1].value]),
1394
+ encode: { x: [0, 2], y: [1, 3] },
1361
1395
  z: 100,
1362
1396
  silent: false,
1363
1397
  });
@@ -1385,6 +1419,20 @@ export class QFChart implements ChartContext {
1385
1419
  return `<div style="min-width: 200px;">${html}</div>`;
1386
1420
  };
1387
1421
 
1422
+ // 6. Extract and render table overlays from indicator plots
1423
+ const allTables: any[] = [];
1424
+ this.indicators.forEach((indicator) => {
1425
+ Object.values(indicator.plots).forEach((plot: any) => {
1426
+ if (plot.options?.style === 'table') {
1427
+ plot.data?.forEach((entry: any) => {
1428
+ const tables = Array.isArray(entry.value) ? entry.value : [entry.value];
1429
+ tables.forEach((t: any) => {
1430
+ if (t && !t._deleted) allTables.push(t);
1431
+ });
1432
+ });
1433
+ }
1434
+ });
1435
+ });
1388
1436
  const option: any = {
1389
1437
  backgroundColor: this.options.backgroundColor,
1390
1438
  animation: false,
@@ -1430,5 +1478,9 @@ export class QFChart implements ChartContext {
1430
1478
  };
1431
1479
 
1432
1480
  this.chart.setOption(option, true); // true = not merge, replace.
1481
+
1482
+ // Render table overlays AFTER setOption so we can query the computed grid rect
1483
+ this._lastTables = allTables;
1484
+ this._renderTableOverlays();
1433
1485
  }
1434
1486
  }