@qfo/qfchart 0.5.7 → 0.6.0
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.
- package/dist/index.d.ts +6 -2
- package/dist/qfchart.min.browser.js +12 -12
- package/dist/qfchart.min.es.js +14 -14
- package/package.json +1 -1
- package/src/QFChart.ts +35 -3
- package/src/components/SeriesBuilder.ts +202 -2
- package/src/types.ts +18 -2
package/dist/index.d.ts
CHANGED
|
@@ -20,13 +20,15 @@ interface OHLCV {
|
|
|
20
20
|
}
|
|
21
21
|
interface IndicatorPoint {
|
|
22
22
|
time: number;
|
|
23
|
-
value: number | null;
|
|
23
|
+
value: number | number[] | null;
|
|
24
24
|
options?: {
|
|
25
25
|
color?: string;
|
|
26
26
|
offset?: number;
|
|
27
|
+
wickcolor?: string;
|
|
28
|
+
bordercolor?: string;
|
|
27
29
|
};
|
|
28
30
|
}
|
|
29
|
-
type IndicatorStyle = 'line' | 'step' | 'columns' | 'histogram' | 'circles' | 'cross' | 'background' | 'shape';
|
|
31
|
+
type IndicatorStyle = 'line' | 'step' | 'columns' | 'histogram' | 'circles' | 'cross' | 'background' | 'shape' | 'char' | 'bar' | 'candle' | 'barcolor';
|
|
30
32
|
interface IndicatorOptions {
|
|
31
33
|
style: IndicatorStyle;
|
|
32
34
|
color: string;
|
|
@@ -40,6 +42,8 @@ interface IndicatorOptions {
|
|
|
40
42
|
location?: string;
|
|
41
43
|
width?: number;
|
|
42
44
|
height?: number;
|
|
45
|
+
wickcolor?: string;
|
|
46
|
+
bordercolor?: string;
|
|
43
47
|
}
|
|
44
48
|
interface IndicatorPlot {
|
|
45
49
|
data: IndicatorPoint[];
|
|
@@ -14,24 +14,24 @@
|
|
|
14
14
|
* See the License for the specific language governing permissions and
|
|
15
15
|
* limitations under the License.
|
|
16
16
|
*/
|
|
17
|
-
(function(B,_){typeof exports=="object"&&typeof module<"u"?_(exports,require("echarts")):typeof define=="function"&&define.amd?define(["exports","echarts"],_):(B=typeof globalThis<"u"?globalThis:B||self,_(B.QFChart={},B.echarts))})(this,function(B,_){"use strict";function ft(a){var e=Object.create(null);return a&&Object.keys(a).forEach(function(t){if(t!=="default"){var i=Object.getOwnPropertyDescriptor(a,t);Object.defineProperty(e,t,i.get?i:{enumerable:!0,get:function(){return a[t]}})}}),e.default=a,Object.freeze(e)}var E=ft(_),yt=Object.defineProperty,xt=(a,e,t)=>e in a?yt(a,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):a[e]=t,U=(a,e,t)=>(xt(a,typeof e!="symbol"?e+"":e,t),t);class mt{constructor(e,t,i,s={}){U(this,"id"),U(this,"plots"),U(this,"paneIndex"),U(this,"height"),U(this,"collapsed"),U(this,"titleColor"),U(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];s.options&&(i.options={...i.options,...s.options});const n=new Map;i.data.forEach(o=>{n.set(o.time,o)}),s.data.forEach(o=>{n.set(o.time,o)}),i.data=Array.from(n.values()).sort((o,r)=>o.time-r.time)}})}}class ut{static calculate(e,t,i,s=!1,n=null){let o=0;e>0&&(o=1/e*100);const r=Array.from(t.values()).map(g=>g.paneIndex).filter(g=>g>0).sort((g,w)=>g-w).filter((g,w,z)=>z.indexOf(g)===w),p=r.length>0,u=i.dataZoom?.visible??!0,v=i.dataZoom?.position??"top",f=i.dataZoom?.height??6,m=i.dataZoom?.start??0,d=i.dataZoom?.end??100;let x=8,S=92,I=-1;if(n)if(n==="main")I=0;else{const g=t.get(n);g&&(I=g.paneIndex)}if(I!==-1){const g=[],w=[],z=[],O=[],W=i.dataZoom?.start??50,P=i.dataZoom?.end??100;O.push({type:"inside",xAxisIndex:"all",start:W,end:P});const M=p?Math.max(...r):0,Z=[];for(let N=0;N<=M;N++){const A=N===I;if(g.push({left:"10%",right:"10%",top:A?"5%":"0%",height:A?"90%":"0%",show:A,containLabel:!1}),w.push({type:"category",gridIndex:N,data:[],show:A,axisLabel:{show:A,color:"#94a3b8",fontFamily:i.fontFamily},axisLine:{show:A,lineStyle:{color:"#334155"}},splitLine:{show:A,lineStyle:{color:"#334155",opacity:.5}}}),z.push({position:"right",gridIndex:N,show:A,scale:!0,axisLabel:{show:A,color:"#94a3b8",fontFamily:i.fontFamily},splitLine:{show:A,lineStyle:{color:"#334155",opacity:.5}}}),N>0){const j=Array.from(t.values()).find(H=>H.paneIndex===N);j&&Z.push({index:N,height:A?90:0,top:A?5:0,isCollapsed:!1,indicatorId:j.id,titleColor:j.titleColor,controls:j.controls})}}return{grid:g,xAxis:w,yAxis:z,dataZoom:O,paneLayout:Z,mainPaneHeight:I===0?90:0,mainPaneTop:I===0?5:0,pixelToPercent:o}}u?v==="top"?(x=f+4,S=95):(S=100-f-2,x=8):(x=5,S=95);let L=5;e>0&&(L=20/e*100);let D=75,y=[];if(p){const g=r.map(P=>{const M=Array.from(t.values()).find(Z=>Z.paneIndex===P);return{index:P,requestedHeight:M?.height,isCollapsed:M?.collapsed??!1,indicatorId:M?.id,titleColor:M?.titleColor,controls:M?.controls}}).map(P=>({...P,height:P.isCollapsed?3:P.requestedHeight!==void 0?P.requestedHeight:15})),w=g.reduce((P,M)=>P+M.height,0),z=g.length*L,O=w+z;D=S-x-O,s?D=3:D<20&&(D=Math.max(D,10));let W=x+D+L;y=g.map(P=>{const M={index:P.index,height:P.height,top:W,isCollapsed:P.isCollapsed,indicatorId:P.indicatorId,titleColor:P.titleColor,controls:P.controls};return W+=P.height+L,M})}else D=S-x,s&&(D=3);const c=[];c.push({left:"10%",right:"10%",top:x+"%",height:D+"%",containLabel:!1}),y.forEach(g=>{c.push({left:"10%",right:"10%",top:g.top+"%",height:g.height+"%",containLabel:!1})});const l=[0,...y.map((g,w)=>w+1)],b=[],h=y.length===0;b.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"},axisTick:{show:!s},axisPointer:{label:{show:h,fontSize:11,backgroundColor:"#475569"}}}),y.forEach((g,w)=>{const z=w===y.length-1;b.push({type:"category",gridIndex:w+1,data:[],axisLabel:{show:!1},axisLine:{show:!g.isCollapsed,lineStyle:{color:"#334155"}},axisTick:{show:!1},splitLine:{show:!1},axisPointer:{label:{show:z,fontSize:11,backgroundColor:"#475569"}}})});const C=[];C.push({position:"right",scale:!0,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"}}),y.forEach((g,w)=>{C.push({position:"right",scale:!0,gridIndex:w+1,splitLine:{show:!g.isCollapsed,lineStyle:{color:"#334155",opacity:.3}},axisLabel:{show:!g.isCollapsed,color:"#94a3b8",fontFamily:i.fontFamily||"sans-serif",fontSize:10},axisLine:{show:!g.isCollapsed,lineStyle:{color:"#334155"}}})});const T=[];return u&&(T.push({type:"inside",xAxisIndex:l,start:m,end:d}),v==="top"?T.push({type:"slider",xAxisIndex:l,top:"1%",height:f+"%",start:m,end:d,borderColor:"#334155",textStyle:{color:"#cbd5e1"},brushSelect:!1}):T.push({type:"slider",xAxisIndex:l,bottom:"1%",height:f+"%",start:m,end:d,borderColor:"#334155",textStyle:{color:"#cbd5e1"},brushSelect:!1})),{grid:c,xAxis:b,yAxis:C,dataZoom:T,paneLayout:y,mainPaneHeight:D,mainPaneTop:x,pixelToPercent:o}}static calculateMaximized(e,t,i){return{grid:[],xAxis:[],yAxis:[],dataZoom:[],paneLayout:[],mainPaneHeight:0,mainPaneTop:0,pixelToPercent:0}}}const ot=new Map;function bt(a,e="#00da3c",t="64px"){if(typeof document>"u")return"";const i=`${a}-${e}-${t}`;if(ot.has(i))return ot.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(a,16,16);const o=s.toDataURL("image/png");return ot.set(i,o),o}return""}class q{static buildCandlestickSeries(e,t,i){const s=t.upColor||"#00da3c",n=t.downColor||"#ec0000",o=e.map(r=>[r.open,r.close,r.low,r.high]);if(i&&i>o.length){const r=i-o.length;for(let p=0;p<r;p++)o.push(null)}return{type:"candlestick",name:t.title||"Market",data:o,itemStyle:{color:s,color0:n,borderColor:s,borderColor0:n},xAxisIndex:0,yAxisIndex:0,z:5}}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://M4 2h16a2 2 0 0 1 2 2v12a2 2 0 0 1 -2 2h-6l-2 4l-2 -4h-6a2 2 0 0 1 -2 -2v-12a2 2 0 0 1 2 -2z";case"labelup":return"path://M12 2l2 4h6a2 2 0 0 1 2 2v12a2 2 0 0 1 -2 2h-16a2 2 0 0 1 -2 -2v-12a2 2 0 0 1 2 -2h6z";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}}}static buildIndicatorSeries(e,t,i,s,n=0,o){const r=[];return e.forEach((p,u)=>{if(p.collapsed)return;let v=0,f=0;if(p.paneIndex>0){const m=i.findIndex(d=>d.index===p.paneIndex);m!==-1&&(v=m+1,f=m+1)}Object.keys(p.plots).forEach(m=>{const d=p.plots[m],x=`${u}::${m}`,S=new Array(s).fill(null),I=new Array(s).fill(null),L=new Array(s).fill(null);switch(d.data.forEach(D=>{const y=t.get(D.time);if(y!==void 0){const c=D.options?.offset??d.options.offset??0,l=y+n+c;if(l>=0&&l<s){let b=D.value;const h=D.options?.color;(h===null||h==="na"||h==="NaN"||typeof h=="number"&&isNaN(h))&&(b=null),S[l]=b,I[l]=h||d.options.color,L[l]=D.options||{}}}}),d.options.style){case"histogram":case"columns":r.push({name:x,type:"bar",xAxisIndex:v,yAxisIndex:f,data:S.map((c,l)=>({value:c,itemStyle:I[l]?{color:I[l]}:void 0})),itemStyle:{color:d.options.color}});break;case"circles":case"cross":const D=S.map((c,l)=>{if(c===null)return null;const b=I[l]||d.options.color,h={value:[l,c],itemStyle:{color:b}};return d.options.style==="cross"?(h.symbol=`image://${bt("+",b,"24px")}`,h.symbolSize=16):(h.symbol="circle",h.symbolSize=6),h}).filter(c=>c!==null);r.push({name:x,type:"scatter",xAxisIndex:v,yAxisIndex:f,data:D});break;case"shape":const y=S.map((c,l)=>{const b=L[l]||{},h=d.options,C=b.location||h.location||"absolute";if(C!=="absolute"&&!c||c==null)return null;const T=b.color||h.color||"blue",g=b.shape||h.shape||"circle",w=b.size||h.size||"normal",z=b.text||h.text,O=b.textcolor||h.textcolor||"white",W=b.width||h.width,P=b.height||h.height;let M=c,Z=[0,0];C==="abovebar"?(o&&o[l]&&(M=o[l].high),Z=[0,"-150%"]):C==="belowbar"?(o&&o[l]&&(M=o[l].low),Z=[0,"150%"]):C==="top"?(M=c,Z=[0,0]):C==="bottom"&&(M=c,Z=[0,0]);const N=q.getShapeSymbol(g),A=q.getShapeSize(w,W,P),j=q.getShapeRotation(g);let H=A;g.includes("label")&&(Array.isArray(A)?H=[A[0]*2.5,A[1]*2.5]:H=A*2.5);const R=q.getLabelConfig(g,C);return{value:[l,M],symbol:N,symbolSize:H,symbolRotate:j,symbolOffset:Z,itemStyle:{color:T},label:{show:!!z,position:R.position,distance:R.distance,formatter:z,color:O,fontSize:10,fontWeight:"bold"}}}).filter(c=>c!==null);r.push({name:x,type:"scatter",xAxisIndex:v,yAxisIndex:f,data:y});break;case"background":r.push({name:x,type:"custom",xAxisIndex:v,yAxisIndex:f,z:-10,renderItem:(c,l)=>{const b=l.value(0);if(isNaN(b))return;const h=l.coord([b,0]),C=l.size([1,0])[0],T=c.coordSys,g=h[0]-C/2,w=I[c.dataIndex],z=l.value(1);if(!(!w||!z))return{type:"rect",shape:{x:g,y:T.y,width:C,height:T.height},style:{fill:w,opacity:.3},silent:!0}},data:S.map((c,l)=>[l,c])});break;case"step":r.push({name:x,type:"custom",xAxisIndex:v,yAxisIndex:f,renderItem:(c,l)=>{const b=l.value(0),h=l.value(1);if(isNaN(h)||h===null)return;const C=l.coord([b,h]),T=l.size([1,0])[0];return{type:"line",shape:{x1:C[0]-T/2,y1:C[1],x2:C[0]+T/2,y2:C[1]},style:{stroke:I[c.dataIndex]||d.options.color,lineWidth:d.options.linewidth||1},silent:!0}},data:S.map((c,l)=>[l,c])});break;case"line":default:r.push({name:x,type:"custom",xAxisIndex:v,yAxisIndex:f,renderItem:(c,l)=>{const b=c.dataIndex;if(b===0)return;const h=l.value(1),C=l.value(2);if(h===null||isNaN(h)||C===null||isNaN(C))return;const T=l.coord([b-1,C]),g=l.coord([b,h]);return{type:"line",shape:{x1:T[0],y1:T[1],x2:g[0],y2:g[1]},style:{stroke:I[b]||d.options.color,lineWidth:d.options.linewidth||1},silent:!0}},data:S.map((c,l)=>[l,c,l>0?S[l-1]:null])});break}})}),r}}class vt{static build(e,t,i,s=!1,n=null){const o=[],r=e.pixelToPercent,p=e.mainPaneTop;if(!n||n==="main"){const u=10*r;if(o.push({type:"text",left:"8.5%",top:p+u+"%",z:10,style:{text:t.title||"Market",fill:t.titleColor||"#fff",font:`bold 16px ${t.fontFamily||"sans-serif"}`,textVerticalAlign:"top"}}),t.watermark!==!1){const f=e.mainPaneTop+e.mainPaneHeight;o.push({type:"text",right:"11%",top:f-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 v=[];if(t.controls?.collapse&&v.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 f=n==="main",m=t.controls?.collapse?25:0;v.push({type:"group",x:m,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:f?"\u2750":"\u25A1",fill:"#cbd5e1",font:`14px ${t.fontFamily}`,x:10,y:10,textAlign:"center",textVerticalAlign:"middle"},silent:!0}]})}if(t.controls?.fullscreen){let f=0;t.controls?.collapse&&(f+=25),t.controls?.maximize&&(f+=25),v.push({type:"group",x:f,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}]})}v.length>0&&o.push({type:"group",right:"10.5%",top:p+"%",children:v})}return e.paneLayout.forEach(u=>{if(n&&u.indicatorId!==n)return;o.push({type:"text",left:"8.5%",top:u.top+10*r+"%",z:10,style:{text:u.indicatorId||"",fill:u.titleColor||"#fff",font:`bold 12px ${t.fontFamily||"sans-serif"}`,textVerticalAlign:"top"}});const v=[];if(u.controls?.collapse&&v.push({type:"group",children:[{type:"rect",shape:{width:20,height:20,r:2},style:{fill:"#334155",stroke:"#475569",lineWidth:1},onclick:()=>u.indicatorId&&i(u.indicatorId,"collapse")},{type:"text",style:{text:u.isCollapsed?"+":"\u2212",fill:"#cbd5e1",font:`bold 14px ${t.fontFamily}`,x:10,y:10,textAlign:"center",textVerticalAlign:"middle"},silent:!0}]}),u.controls?.maximize){const f=n===u.indicatorId,m=u.controls?.collapse?25:0;v.push({type:"group",x:m,children:[{type:"rect",shape:{width:20,height:20,r:2},style:{fill:"#334155",stroke:"#475569",lineWidth:1},onclick:()=>u.indicatorId&&i(u.indicatorId,"maximize")},{type:"text",style:{text:f?"\u2750":"\u25A1",fill:"#cbd5e1",font:`14px ${t.fontFamily}`,x:10,y:10,textAlign:"center",textVerticalAlign:"middle"},silent:!0}]})}v.length>0&&o.push({type:"group",right:"10.5%",top:u.top+"%",children:v})}),o}}class wt{static format(e,t){if(!e||e.length===0)return"";const i=t.title||"Market",s=t.upColor||"#00da3c",n=t.downColor||"#ec0000",o=t.fontFamily||"sans-serif",r=e[0].axisValue;let p=`<div style="font-weight: bold; margin-bottom: 5px; color: #cbd5e1; font-family: ${o};">${r}</div>`;const u=e.find(f=>f.seriesType==="candlestick"),v=e.filter(f=>f.seriesType!=="candlestick");if(u){const[f,m,d,x,S]=u.value,I=d>=m?s:n;p+=`
|
|
17
|
+
(function(B,tt){typeof exports=="object"&&typeof module<"u"?tt(exports,require("echarts")):typeof define=="function"&&define.amd?define(["exports","echarts"],tt):(B=typeof globalThis<"u"?globalThis:B||self,tt(B.QFChart={},B.echarts))})(this,function(B,tt){"use strict";function yt(a){var e=Object.create(null);return a&&Object.keys(a).forEach(function(t){if(t!=="default"){var i=Object.getOwnPropertyDescriptor(a,t);Object.defineProperty(e,t,i.get?i:{enumerable:!0,get:function(){return a[t]}})}}),e.default=a,Object.freeze(e)}var G=yt(tt),xt=Object.defineProperty,mt=(a,e,t)=>e in a?xt(a,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):a[e]=t,K=(a,e,t)=>(mt(a,typeof e!="symbol"?e+"":e,t),t);class bt{constructor(e,t,i,s={}){K(this,"id"),K(this,"plots"),K(this,"paneIndex"),K(this,"height"),K(this,"collapsed"),K(this,"titleColor"),K(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];s.options&&(i.options={...i.options,...s.options});const n=new Map;i.data.forEach(o=>{n.set(o.time,o)}),s.data.forEach(o=>{n.set(o.time,o)}),i.data=Array.from(n.values()).sort((o,h)=>o.time-h.time)}})}}class gt{static calculate(e,t,i,s=!1,n=null){let o=0;e>0&&(o=1/e*100);const h=Array.from(t.values()).map(c=>c.paneIndex).filter(c=>c>0).sort((c,b)=>c-b).filter((c,b,C)=>C.indexOf(c)===b),f=h.length>0,u=i.dataZoom?.visible??!0,M=i.dataZoom?.position??"top",y=i.dataZoom?.height??6,m=i.dataZoom?.start??0,I=i.dataZoom?.end??100;let p=8,g=92,v=-1;if(n)if(n==="main")v=0;else{const c=t.get(n);c&&(v=c.paneIndex)}if(v!==-1){const c=[],b=[],C=[],L=[],N=i.dataZoom?.start??50,P=i.dataZoom?.end??100;L.push({type:"inside",xAxisIndex:"all",start:N,end:P});const k=f?Math.max(...h):0,Z=[];for(let E=0;E<=k;E++){const A=E===v;if(c.push({left:"10%",right:"10%",top:A?"5%":"0%",height:A?"90%":"0%",show:A,containLabel:!1}),b.push({type:"category",gridIndex:E,data:[],show:A,axisLabel:{show:A,color:"#94a3b8",fontFamily:i.fontFamily},axisLine:{show:A,lineStyle:{color:"#334155"}},splitLine:{show:A,lineStyle:{color:"#334155",opacity:.5}}}),C.push({position:"right",gridIndex:E,show:A,scale:!0,axisLabel:{show:A,color:"#94a3b8",fontFamily:i.fontFamily},splitLine:{show:A,lineStyle:{color:"#334155",opacity:.5}}}),E>0){const X=Array.from(t.values()).find(O=>O.paneIndex===E);X&&Z.push({index:E,height:A?90:0,top:A?5:0,isCollapsed:!1,indicatorId:X.id,titleColor:X.titleColor,controls:X.controls})}}return{grid:c,xAxis:b,yAxis:C,dataZoom:L,paneLayout:Z,mainPaneHeight:v===0?90:0,mainPaneTop:v===0?5:0,pixelToPercent:o}}u?M==="top"?(p=y+4,g=95):(g=100-y-2,p=8):(p=5,g=95);let z=5;e>0&&(z=20/e*100);let $=75,T=[];if(f){const c=h.map(P=>{const k=Array.from(t.values()).find(Z=>Z.paneIndex===P);return{index:P,requestedHeight:k?.height,isCollapsed:k?.collapsed??!1,indicatorId:k?.id,titleColor:k?.titleColor,controls:k?.controls}}).map(P=>({...P,height:P.isCollapsed?3:P.requestedHeight!==void 0?P.requestedHeight:15})),b=c.reduce((P,k)=>P+k.height,0),C=c.length*z,L=b+C;$=g-p-L,s?$=3:$<20&&($=Math.max($,10));let N=p+$+z;T=c.map(P=>{const k={index:P.index,height:P.height,top:N,isCollapsed:P.isCollapsed,indicatorId:P.indicatorId,titleColor:P.titleColor,controls:P.controls};return N+=P.height+z,k})}else $=g-p,s&&($=3);const w=[];w.push({left:"10%",right:"10%",top:p+"%",height:$+"%",containLabel:!1}),T.forEach(c=>{w.push({left:"10%",right:"10%",top:c.top+"%",height:c.height+"%",containLabel:!1})});const S=[0,...T.map((c,b)=>b+1)],l=[],r=T.length===0;l.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"},axisTick:{show:!s},axisPointer:{label:{show:r,fontSize:11,backgroundColor:"#475569"}}}),T.forEach((c,b)=>{const C=b===T.length-1;l.push({type:"category",gridIndex:b+1,data:[],axisLabel:{show:!1},axisLine:{show:!c.isCollapsed,lineStyle:{color:"#334155"}},axisTick:{show:!1},splitLine:{show:!1},axisPointer:{label:{show:C,fontSize:11,backgroundColor:"#475569"}}})});const d=[];d.push({position:"right",scale:!0,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"}}),T.forEach((c,b)=>{d.push({position:"right",scale:!0,gridIndex:b+1,splitLine:{show:!c.isCollapsed,lineStyle:{color:"#334155",opacity:.3}},axisLabel:{show:!c.isCollapsed,color:"#94a3b8",fontFamily:i.fontFamily||"sans-serif",fontSize:10},axisLine:{show:!c.isCollapsed,lineStyle:{color:"#334155"}}})});const x=[];return u&&(x.push({type:"inside",xAxisIndex:S,start:m,end:I}),M==="top"?x.push({type:"slider",xAxisIndex:S,top:"1%",height:y+"%",start:m,end:I,borderColor:"#334155",textStyle:{color:"#cbd5e1"},brushSelect:!1}):x.push({type:"slider",xAxisIndex:S,bottom:"1%",height:y+"%",start:m,end:I,borderColor:"#334155",textStyle:{color:"#cbd5e1"},brushSelect:!1})),{grid:w,xAxis:l,yAxis:d,dataZoom:x,paneLayout:T,mainPaneHeight:$,mainPaneTop:p,pixelToPercent:o}}static calculateMaximized(e,t,i){return{grid:[],xAxis:[],yAxis:[],dataZoom:[],paneLayout:[],mainPaneHeight:0,mainPaneTop:0,pixelToPercent:0}}}const at=new Map;function vt(a,e="#00da3c",t="64px"){if(typeof document>"u")return"";const i=`${a}-${e}-${t}`;if(at.has(i))return at.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(a,16,16);const o=s.toDataURL("image/png");return at.set(i,o),o}return""}class U{static buildCandlestickSeries(e,t,i){const s=t.upColor||"#00da3c",n=t.downColor||"#ec0000",o=e.map(h=>[h.open,h.close,h.low,h.high]);if(i&&i>o.length){const h=i-o.length;for(let f=0;f<h;f++)o.push(null)}return{type:"candlestick",name:t.title||"Market",data:o,itemStyle:{color:s,color0:n,borderColor:s,borderColor0:n},xAxisIndex:0,yAxisIndex:0,z:5}}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://M4 2h16a2 2 0 0 1 2 2v12a2 2 0 0 1 -2 2h-6l-2 4l-2 -4h-6a2 2 0 0 1 -2 -2v-12a2 2 0 0 1 2 -2z";case"labelup":return"path://M12 2l2 4h6a2 2 0 0 1 2 2v12a2 2 0 0 1 -2 2h-16a2 2 0 0 1 -2 -2v-12a2 2 0 0 1 2 -2h6z";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}}}static buildIndicatorSeries(e,t,i,s,n=0,o){const h=[],f=new Array(s).fill(null);return e.forEach((u,M)=>{if(u.collapsed)return;let y=0,m=0;if(u.paneIndex>0){const I=i.findIndex(p=>p.index===u.paneIndex);I!==-1&&(y=I+1,m=I+1)}Object.keys(u.plots).forEach(I=>{const p=u.plots[I],g=`${M}::${I}`,v=new Array(s).fill(null),z=new Array(s).fill(null),$=new Array(s).fill(null);switch(p.data.forEach(T=>{const w=t.get(T.time);if(w!==void 0){const S=T.options?.offset??p.options.offset??0,l=w+n+S;if(l>=0&&l<s){let r=T.value;const d=T.options?.color;(d===null||d==="na"||d==="NaN"||typeof d=="number"&&isNaN(d))&&(r=null),v[l]=r,z[l]=d||p.options.color,$[l]=T.options||{}}}}),p.options.style){case"histogram":case"columns":h.push({name:g,type:"bar",xAxisIndex:y,yAxisIndex:m,data:v.map((l,r)=>({value:l,itemStyle:z[r]?{color:z[r]}:void 0})),itemStyle:{color:p.options.color}});break;case"circles":case"cross":const T=v.map((l,r)=>{if(l===null)return null;const d=z[r]||p.options.color,x={value:[r,l],itemStyle:{color:d}};return p.options.style==="cross"?(x.symbol=`image://${vt("+",d,"24px")}`,x.symbolSize=16):(x.symbol="circle",x.symbolSize=6),x}).filter(l=>l!==null);h.push({name:g,type:"scatter",xAxisIndex:y,yAxisIndex:m,data:T});break;case"bar":case"candle":const w=v.map((l,r)=>{if(l===null||!Array.isArray(l)||l.length!==4)return null;const[d,x,c,b]=l,C=$[r]||{},L=C.color||z[r]||p.options.color,N=C.wickcolor||p.options.wickcolor||L,P=C.bordercolor||p.options.bordercolor||N;return[r,d,b,c,x,L,N,P]}).filter(l=>l!==null);h.push({name:g,type:"custom",xAxisIndex:y,yAxisIndex:m,renderItem:(l,r)=>{const d=r.value(0),x=r.value(1),c=r.value(2),b=r.value(3),C=r.value(4),L=r.value(5),N=r.value(6),P=r.value(7);if(isNaN(x)||isNaN(c)||isNaN(b)||isNaN(C))return null;const k=r.coord([d,0])[0],Z=r.coord([d,x])[1],E=r.coord([d,c])[1],A=r.coord([d,b])[1],X=r.coord([d,C])[1],O=r.size([1,0])[0]*.6;if(p.options.style==="candle"){const H=Math.min(Z,E),j=Math.max(Z,E),Y=Math.abs(E-Z);return{type:"group",children:[{type:"line",shape:{x1:k,y1:X,x2:k,y2:H},style:{stroke:N,lineWidth:1}},{type:"line",shape:{x1:k,y1:j,x2:k,y2:A},style:{stroke:N,lineWidth:1}},{type:"rect",shape:{x:k-O/2,y:H,width:O,height:Y||1},style:{fill:L,stroke:P,lineWidth:1}}]}}else{const H=O*.5;return{type:"group",children:[{type:"line",shape:{x1:k,y1:A,x2:k,y2:X},style:{stroke:L,lineWidth:1}},{type:"line",shape:{x1:k-H,y1:Z,x2:k,y2:Z},style:{stroke:L,lineWidth:1}},{type:"line",shape:{x1:k,y1:E,x2:k+H,y2:E},style:{stroke:L,lineWidth:1}}]}}},data:w});break;case"shape":const S=v.map((l,r)=>{const d=$[r]||{},x=p.options,c=d.location||x.location||"absolute";if(c!=="absolute"&&!l||l==null)return null;const b=d.color||x.color||"blue",C=d.shape||x.shape||"circle",L=d.size||x.size||"normal",N=d.text||x.text,P=d.textcolor||x.textcolor||"white",k=d.width||x.width,Z=d.height||x.height;let E=l,A=[0,0];c==="abovebar"?(o&&o[r]&&(E=o[r].high),A=[0,"-150%"]):c==="belowbar"?(o&&o[r]&&(E=o[r].low),A=[0,"150%"]):c==="top"?(E=l,A=[0,0]):c==="bottom"&&(E=l,A=[0,0]);const X=U.getShapeSymbol(C),O=U.getShapeSize(L,k,Z),H=U.getShapeRotation(C);let j=O;C.includes("label")&&(Array.isArray(O)?j=[O[0]*2.5,O[1]*2.5]:j=O*2.5);const Y=U.getLabelConfig(C,c);return{value:[r,E],symbol:X,symbolSize:j,symbolRotate:H,symbolOffset:A,itemStyle:{color:b},label:{show:!!N,position:Y.position,distance:Y.distance,formatter:N,color:P,fontSize:10,fontWeight:"bold"}}}).filter(l=>l!==null);h.push({name:g,type:"scatter",xAxisIndex:y,yAxisIndex:m,data:S});break;case"background":h.push({name:g,type:"custom",xAxisIndex:y,yAxisIndex:m,z:-10,renderItem:(l,r)=>{const d=r.value(0);if(isNaN(d))return;const x=r.coord([d,0]),c=r.size([1,0])[0],b=l.coordSys,C=x[0]-c/2,L=z[l.dataIndex],N=r.value(1);if(!(!L||!N))return{type:"rect",shape:{x:C,y:b.y,width:c,height:b.height},style:{fill:L,opacity:.3},silent:!0}},data:v.map((l,r)=>[r,l])});break;case"step":h.push({name:g,type:"custom",xAxisIndex:y,yAxisIndex:m,renderItem:(l,r)=>{const d=r.value(0),x=r.value(1);if(isNaN(x)||x===null)return;const c=r.coord([d,x]),b=r.size([1,0])[0];return{type:"line",shape:{x1:c[0]-b/2,y1:c[1],x2:c[0]+b/2,y2:c[1]},style:{stroke:z[l.dataIndex]||p.options.color,lineWidth:p.options.linewidth||1},silent:!0}},data:v.map((l,r)=>[r,l])});break;case"barcolor":p.data.forEach(l=>{const r=t.get(l.time);if(r!==void 0){const d=l.options?.offset??p.options.offset??0,x=r+n+d;if(x>=0&&x<s){const c=l.options?.color||p.options.color;!(c===null||c==="na"||c==="NaN"||typeof c=="number"&&isNaN(c))&&l.value&&(f[x]=c)}}});break;case"char":h.push({name:g,type:"scatter",xAxisIndex:y,yAxisIndex:m,symbolSize:0,data:v.map((l,r)=>({value:[r,l],itemStyle:{opacity:0}})),silent:!0});break;case"line":default:h.push({name:g,type:"custom",xAxisIndex:y,yAxisIndex:m,renderItem:(l,r)=>{const d=l.dataIndex;if(d===0)return;const x=r.value(1),c=r.value(2);if(x===null||isNaN(x)||c===null||isNaN(c))return;const b=r.coord([d-1,c]),C=r.coord([d,x]);return{type:"line",shape:{x1:b[0],y1:b[1],x2:C[0],y2:C[1]},style:{stroke:z[d]||p.options.color,lineWidth:p.options.linewidth||1},silent:!0}},data:v.map((l,r)=>[r,l,r>0?v[r-1]:null])});break}})}),{series:h,barColors:f}}}class wt{static build(e,t,i,s=!1,n=null){const o=[],h=e.pixelToPercent,f=e.mainPaneTop;if(!n||n==="main"){const u=10*h;if(o.push({type:"text",left:"8.5%",top:f+u+"%",z:10,style:{text:t.title||"Market",fill:t.titleColor||"#fff",font:`bold 16px ${t.fontFamily||"sans-serif"}`,textVerticalAlign:"top"}}),t.watermark!==!1){const y=e.mainPaneTop+e.mainPaneHeight;o.push({type:"text",right:"11%",top:y-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 M=[];if(t.controls?.collapse&&M.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 y=n==="main",m=t.controls?.collapse?25:0;M.push({type:"group",x:m,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:y?"\u2750":"\u25A1",fill:"#cbd5e1",font:`14px ${t.fontFamily}`,x:10,y:10,textAlign:"center",textVerticalAlign:"middle"},silent:!0}]})}if(t.controls?.fullscreen){let y=0;t.controls?.collapse&&(y+=25),t.controls?.maximize&&(y+=25),M.push({type:"group",x:y,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}]})}M.length>0&&o.push({type:"group",right:"10.5%",top:f+"%",children:M})}return e.paneLayout.forEach(u=>{if(n&&u.indicatorId!==n)return;o.push({type:"text",left:"8.5%",top:u.top+10*h+"%",z:10,style:{text:u.indicatorId||"",fill:u.titleColor||"#fff",font:`bold 12px ${t.fontFamily||"sans-serif"}`,textVerticalAlign:"top"}});const M=[];if(u.controls?.collapse&&M.push({type:"group",children:[{type:"rect",shape:{width:20,height:20,r:2},style:{fill:"#334155",stroke:"#475569",lineWidth:1},onclick:()=>u.indicatorId&&i(u.indicatorId,"collapse")},{type:"text",style:{text:u.isCollapsed?"+":"\u2212",fill:"#cbd5e1",font:`bold 14px ${t.fontFamily}`,x:10,y:10,textAlign:"center",textVerticalAlign:"middle"},silent:!0}]}),u.controls?.maximize){const y=n===u.indicatorId,m=u.controls?.collapse?25:0;M.push({type:"group",x:m,children:[{type:"rect",shape:{width:20,height:20,r:2},style:{fill:"#334155",stroke:"#475569",lineWidth:1},onclick:()=>u.indicatorId&&i(u.indicatorId,"maximize")},{type:"text",style:{text:y?"\u2750":"\u25A1",fill:"#cbd5e1",font:`14px ${t.fontFamily}`,x:10,y:10,textAlign:"center",textVerticalAlign:"middle"},silent:!0}]})}M.length>0&&o.push({type:"group",right:"10.5%",top:u.top+"%",children:M})}),o}}class Ct{static format(e,t){if(!e||e.length===0)return"";const i=t.title||"Market",s=t.upColor||"#00da3c",n=t.downColor||"#ec0000",o=t.fontFamily||"sans-serif",h=e[0].axisValue;let f=`<div style="font-weight: bold; margin-bottom: 5px; color: #cbd5e1; font-family: ${o};">${h}</div>`;const u=e.find(y=>y.seriesType==="candlestick"),M=e.filter(y=>y.seriesType!=="candlestick");if(u){const[y,m,I,p,g]=u.value,v=I>=m?s:n;f+=`
|
|
18
18
|
<div style="margin-bottom: 8px; font-family: ${o};">
|
|
19
|
-
<div style="display:flex; justify-content:space-between; color:${
|
|
19
|
+
<div style="display:flex; justify-content:space-between; color:${v}; 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: ${
|
|
24
|
-
<span>High:</span> <span style="text-align: right; color: ${s}">${
|
|
25
|
-
<span>Low:</span> <span style="text-align: right; color: ${n}">${
|
|
26
|
-
<span>Close:</span> <span style="text-align: right; color: ${
|
|
23
|
+
<span>Open:</span> <span style="text-align: right; color: ${I>=m?s:n}">${m}</span>
|
|
24
|
+
<span>High:</span> <span style="text-align: right; color: ${s}">${g}</span>
|
|
25
|
+
<span>Low:</span> <span style="text-align: right; color: ${n}">${p}</span>
|
|
26
|
+
<span>Close:</span> <span style="text-align: right; color: ${I>=m?s:n}">${I}</span>
|
|
27
27
|
</div>
|
|
28
28
|
</div>
|
|
29
|
-
`}if(
|
|
29
|
+
`}if(M.length>0){f+='<div style="border-top: 1px solid #334155; margin: 5px 0; padding-top: 5px;"></div>';const y={};M.forEach(m=>{const I=m.seriesName.split("::"),p=I.length>1?I[0]:"Unknown",g=I.length>1?I[1]:m.seriesName;y[p]||(y[p]=[]),y[p].push({...m,displayName:g})}),Object.keys(y).forEach(m=>{f+=`
|
|
30
30
|
<div style="margin-top: 8px; font-family: ${o};">
|
|
31
31
|
<div style="font-weight:bold; color: #fff; margin-bottom: 2px;">${m}</div>
|
|
32
|
-
`,
|
|
32
|
+
`,y[m].forEach(I=>{let p=I.value;if(Array.isArray(p)&&(p=p[1]),p==null)return;const g=typeof p=="number"?p.toLocaleString(void 0,{maximumFractionDigits:4}):p;f+=`
|
|
33
33
|
<div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 2px; padding-left: 8px;">
|
|
34
|
-
<div>${
|
|
35
|
-
<div style="font-size: 10px; color: #fff;padding-left:10px;">${
|
|
36
|
-
</div>`}),p+="</div>"})}return p}}var Ct=Object.defineProperty,St=(a,e,t)=>e in a?Ct(a,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):a[e]=t,J=(a,e,t)=>(St(a,typeof e!="symbol"?e+"":e,t),t);class kt{constructor(e,t){J(this,"plugins",new Map),J(this,"activePluginId",null),J(this,"context"),J(this,"toolbarContainer"),J(this,"tooltipElement",null),J(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,o=i.right+10;this.tooltipElement.style.top=`${n}px`,this.tooltipElement.style.left=`${o}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.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 It=Object.defineProperty,Pt=(a,e,t)=>e in a?It(a,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):a[e]=t,$=(a,e,t)=>(Pt(a,typeof e!="symbol"?e+"":e,t),t);class Mt{constructor(e){$(this,"context"),$(this,"isEditing",!1),$(this,"currentDrawing",null),$(this,"editingPointIndex",null),$(this,"zr"),$(this,"editGroup",null),$(this,"editLine",null),$(this,"editStartPoint",null),$(this,"editEndPoint",null),$(this,"isMovingShape",!1),$(this,"dragStart",null),$(this,"initialPixelPoints",[]),$(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))}),$(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))}),$(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,o=s-this.dragStart.y,r={x:this.initialPixelPoints[0].x+n,y:this.initialPixelPoints[0].y+o},p={x:this.initialPixelPoints[1].x+n,y:this.initialPixelPoints[1].y+o};this.editLine.setShape({x1:r.x,y1:r.y,x2:p.x,y2:p.y}),this.editStartPoint.setShape({cx:r.x,cy:r.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})))}),$(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 E.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 E.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 E.graphic.Circle({shape:{cx:i.x,cy:i.y,r:5},style:{fill:"#fff",stroke:"#3b82f6",lineWidth:2},z:1e3}),this.editEndPoint=new E.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((o,r)=>{const p=o.x+i,u=o.y+s;return this.context.coordinateConversion.pixelToData({x:p,y:u})});n.every(o=>o!==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 Dt=Object.defineProperty,zt=(a,e,t)=>e in a?Dt(a,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):a[e]=t,Et=(a,e,t)=>(zt(a,typeof e!="symbol"?e+"":e,t),t);class Tt{constructor(){Et(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 At=Object.defineProperty,Lt=(a,e,t)=>e in a?At(a,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):a[e]=t,k=(a,e,t)=>(Lt(a,typeof e!="symbol"?e+"":e,t),t);class Zt{constructor(e,t={}){k(this,"chart"),k(this,"options"),k(this,"marketData",[]),k(this,"indicators",new Map),k(this,"timeToIndex",new Map),k(this,"pluginManager"),k(this,"drawingEditor"),k(this,"events",new Tt),k(this,"isMainCollapsed",!1),k(this,"maximizedPaneId",null),k(this,"selectedDrawingId",null),k(this,"drawings",[]),k(this,"coordinateConversion",{pixelToData:n=>{const o=this.chart.getOption();if(!o||!o.grid)return null;const r=o.grid.length;for(let p=0;p<r;p++)if(this.chart.containPixel({gridIndex:p},[n.x,n.y])){this.chart.convertFromPixel({seriesIndex:p},[n.x,n.y]);const u=this.chart.convertFromPixel({gridIndex:p},[n.x,n.y]);if(u)return{timeIndex:Math.round(u[0]),value:u[1],paneIndex:p}}return null},dataToPixel:n=>{const o=n.paneIndex||0,r=this.chart.convertToPixel({gridIndex:o},[n.timeIndex,n.value]);return r?{x:r[0],y:r[1]}:null}}),k(this,"upColor","#00da3c"),k(this,"downColor","#ec0000"),k(this,"defaultPadding",0),k(this,"padding"),k(this,"dataIndexOffset",0),k(this,"rootContainer"),k(this,"layoutContainer"),k(this,"toolbarContainer"),k(this,"leftSidebar"),k(this,"rightSidebar"),k(this,"chartContainer"),k(this,"onKeyDown",n=>{(n.key==="Delete"||n.key==="Backspace")&&this.selectedDrawingId&&(this.removeDrawing(this.selectedDrawingId),this.selectedDrawingId=null,this.render())}),k(this,"onFullscreenChange",()=>{this.render()}),k(this,"isLocked",!1),k(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=E.init(this.chartContainer),this.pluginManager=new kt(this,this.toolbarContainer),this.drawingEditor=new Mt(this),this.chart.on("dataZoom",n=>this.events.emit("chart:dataZoom",n)),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]),o=this.drawings.filter(p=>(p.paneIndex||0)===n)[i.dataIndex];if(!o)return null;const r=i.event?.target?.name;return{drawing:o,targetName:r,paneIdx:n}};this.chart.on("mouseover",i=>{const s=t(i);if(!s)return;const n=i.event?.target?.parent;if(n){const o=s.drawing.id===this.selectedDrawingId;e&&(clearTimeout(e),e=null),o||n.children().forEach(r=>{r.name&&r.name.startsWith("point")&&r.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 o=s.targetName==="point-start"?0:1;this.events.emit("drawing:point:hover",{id:s.drawing.id,pointIndex:o}),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(o=>{o.name&&o.name.startsWith("point")&&o.attr("style",{opacity:0})})}},50),s.targetName==="line")this.events.emit("drawing:mouseout",{id:s.drawing.id});else if(s.targetName?.startsWith("point")){const o=s.targetName==="point-start"?0:1;this.events.emit("drawing:point:mouseout",{id:s.drawing.id,pointIndex:o})}this.chart.getZr().setCursorStyle("default")}}),this.chart.on("mousedown",i=>{const s=t(i);if(!s)return;const n=i.event?.event||i.event,o=n?.offsetX,r=n?.offsetY;if(s.targetName==="line")this.events.emit("drawing:mousedown",{id:s.drawing.id,x:o,y:r});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:o,y:r})}}),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(d=>{t.set(d.time,d)}),e.forEach(d=>{t.has(d.time),t.set(d.time,d)}),this.marketData=Array.from(t.values()).sort((d,x)=>d.time-x.time),this.rebuildTimeIndex();const i=this.dataIndexOffset,s=this.marketData.map(d=>[d.open,d.close,d.low,d.high]),n={value:[NaN,NaN,NaN,NaN],itemStyle:{opacity:0}},o=[...Array(i).fill(n),...s,...Array(i).fill(n)],r=[...Array(i).fill(""),...this.marketData.map(d=>new Date(d.time).toLocaleString()),...Array(i).fill("")],p=this.chart.getOption(),u=ut.calculate(this.chart.getHeight(),this.indicators,this.options,this.isMainCollapsed,this.maximizedPaneId),v=[...Array(i).fill(null),...this.marketData,...Array(i).fill(null)],f=q.buildIndicatorSeries(this.indicators,this.timeToIndex,u.paneLayout,r.length,i,v),m={xAxis:p.xAxis.map((d,x)=>({data:r})),series:[{data:o},...f.map(d=>({data:d.data}))]};this.chart.setOption(m,{notMerge:!1})}addIndicator(e,t,i={isOverlay:!1}){const s=i.isOverlay??!1;let n=0;if(!s){let r=0;this.indicators.forEach(p=>{p.paneIndex>r&&(r=p.paneIndex)}),n=r+1}const o=new mt(e,t,n,{height:i.height,collapsed:!1,titleColor:i.titleColor,controls:i.controls});return this.indicators.set(e,o),this.render(),o}setIndicator(e,t,i=!1){this.addIndicator(e,{[e]:t},{isOverlay: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(){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 y=this.chart.getOption();if(y&&y.dataZoom&&y.dataZoom.length>0){const c=y.dataZoom.find(l=>l.type==="slider"||l.type==="inside");c&&(e={start:c.start,end:c.end})}}catch{}const t=this.options.databox?.position,i=this.leftSidebar.style.display,s=this.rightSidebar.style.display,n=t==="left"?"block":"none",o=t==="right"?"block":"none";(i!==n||s!==o)&&(this.leftSidebar.style.display=n,this.rightSidebar.style.display=o,this.chart.resize());const r=this.dataIndexOffset,p=[...Array(r).fill(""),...this.marketData.map(y=>new Date(y.time).toLocaleString()),...Array(r).fill("")],u=ut.calculate(this.chart.getHeight(),this.indicators,this.options,this.isMainCollapsed,this.maximizedPaneId);e&&u.dataZoom&&u.dataZoom.forEach(y=>{y.start=e.start,y.end=e.end}),u.xAxis.forEach(y=>{y.data=p,y.boundaryGap=!1});const v=q.buildCandlestickSeries(this.marketData,this.options),f={value:[NaN,NaN,NaN,NaN],itemStyle:{opacity:0}};v.data=[...Array(r).fill(f),...v.data,...Array(r).fill(f)];const m=[...Array(r).fill(null),...this.marketData,...Array(r).fill(null)],d=q.buildIndicatorSeries(this.indicators,this.timeToIndex,u.paneLayout,p.length,r,m),x=vt.build(u,this.options,this.toggleIndicator.bind(this),this.isMainCollapsed,this.maximizedPaneId),S=new Map;this.drawings.forEach(y=>{const c=y.paneIndex||0;S.has(c)||S.set(c,[]),S.get(c).push(y)});const I=[];S.forEach((y,c)=>{I.push({type:"custom",name:`drawings-pane-${c}`,xAxisIndex:c,yAxisIndex:c,clip:!0,renderItem:(l,b)=>{const h=y[l.dataIndex];if(!h)return;const C=h.points[0],T=h.points[1];if(!C||!T)return;const g=b.coord([C.timeIndex,C.value]),w=b.coord([T.timeIndex,T.value]),z=h.id===this.selectedDrawingId;if(h.type==="line")return{type:"group",children:[{type:"line",name:"line",shape:{x1:g[0],y1:g[1],x2:w[0],y2:w[1]},style:{stroke:h.style?.color||"#3b82f6",lineWidth:h.style?.lineWidth||2}},{type:"circle",name:"point-start",shape:{cx:g[0],cy:g[1],r:4},style:{fill:"#fff",stroke:h.style?.color||"#3b82f6",lineWidth:1,opacity:z?1:0}},{type:"circle",name:"point-end",shape:{cx:w[0],cy:w[1],r:4},style:{fill:"#fff",stroke:h.style?.color||"#3b82f6",lineWidth:1,opacity:z?1:0}}]};if(h.type==="fibonacci"){const O=g[0],W=g[1],P=w[0],M=w[1],Z=Math.min(O,P),N=Math.max(O,P),A=N-Z,j=M-W,H=[0,.236,.382,.5,.618,.786,1],R=["#787b86","#f44336","#ff9800","#4caf50","#2196f3","#00bcd4","#787b86"],K=[];K.push({type:"line",name:"line",shape:{x1:O,y1:W,x2:P,y2:M},style:{stroke:"#999",lineWidth:1,lineDash:[4,4]}}),K.push({type:"circle",name:"point-start",shape:{cx:O,cy:W,r:4},style:{fill:"#fff",stroke:h.style?.color||"#3b82f6",lineWidth:1,opacity:z?1:0},z:100}),K.push({type:"circle",name:"point-end",shape:{cx:P,cy:M,r:4},style:{fill:"#fff",stroke:h.style?.color||"#3b82f6",lineWidth:1,opacity:z?1:0},z:100}),H.forEach((Q,Y)=>{const X=M-j*Q,et=R[Y%R.length];K.push({type:"line",name:"fib-line",shape:{x1:Z,y1:X,x2:N,y2:X},style:{stroke:et,lineWidth:1},silent:!0});const rt=h.points[0].value,it=h.points[1].value,lt=it-rt,ht=it-lt*Q;if(K.push({type:"text",style:{text:`${Q} (${ht.toFixed(2)})`,x:Z+5,y:X-10,fill:et,fontSize:10},silent:!0}),Y<H.length-1){const dt=H[Y+1],st=M-j*dt,ct=Math.abs(st-X),pt=Math.min(X,st);K.push({type:"rect",shape:{x:Z,y:pt,width:A,height:ct},style:{fill:R[(Y+1)%R.length],opacity:.1},silent:!0})}});const gt=[],at=[];return H.forEach((Q,Y)=>{const X=M-j*Q,et=R[Y%R.length];at.push({type:"line",shape:{x1:Z,y1:X,x2:N,y2:X},style:{stroke:et,lineWidth:1},silent:!0});const rt=h.points[0].value,it=h.points[1].value,lt=it-rt,ht=it-lt*Q;if(at.push({type:"text",style:{text:`${Q} (${ht.toFixed(2)})`,x:Z+5,y:X-10,fill:et,fontSize:10},silent:!0}),Y<H.length-1){const dt=H[Y+1],st=M-j*dt,ct=Math.abs(st-X),pt=Math.min(X,st);gt.push({type:"rect",name:"line",shape:{x:Z,y:pt,width:A,height:ct},style:{fill:R[(Y+1)%R.length],opacity:.1}})}}),{type:"group",children:[...gt,...at,{type:"line",name:"line",shape:{x1:O,y1:W,x2:P,y2:M},style:{stroke:"#999",lineWidth:1,lineDash:[4,4]}},{type:"circle",name:"point-start",shape:{cx:O,cy:W,r:4},style:{fill:"#fff",stroke:h.style?.color||"#3b82f6",lineWidth:1,opacity:z?1:0},z:100},{type:"circle",name:"point-end",shape:{cx:P,cy:M,r:4},style:{fill:"#fff",stroke:h.style?.color||"#3b82f6",lineWidth:1,opacity:z?1:0},z:100}]}}},data:y.map(l=>[l.points[0].timeIndex,l.points[0].value,l.points[1].timeIndex,l.points[1].value]),z:100,silent:!1})});const L=y=>{const c=wt.format(y,this.options),l=this.options.databox?.position;return l==="left"?(this.leftSidebar.innerHTML=c,""):l==="right"?(this.rightSidebar.innerHTML=c,""):this.options.databox?`<div style="min-width: 200px;">${c}</div>`:""},D={backgroundColor:this.options.backgroundColor,animation:!1,legend:{show:!1},tooltip:{show:!0,showContent:!!this.options.databox,trigger:"axis",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:L,extraCssText:t!=="floating"&&t!==void 0?"display: none !important;":void 0,position:(y,c,l,b,h)=>{if(this.options.databox?.position==="floating"){const C={top:10};return C[["left","right"][+(y[0]<h.viewSize[0]/2)]]=30,C}return null}},axisPointer:{link:{xAxisIndex:"all"},label:{backgroundColor:"#475569"}},graphic:x,grid:u.grid,xAxis:u.xAxis,yAxis:u.yAxis,dataZoom:u.dataZoom,series:[v,...d,...I]};this.chart.setOption(D,!0)}}var Gt=Object.defineProperty,$t=(a,e,t)=>e in a?Gt(a,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):a[e]=t,tt=(a,e,t)=>($t(a,typeof e!="symbol"?e+"":e,t),t);class nt{constructor(e){tt(this,"id"),tt(this,"name"),tt(this,"icon"),tt(this,"context"),tt(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 Nt=Object.defineProperty,Ft=(a,e,t)=>e in a?Nt(a,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):a[e]=t,G=(a,e,t)=>(Ft(a,typeof e!="symbol"?e+"":e,t),t);class Ot extends nt{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>'}),G(this,"zr"),G(this,"state","idle"),G(this,"startPoint",null),G(this,"endPoint",null),G(this,"group",null),G(this,"rect",null),G(this,"labelRect",null),G(this,"labelText",null),G(this,"lineV",null),G(this,"lineH",null),G(this,"arrowStart",null),G(this,"arrowEnd",null),G(this,"onMouseDown",()=>{this.state==="finished"&&this.removeGraphic()}),G(this,"onChartInteraction",()=>{this.group&&this.removeGraphic()}),G(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())}),G(this,"clearHandlers",{}),G(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 E.graphic.Group,this.rect=new E.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 E.graphic.Line({shape:{x1:0,y1:0,x2:0,y2:0},style:{stroke:"#fff",lineWidth:1,lineDash:[4,4]},z:101}),this.lineH=new E.graphic.Line({shape:{x1:0,y1:0,x2:0,y2:0},style:{stroke:"#fff",lineWidth:1,lineDash:[4,4]},z:101}),this.arrowStart=new E.graphic.Polygon({shape:{points:[[0,0],[-5,10],[5,10]]},style:{fill:"#fff"},z:102}),this.arrowEnd=new E.graphic.Polygon({shape:{points:[[0,0],[-5,-10],[5,-10]]},style:{fill:"#fff"},z:102}),this.labelRect=new E.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 E.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}),o=this.context.coordinateConversion.pixelToData({x:i,y:s});if(!n||!o)return;const r=Math.round(n.timeIndex),p=Math.round(o.timeIndex),u=n.value,v=o.value,f=p-r,m=v-u,d=m/u*100,x=m>=0,S=x?"rgba(33, 150, 243, 0.2)":"rgba(236, 0, 0, 0.2)",I=x?"#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:S});const L=(e+i)/2,D=(t+s)/2;this.lineV.setShape({x1:L,y1:t,x2:L,y2:s}),this.lineV.setStyle({stroke:I}),this.lineH.setShape({x1:e,y1:D,x2:i,y2:D}),this.lineH.setStyle({stroke:I});const y=Math.min(t,s),c=Math.max(t,s);this.arrowStart.setStyle({fill:"none"}),this.arrowEnd.setStyle({fill:"none"}),x?(this.arrowStart.setShape({points:[[L,y],[L-4,y+6],[L+4,y+6]]}),this.arrowStart.setStyle({fill:I})):(this.arrowEnd.setShape({points:[[L,c],[L-4,c-6],[L+4,c-6]]}),this.arrowEnd.setStyle({fill:I}));const l=[`${m.toFixed(2)} (${d.toFixed(2)}%)`,`${f} bars, ${(f*0).toFixed(0)}d`].join(`
|
|
37
|
-
`),
|
|
34
|
+
<div>${I.marker} <span style="color: #cbd5e1;">${I.displayName}</span></div>
|
|
35
|
+
<div style="font-size: 10px; color: #fff;padding-left:10px;">${g}</div>
|
|
36
|
+
</div>`}),f+="</div>"})}return f}}var It=Object.defineProperty,St=(a,e,t)=>e in a?It(a,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):a[e]=t,_=(a,e,t)=>(St(a,typeof e!="symbol"?e+"":e,t),t);class kt{constructor(e,t){_(this,"plugins",new Map),_(this,"activePluginId",null),_(this,"context"),_(this,"toolbarContainer"),_(this,"tooltipElement",null),_(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,o=i.right+10;this.tooltipElement.style.top=`${n}px`,this.tooltipElement.style.left=`${o}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.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 Pt=Object.defineProperty,Mt=(a,e,t)=>e in a?Pt(a,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):a[e]=t,W=(a,e,t)=>(Mt(a,typeof e!="symbol"?e+"":e,t),t);class Dt{constructor(e){W(this,"context"),W(this,"isEditing",!1),W(this,"currentDrawing",null),W(this,"editingPointIndex",null),W(this,"zr"),W(this,"editGroup",null),W(this,"editLine",null),W(this,"editStartPoint",null),W(this,"editEndPoint",null),W(this,"isMovingShape",!1),W(this,"dragStart",null),W(this,"initialPixelPoints",[]),W(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))}),W(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))}),W(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,o=s-this.dragStart.y,h={x:this.initialPixelPoints[0].x+n,y:this.initialPixelPoints[0].y+o},f={x:this.initialPixelPoints[1].x+n,y:this.initialPixelPoints[1].y+o};this.editLine.setShape({x1:h.x,y1:h.y,x2:f.x,y2:f.y}),this.editStartPoint.setShape({cx:h.x,cy:h.y}),this.editEndPoint.setShape({cx:f.x,cy:f.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})))}),W(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 G.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 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(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((o,h)=>{const f=o.x+i,u=o.y+s;return this.context.coordinateConversion.pixelToData({x:f,y:u})});n.every(o=>o!==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 Et=Object.defineProperty,zt=(a,e,t)=>e in a?Et(a,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):a[e]=t,At=(a,e,t)=>(zt(a,typeof e!="symbol"?e+"":e,t),t);class Tt{constructor(){At(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 Lt=Object.defineProperty,Nt=(a,e,t)=>e in a?Lt(a,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):a[e]=t,D=(a,e,t)=>(Nt(a,typeof e!="symbol"?e+"":e,t),t);class Zt{constructor(e,t={}){D(this,"chart"),D(this,"options"),D(this,"marketData",[]),D(this,"indicators",new Map),D(this,"timeToIndex",new Map),D(this,"pluginManager"),D(this,"drawingEditor"),D(this,"events",new Tt),D(this,"isMainCollapsed",!1),D(this,"maximizedPaneId",null),D(this,"selectedDrawingId",null),D(this,"drawings",[]),D(this,"coordinateConversion",{pixelToData:n=>{const o=this.chart.getOption();if(!o||!o.grid)return null;const h=o.grid.length;for(let f=0;f<h;f++)if(this.chart.containPixel({gridIndex:f},[n.x,n.y])){this.chart.convertFromPixel({seriesIndex:f},[n.x,n.y]);const u=this.chart.convertFromPixel({gridIndex:f},[n.x,n.y]);if(u)return{timeIndex:Math.round(u[0]),value:u[1],paneIndex:f}}return null},dataToPixel:n=>{const o=n.paneIndex||0,h=this.chart.convertToPixel({gridIndex:o},[n.timeIndex,n.value]);return h?{x:h[0],y:h[1]}:null}}),D(this,"upColor","#00da3c"),D(this,"downColor","#ec0000"),D(this,"defaultPadding",0),D(this,"padding"),D(this,"dataIndexOffset",0),D(this,"rootContainer"),D(this,"layoutContainer"),D(this,"toolbarContainer"),D(this,"leftSidebar"),D(this,"rightSidebar"),D(this,"chartContainer"),D(this,"onKeyDown",n=>{(n.key==="Delete"||n.key==="Backspace")&&this.selectedDrawingId&&(this.removeDrawing(this.selectedDrawingId),this.selectedDrawingId=null,this.render())}),D(this,"onFullscreenChange",()=>{this.render()}),D(this,"isLocked",!1),D(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=G.init(this.chartContainer),this.pluginManager=new kt(this,this.toolbarContainer),this.drawingEditor=new Dt(this),this.chart.on("dataZoom",n=>this.events.emit("chart:dataZoom",n)),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]),o=this.drawings.filter(f=>(f.paneIndex||0)===n)[i.dataIndex];if(!o)return null;const h=i.event?.target?.name;return{drawing:o,targetName:h,paneIdx:n}};this.chart.on("mouseover",i=>{const s=t(i);if(!s)return;const n=i.event?.target?.parent;if(n){const o=s.drawing.id===this.selectedDrawingId;e&&(clearTimeout(e),e=null),o||n.children().forEach(h=>{h.name&&h.name.startsWith("point")&&h.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 o=s.targetName==="point-start"?0:1;this.events.emit("drawing:point:hover",{id:s.drawing.id,pointIndex:o}),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(o=>{o.name&&o.name.startsWith("point")&&o.attr("style",{opacity:0})})}},50),s.targetName==="line")this.events.emit("drawing:mouseout",{id:s.drawing.id});else if(s.targetName?.startsWith("point")){const o=s.targetName==="point-start"?0:1;this.events.emit("drawing:point:mouseout",{id:s.drawing.id,pointIndex:o})}this.chart.getZr().setCursorStyle("default")}}),this.chart.on("mousedown",i=>{const s=t(i);if(!s)return;const n=i.event?.event||i.event,o=n?.offsetX,h=n?.offsetY;if(s.targetName==="line")this.events.emit("drawing:mousedown",{id:s.drawing.id,x:o,y:h});else if(s.targetName?.startsWith("point")){const f=s.targetName==="point-start"?0:1;this.events.emit("drawing:point:mousedown",{id:s.drawing.id,pointIndex:f,x:o,y:h})}}),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(g=>{t.set(g.time,g)}),e.forEach(g=>{t.has(g.time),t.set(g.time,g)}),this.marketData=Array.from(t.values()).sort((g,v)=>g.time-v.time),this.rebuildTimeIndex();const i=this.dataIndexOffset,s=this.marketData.map(g=>[g.open,g.close,g.low,g.high]),n={value:[NaN,NaN,NaN,NaN],itemStyle:{opacity:0}},o=[...Array(i).fill(n),...s,...Array(i).fill(n)],h=[...Array(i).fill(""),...this.marketData.map(g=>new Date(g.time).toLocaleString()),...Array(i).fill("")],f=this.chart.getOption(),u=gt.calculate(this.chart.getHeight(),this.indicators,this.options,this.isMainCollapsed,this.maximizedPaneId),M=[...Array(i).fill(null),...this.marketData,...Array(i).fill(null)],{series:y,barColors:m}=U.buildIndicatorSeries(this.indicators,this.timeToIndex,u.paneLayout,h.length,i,M),I=o.map((g,v)=>m[v]?{value:g.value||g,itemStyle:{color:m[v],color0:m[v],borderColor:m[v],borderColor0:m[v]}}:g),p={xAxis:f.xAxis.map((g,v)=>({data:h})),series:[{data:I},...y.map(g=>({data:g.data}))]};this.chart.setOption(p,{notMerge:!1})}addIndicator(e,t,i={isOverlay:!1}){const s=i.isOverlay??!1;let n=0;if(!s){let h=0;this.indicators.forEach(f=>{f.paneIndex>h&&(h=f.paneIndex)}),n=h+1}const o=new bt(e,t,n,{height:i.height,collapsed:!1,titleColor:i.titleColor,controls:i.controls});return this.indicators.set(e,o),this.render(),o}setIndicator(e,t,i=!1){this.addIndicator(e,{[e]:t},{isOverlay: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(){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 w=this.chart.getOption();if(w&&w.dataZoom&&w.dataZoom.length>0){const S=w.dataZoom.find(l=>l.type==="slider"||l.type==="inside");S&&(e={start:S.start,end:S.end})}}catch{}const t=this.options.databox?.position,i=this.leftSidebar.style.display,s=this.rightSidebar.style.display,n=t==="left"?"block":"none",o=t==="right"?"block":"none";(i!==n||s!==o)&&(this.leftSidebar.style.display=n,this.rightSidebar.style.display=o,this.chart.resize());const h=this.dataIndexOffset,f=[...Array(h).fill(""),...this.marketData.map(w=>new Date(w.time).toLocaleString()),...Array(h).fill("")],u=gt.calculate(this.chart.getHeight(),this.indicators,this.options,this.isMainCollapsed,this.maximizedPaneId);e&&u.dataZoom&&u.dataZoom.forEach(w=>{w.start=e.start,w.end=e.end}),u.xAxis.forEach(w=>{w.data=f,w.boundaryGap=!1});const M=U.buildCandlestickSeries(this.marketData,this.options),y={value:[NaN,NaN,NaN,NaN],itemStyle:{opacity:0}};M.data=[...Array(h).fill(y),...M.data,...Array(h).fill(y)];const m=[...Array(h).fill(null),...this.marketData,...Array(h).fill(null)],{series:I,barColors:p}=U.buildIndicatorSeries(this.indicators,this.timeToIndex,u.paneLayout,f.length,h,m);M.data=M.data.map((w,S)=>p[S]?{value:w.value||w,itemStyle:{color:p[S],color0:p[S],borderColor:p[S],borderColor0:p[S]}}:w);const g=wt.build(u,this.options,this.toggleIndicator.bind(this),this.isMainCollapsed,this.maximizedPaneId),v=new Map;this.drawings.forEach(w=>{const S=w.paneIndex||0;v.has(S)||v.set(S,[]),v.get(S).push(w)});const z=[];v.forEach((w,S)=>{z.push({type:"custom",name:`drawings-pane-${S}`,xAxisIndex:S,yAxisIndex:S,clip:!0,renderItem:(l,r)=>{const d=w[l.dataIndex];if(!d)return;const x=d.points[0],c=d.points[1];if(!x||!c)return;const b=r.coord([x.timeIndex,x.value]),C=r.coord([c.timeIndex,c.value]),L=d.id===this.selectedDrawingId;if(d.type==="line")return{type:"group",children:[{type:"line",name:"line",shape:{x1:b[0],y1:b[1],x2:C[0],y2:C[1]},style:{stroke:d.style?.color||"#3b82f6",lineWidth:d.style?.lineWidth||2}},{type:"circle",name:"point-start",shape:{cx:b[0],cy:b[1],r:4},style:{fill:"#fff",stroke:d.style?.color||"#3b82f6",lineWidth:1,opacity:L?1:0}},{type:"circle",name:"point-end",shape:{cx:C[0],cy:C[1],r:4},style:{fill:"#fff",stroke:d.style?.color||"#3b82f6",lineWidth:1,opacity:L?1:0}}]};if(d.type==="fibonacci"){const N=b[0],P=b[1],k=C[0],Z=C[1],E=Math.min(N,k),A=Math.max(N,k),X=A-E,O=Z-P,H=[0,.236,.382,.5,.618,.786,1],j=["#787b86","#f44336","#ff9800","#4caf50","#2196f3","#00bcd4","#787b86"],Y=[];Y.push({type:"line",name:"line",shape:{x1:N,y1:P,x2:k,y2:Z},style:{stroke:"#999",lineWidth:1,lineDash:[4,4]}}),Y.push({type:"circle",name:"point-start",shape:{cx:N,cy:P,r:4},style:{fill:"#fff",stroke:d.style?.color||"#3b82f6",lineWidth:1,opacity:L?1:0},z:100}),Y.push({type:"circle",name:"point-end",shape:{cx:k,cy:Z,r:4},style:{fill:"#fff",stroke:d.style?.color||"#3b82f6",lineWidth:1,opacity:L?1:0},z:100}),H.forEach((Q,V)=>{const q=Z-O*Q,it=j[V%j.length];Y.push({type:"line",name:"fib-line",shape:{x1:E,y1:q,x2:A,y2:q},style:{stroke:it,lineWidth:1},silent:!0});const lt=d.points[0].value,st=d.points[1].value,ht=st-lt,dt=st-ht*Q;if(Y.push({type:"text",style:{text:`${Q} (${dt.toFixed(2)})`,x:E+5,y:q-10,fill:it,fontSize:10},silent:!0}),V<H.length-1){const ct=H[V+1],nt=Z-O*ct,pt=Math.abs(nt-q),ut=Math.min(q,nt);Y.push({type:"rect",shape:{x:E,y:ut,width:X,height:pt},style:{fill:j[(V+1)%j.length],opacity:.1},silent:!0})}});const ft=[],rt=[];return H.forEach((Q,V)=>{const q=Z-O*Q,it=j[V%j.length];rt.push({type:"line",shape:{x1:E,y1:q,x2:A,y2:q},style:{stroke:it,lineWidth:1},silent:!0});const lt=d.points[0].value,st=d.points[1].value,ht=st-lt,dt=st-ht*Q;if(rt.push({type:"text",style:{text:`${Q} (${dt.toFixed(2)})`,x:E+5,y:q-10,fill:it,fontSize:10},silent:!0}),V<H.length-1){const ct=H[V+1],nt=Z-O*ct,pt=Math.abs(nt-q),ut=Math.min(q,nt);ft.push({type:"rect",name:"line",shape:{x:E,y:ut,width:X,height:pt},style:{fill:j[(V+1)%j.length],opacity:.1}})}}),{type:"group",children:[...ft,...rt,{type:"line",name:"line",shape:{x1:N,y1:P,x2:k,y2:Z},style:{stroke:"#999",lineWidth:1,lineDash:[4,4]}},{type:"circle",name:"point-start",shape:{cx:N,cy:P,r:4},style:{fill:"#fff",stroke:d.style?.color||"#3b82f6",lineWidth:1,opacity:L?1:0},z:100},{type:"circle",name:"point-end",shape:{cx:k,cy:Z,r:4},style:{fill:"#fff",stroke:d.style?.color||"#3b82f6",lineWidth:1,opacity:L?1:0},z:100}]}}},data:w.map(l=>[l.points[0].timeIndex,l.points[0].value,l.points[1].timeIndex,l.points[1].value]),z:100,silent:!1})});const $=w=>{const S=Ct.format(w,this.options),l=this.options.databox?.position;return l==="left"?(this.leftSidebar.innerHTML=S,""):l==="right"?(this.rightSidebar.innerHTML=S,""):this.options.databox?`<div style="min-width: 200px;">${S}</div>`:""},T={backgroundColor:this.options.backgroundColor,animation:!1,legend:{show:!1},tooltip:{show:!0,showContent:!!this.options.databox,trigger:"axis",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:$,extraCssText:t!=="floating"&&t!==void 0?"display: none !important;":void 0,position:(w,S,l,r,d)=>{if(this.options.databox?.position==="floating"){const x={top:10};return x[["left","right"][+(w[0]<d.viewSize[0]/2)]]=30,x}return null}},axisPointer:{link:{xAxisIndex:"all"},label:{backgroundColor:"#475569"}},graphic:g,grid:u.grid,xAxis:u.xAxis,yAxis:u.yAxis,dataZoom:u.dataZoom,series:[M,...I,...z]};this.chart.setOption(T,!0)}}var Gt=Object.defineProperty,$t=(a,e,t)=>e in a?Gt(a,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):a[e]=t,et=(a,e,t)=>($t(a,typeof e!="symbol"?e+"":e,t),t);class ot{constructor(e){et(this,"id"),et(this,"name"),et(this,"icon"),et(this,"context"),et(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 Ft=Object.defineProperty,Wt=(a,e,t)=>e in a?Ft(a,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):a[e]=t,F=(a,e,t)=>(Wt(a,typeof e!="symbol"?e+"":e,t),t);class Ot extends ot{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>'}),F(this,"zr"),F(this,"state","idle"),F(this,"startPoint",null),F(this,"endPoint",null),F(this,"group",null),F(this,"rect",null),F(this,"labelRect",null),F(this,"labelText",null),F(this,"lineV",null),F(this,"lineH",null),F(this,"arrowStart",null),F(this,"arrowEnd",null),F(this,"onMouseDown",()=>{this.state==="finished"&&this.removeGraphic()}),F(this,"onChartInteraction",()=>{this.group&&this.removeGraphic()}),F(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())}),F(this,"clearHandlers",{}),F(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 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[e,t]=this.startPoint,[i,s]=this.endPoint,n=this.context.coordinateConversion.pixelToData({x:e,y:t}),o=this.context.coordinateConversion.pixelToData({x:i,y:s});if(!n||!o)return;const h=Math.round(n.timeIndex),f=Math.round(o.timeIndex),u=n.value,M=o.value,y=f-h,m=M-u,I=m/u*100,p=m>=0,g=p?"rgba(33, 150, 243, 0.2)":"rgba(236, 0, 0, 0.2)",v=p?"#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:g});const z=(e+i)/2,$=(t+s)/2;this.lineV.setShape({x1:z,y1:t,x2:z,y2:s}),this.lineV.setStyle({stroke:v}),this.lineH.setShape({x1:e,y1:$,x2:i,y2:$}),this.lineH.setStyle({stroke:v});const T=Math.min(t,s),w=Math.max(t,s);this.arrowStart.setStyle({fill:"none"}),this.arrowEnd.setStyle({fill:"none"}),p?(this.arrowStart.setShape({points:[[z,T],[z-4,T+6],[z+4,T+6]]}),this.arrowStart.setStyle({fill:v})):(this.arrowEnd.setShape({points:[[z,w],[z-4,w-6],[z+4,w-6]]}),this.arrowEnd.setStyle({fill:v}));const S=[`${m.toFixed(2)} (${I.toFixed(2)}%)`,`${y} bars, ${(y*0).toFixed(0)}d`].join(`
|
|
37
|
+
`),l=140,r=40,d=Math.max(t,s),x=Math.min(t,s);let c=(e+i)/2-l/2,b=d+10;const C=this.chart.getHeight();b+r>C&&(b=x-r-10),this.labelRect.setShape({x:c,y:b,width:l,height:r}),this.labelRect.setStyle({fill:"#1e293b",stroke:v,lineWidth:1}),this.labelText.setStyle({x:c+l/2,y:b+r/2,text:S,fill:"#fff"})}}var Ht=Object.defineProperty,jt=(a,e,t)=>e in a?Ht(a,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):a[e]=t,R=(a,e,t)=>(jt(a,typeof e!="symbol"?e+"":e,t),t);class Rt extends ot{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>'}),R(this,"zr"),R(this,"state","idle"),R(this,"startPoint",null),R(this,"endPoint",null),R(this,"group",null),R(this,"line",null),R(this,"startCircle",null),R(this,"endCircle",null),R(this,"onMouseDown",()=>{}),R(this,"onChartInteraction",()=>{}),R(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()}}),R(this,"clearHandlers",{}),R(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 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[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 Xt=Object.defineProperty,Yt=(a,e,t)=>e in a?Xt(a,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):a[e]=t,J=(a,e,t)=>(Yt(a,typeof e!="symbol"?e+"":e,t),t);class qt extends ot{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>'}),J(this,"startPoint",null),J(this,"endPoint",null),J(this,"state","idle"),J(this,"graphicGroup",null),J(this,"levels",[0,.236,.382,.5,.618,.786,1]),J(this,"colors",["#787b86","#f44336","#ff9800","#4caf50","#2196f3","#00bcd4","#787b86"]),J(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())}),J(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 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 e=this.startPoint[0],t=this.startPoint[1],i=this.endPoint[0],s=this.endPoint[1],n=new G.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 o=Math.min(e,i),h=Math.max(e,i),f=h-o,u=s-t;this.levels.forEach((M,y)=>{const m=s-u*M,I=this.colors[y%this.colors.length],p=new G.graphic.Line({shape:{x1:o,y1:m,x2:h,y2:m},style:{stroke:I,lineWidth:1},silent:!0});if(this.graphicGroup.add(p),y<this.levels.length-1){const g=this.levels[y+1],v=s-u*g,z=Math.abs(v-m),$=Math.min(m,v),T=new G.graphic.Rect({shape:{x:o,y:$,width:f,height:z},style:{fill:this.colors[(y+1)%this.colors.length],opacity:.1},silent:!0});this.graphicGroup.add(T)}})}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}})}}}B.AbstractPlugin=ot,B.FibonacciTool=qt,B.LineTool=Rt,B.MeasureTool=Ot,B.QFChart=Zt});
|
package/dist/qfchart.min.es.js
CHANGED
|
@@ -14,24 +14,24 @@
|
|
|
14
14
|
* See the License for the specific language governing permissions and
|
|
15
15
|
* limitations under the License.
|
|
16
16
|
*/
|
|
17
|
-
import*as T from"echarts";var ut=Object.defineProperty,gt=(a,e,t)=>e in a?ut(a,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):a[e]=t,U=(a,e,t)=>(gt(a,typeof e!="symbol"?e+"":e,t),t);class ft{constructor(e,t,i,s={}){U(this,"id"),U(this,"plots"),U(this,"paneIndex"),U(this,"height"),U(this,"collapsed"),U(this,"titleColor"),U(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];s.options&&(i.options={...i.options,...s.options});const n=new Map;i.data.forEach(o=>{n.set(o.time,o)}),s.data.forEach(o=>{n.set(o.time,o)}),i.data=Array.from(n.values()).sort((o,r)=>o.time-r.time)}})}}class pt{static calculate(e,t,i,s=!1,n=null){let o=0;e>0&&(o=1/e*100);const r=Array.from(t.values()).map(g=>g.paneIndex).filter(g=>g>0).sort((g,w)=>g-w).filter((g,w,z)=>z.indexOf(g)===w),p=r.length>0,u=i.dataZoom?.visible??!0,v=i.dataZoom?.position??"top",f=i.dataZoom?.height??6,m=i.dataZoom?.start??0,d=i.dataZoom?.end??100;let x=8,S=92,k=-1;if(n)if(n==="main")k=0;else{const g=t.get(n);g&&(k=g.paneIndex)}if(k!==-1){const g=[],w=[],z=[],F=[],H=i.dataZoom?.start??50,I=i.dataZoom?.end??100;F.push({type:"inside",xAxisIndex:"all",start:H,end:I});const M=p?Math.max(...r):0,Z=[];for(let N=0;N<=M;N++){const A=N===k;if(g.push({left:"10%",right:"10%",top:A?"5%":"0%",height:A?"90%":"0%",show:A,containLabel:!1}),w.push({type:"category",gridIndex:N,data:[],show:A,axisLabel:{show:A,color:"#94a3b8",fontFamily:i.fontFamily},axisLine:{show:A,lineStyle:{color:"#334155"}},splitLine:{show:A,lineStyle:{color:"#334155",opacity:.5}}}),z.push({position:"right",gridIndex:N,show:A,scale:!0,axisLabel:{show:A,color:"#94a3b8",fontFamily:i.fontFamily},splitLine:{show:A,lineStyle:{color:"#334155",opacity:.5}}}),N>0){const R=Array.from(t.values()).find(O=>O.paneIndex===N);R&&Z.push({index:N,height:A?90:0,top:A?5:0,isCollapsed:!1,indicatorId:R.id,titleColor:R.titleColor,controls:R.controls})}}return{grid:g,xAxis:w,yAxis:z,dataZoom:F,paneLayout:Z,mainPaneHeight:k===0?90:0,mainPaneTop:k===0?5:0,pixelToPercent:o}}u?v==="top"?(x=f+4,S=95):(S=100-f-2,x=8):(x=5,S=95);let L=5;e>0&&(L=20/e*100);let D=75,y=[];if(p){const g=r.map(I=>{const M=Array.from(t.values()).find(Z=>Z.paneIndex===I);return{index:I,requestedHeight:M?.height,isCollapsed:M?.collapsed??!1,indicatorId:M?.id,titleColor:M?.titleColor,controls:M?.controls}}).map(I=>({...I,height:I.isCollapsed?3:I.requestedHeight!==void 0?I.requestedHeight:15})),w=g.reduce((I,M)=>I+M.height,0),z=g.length*L,F=w+z;D=S-x-F,s?D=3:D<20&&(D=Math.max(D,10));let H=x+D+L;y=g.map(I=>{const M={index:I.index,height:I.height,top:H,isCollapsed:I.isCollapsed,indicatorId:I.indicatorId,titleColor:I.titleColor,controls:I.controls};return H+=I.height+L,M})}else D=S-x,s&&(D=3);const c=[];c.push({left:"10%",right:"10%",top:x+"%",height:D+"%",containLabel:!1}),y.forEach(g=>{c.push({left:"10%",right:"10%",top:g.top+"%",height:g.height+"%",containLabel:!1})});const l=[0,...y.map((g,w)=>w+1)],b=[],h=y.length===0;b.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"},axisTick:{show:!s},axisPointer:{label:{show:h,fontSize:11,backgroundColor:"#475569"}}}),y.forEach((g,w)=>{const z=w===y.length-1;b.push({type:"category",gridIndex:w+1,data:[],axisLabel:{show:!1},axisLine:{show:!g.isCollapsed,lineStyle:{color:"#334155"}},axisTick:{show:!1},splitLine:{show:!1},axisPointer:{label:{show:z,fontSize:11,backgroundColor:"#475569"}}})});const C=[];C.push({position:"right",scale:!0,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"}}),y.forEach((g,w)=>{C.push({position:"right",scale:!0,gridIndex:w+1,splitLine:{show:!g.isCollapsed,lineStyle:{color:"#334155",opacity:.3}},axisLabel:{show:!g.isCollapsed,color:"#94a3b8",fontFamily:i.fontFamily||"sans-serif",fontSize:10},axisLine:{show:!g.isCollapsed,lineStyle:{color:"#334155"}}})});const E=[];return u&&(E.push({type:"inside",xAxisIndex:l,start:m,end:d}),v==="top"?E.push({type:"slider",xAxisIndex:l,top:"1%",height:f+"%",start:m,end:d,borderColor:"#334155",textStyle:{color:"#cbd5e1"},brushSelect:!1}):E.push({type:"slider",xAxisIndex:l,bottom:"1%",height:f+"%",start:m,end:d,borderColor:"#334155",textStyle:{color:"#cbd5e1"},brushSelect:!1})),{grid:c,xAxis:b,yAxis:C,dataZoom:E,paneLayout:y,mainPaneHeight:D,mainPaneTop:x,pixelToPercent:o}}static calculateMaximized(e,t,i){return{grid:[],xAxis:[],yAxis:[],dataZoom:[],paneLayout:[],mainPaneHeight:0,mainPaneTop:0,pixelToPercent:0}}}const dt=new Map;function yt(a,e="#00da3c",t="64px"){if(typeof document>"u")return"";const i=`${a}-${e}-${t}`;if(dt.has(i))return dt.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(a,16,16);const o=s.toDataURL("image/png");return dt.set(i,o),o}return""}class V{static buildCandlestickSeries(e,t,i){const s=t.upColor||"#00da3c",n=t.downColor||"#ec0000",o=e.map(r=>[r.open,r.close,r.low,r.high]);if(i&&i>o.length){const r=i-o.length;for(let p=0;p<r;p++)o.push(null)}return{type:"candlestick",name:t.title||"Market",data:o,itemStyle:{color:s,color0:n,borderColor:s,borderColor0:n},xAxisIndex:0,yAxisIndex:0,z:5}}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://M4 2h16a2 2 0 0 1 2 2v12a2 2 0 0 1 -2 2h-6l-2 4l-2 -4h-6a2 2 0 0 1 -2 -2v-12a2 2 0 0 1 2 -2z";case"labelup":return"path://M12 2l2 4h6a2 2 0 0 1 2 2v12a2 2 0 0 1 -2 2h-16a2 2 0 0 1 -2 -2v-12a2 2 0 0 1 2 -2h6z";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}}}static buildIndicatorSeries(e,t,i,s,n=0,o){const r=[];return e.forEach((p,u)=>{if(p.collapsed)return;let v=0,f=0;if(p.paneIndex>0){const m=i.findIndex(d=>d.index===p.paneIndex);m!==-1&&(v=m+1,f=m+1)}Object.keys(p.plots).forEach(m=>{const d=p.plots[m],x=`${u}::${m}`,S=new Array(s).fill(null),k=new Array(s).fill(null),L=new Array(s).fill(null);switch(d.data.forEach(D=>{const y=t.get(D.time);if(y!==void 0){const c=D.options?.offset??d.options.offset??0,l=y+n+c;if(l>=0&&l<s){let b=D.value;const h=D.options?.color;(h===null||h==="na"||h==="NaN"||typeof h=="number"&&isNaN(h))&&(b=null),S[l]=b,k[l]=h||d.options.color,L[l]=D.options||{}}}}),d.options.style){case"histogram":case"columns":r.push({name:x,type:"bar",xAxisIndex:v,yAxisIndex:f,data:S.map((c,l)=>({value:c,itemStyle:k[l]?{color:k[l]}:void 0})),itemStyle:{color:d.options.color}});break;case"circles":case"cross":const D=S.map((c,l)=>{if(c===null)return null;const b=k[l]||d.options.color,h={value:[l,c],itemStyle:{color:b}};return d.options.style==="cross"?(h.symbol=`image://${yt("+",b,"24px")}`,h.symbolSize=16):(h.symbol="circle",h.symbolSize=6),h}).filter(c=>c!==null);r.push({name:x,type:"scatter",xAxisIndex:v,yAxisIndex:f,data:D});break;case"shape":const y=S.map((c,l)=>{const b=L[l]||{},h=d.options,C=b.location||h.location||"absolute";if(C!=="absolute"&&!c||c==null)return null;const E=b.color||h.color||"blue",g=b.shape||h.shape||"circle",w=b.size||h.size||"normal",z=b.text||h.text,F=b.textcolor||h.textcolor||"white",H=b.width||h.width,I=b.height||h.height;let M=c,Z=[0,0];C==="abovebar"?(o&&o[l]&&(M=o[l].high),Z=[0,"-150%"]):C==="belowbar"?(o&&o[l]&&(M=o[l].low),Z=[0,"150%"]):C==="top"?(M=c,Z=[0,0]):C==="bottom"&&(M=c,Z=[0,0]);const N=V.getShapeSymbol(g),A=V.getShapeSize(w,H,I),R=V.getShapeRotation(g);let O=A;g.includes("label")&&(Array.isArray(A)?O=[A[0]*2.5,A[1]*2.5]:O=A*2.5);const X=V.getLabelConfig(g,C);return{value:[l,M],symbol:N,symbolSize:O,symbolRotate:R,symbolOffset:Z,itemStyle:{color:E},label:{show:!!z,position:X.position,distance:X.distance,formatter:z,color:F,fontSize:10,fontWeight:"bold"}}}).filter(c=>c!==null);r.push({name:x,type:"scatter",xAxisIndex:v,yAxisIndex:f,data:y});break;case"background":r.push({name:x,type:"custom",xAxisIndex:v,yAxisIndex:f,z:-10,renderItem:(c,l)=>{const b=l.value(0);if(isNaN(b))return;const h=l.coord([b,0]),C=l.size([1,0])[0],E=c.coordSys,g=h[0]-C/2,w=k[c.dataIndex],z=l.value(1);if(!(!w||!z))return{type:"rect",shape:{x:g,y:E.y,width:C,height:E.height},style:{fill:w,opacity:.3},silent:!0}},data:S.map((c,l)=>[l,c])});break;case"step":r.push({name:x,type:"custom",xAxisIndex:v,yAxisIndex:f,renderItem:(c,l)=>{const b=l.value(0),h=l.value(1);if(isNaN(h)||h===null)return;const C=l.coord([b,h]),E=l.size([1,0])[0];return{type:"line",shape:{x1:C[0]-E/2,y1:C[1],x2:C[0]+E/2,y2:C[1]},style:{stroke:k[c.dataIndex]||d.options.color,lineWidth:d.options.linewidth||1},silent:!0}},data:S.map((c,l)=>[l,c])});break;case"line":default:r.push({name:x,type:"custom",xAxisIndex:v,yAxisIndex:f,renderItem:(c,l)=>{const b=c.dataIndex;if(b===0)return;const h=l.value(1),C=l.value(2);if(h===null||isNaN(h)||C===null||isNaN(C))return;const E=l.coord([b-1,C]),g=l.coord([b,h]);return{type:"line",shape:{x1:E[0],y1:E[1],x2:g[0],y2:g[1]},style:{stroke:k[b]||d.options.color,lineWidth:d.options.linewidth||1},silent:!0}},data:S.map((c,l)=>[l,c,l>0?S[l-1]:null])});break}})}),r}}class xt{static build(e,t,i,s=!1,n=null){const o=[],r=e.pixelToPercent,p=e.mainPaneTop;if(!n||n==="main"){const u=10*r;if(o.push({type:"text",left:"8.5%",top:p+u+"%",z:10,style:{text:t.title||"Market",fill:t.titleColor||"#fff",font:`bold 16px ${t.fontFamily||"sans-serif"}`,textVerticalAlign:"top"}}),t.watermark!==!1){const f=e.mainPaneTop+e.mainPaneHeight;o.push({type:"text",right:"11%",top:f-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 v=[];if(t.controls?.collapse&&v.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 f=n==="main",m=t.controls?.collapse?25:0;v.push({type:"group",x:m,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:f?"\u2750":"\u25A1",fill:"#cbd5e1",font:`14px ${t.fontFamily}`,x:10,y:10,textAlign:"center",textVerticalAlign:"middle"},silent:!0}]})}if(t.controls?.fullscreen){let f=0;t.controls?.collapse&&(f+=25),t.controls?.maximize&&(f+=25),v.push({type:"group",x:f,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}]})}v.length>0&&o.push({type:"group",right:"10.5%",top:p+"%",children:v})}return e.paneLayout.forEach(u=>{if(n&&u.indicatorId!==n)return;o.push({type:"text",left:"8.5%",top:u.top+10*r+"%",z:10,style:{text:u.indicatorId||"",fill:u.titleColor||"#fff",font:`bold 12px ${t.fontFamily||"sans-serif"}`,textVerticalAlign:"top"}});const v=[];if(u.controls?.collapse&&v.push({type:"group",children:[{type:"rect",shape:{width:20,height:20,r:2},style:{fill:"#334155",stroke:"#475569",lineWidth:1},onclick:()=>u.indicatorId&&i(u.indicatorId,"collapse")},{type:"text",style:{text:u.isCollapsed?"+":"\u2212",fill:"#cbd5e1",font:`bold 14px ${t.fontFamily}`,x:10,y:10,textAlign:"center",textVerticalAlign:"middle"},silent:!0}]}),u.controls?.maximize){const f=n===u.indicatorId,m=u.controls?.collapse?25:0;v.push({type:"group",x:m,children:[{type:"rect",shape:{width:20,height:20,r:2},style:{fill:"#334155",stroke:"#475569",lineWidth:1},onclick:()=>u.indicatorId&&i(u.indicatorId,"maximize")},{type:"text",style:{text:f?"\u2750":"\u25A1",fill:"#cbd5e1",font:`14px ${t.fontFamily}`,x:10,y:10,textAlign:"center",textVerticalAlign:"middle"},silent:!0}]})}v.length>0&&o.push({type:"group",right:"10.5%",top:u.top+"%",children:v})}),o}}class mt{static format(e,t){if(!e||e.length===0)return"";const i=t.title||"Market",s=t.upColor||"#00da3c",n=t.downColor||"#ec0000",o=t.fontFamily||"sans-serif",r=e[0].axisValue;let p=`<div style="font-weight: bold; margin-bottom: 5px; color: #cbd5e1; font-family: ${o};">${r}</div>`;const u=e.find(f=>f.seriesType==="candlestick"),v=e.filter(f=>f.seriesType!=="candlestick");if(u){const[f,m,d,x,S]=u.value,k=d>=m?s:n;p+=`
|
|
18
|
-
<div style="margin-bottom: 8px; font-family: ${
|
|
19
|
-
<div style="display:flex; justify-content:space-between; color:${
|
|
17
|
+
import*as G from"echarts";var gt=Object.defineProperty,ft=(l,e,t)=>e in l?gt(l,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):l[e]=t,K=(l,e,t)=>(ft(l,typeof e!="symbol"?e+"":e,t),t);class yt{constructor(e,t,i,s={}){K(this,"id"),K(this,"plots"),K(this,"paneIndex"),K(this,"height"),K(this,"collapsed"),K(this,"titleColor"),K(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];s.options&&(i.options={...i.options,...s.options});const o=new Map;i.data.forEach(n=>{o.set(n.time,n)}),s.data.forEach(n=>{o.set(n.time,n)}),i.data=Array.from(o.values()).sort((n,h)=>n.time-h.time)}})}}class ut{static calculate(e,t,i,s=!1,o=null){let n=0;e>0&&(n=1/e*100);const h=Array.from(t.values()).map(c=>c.paneIndex).filter(c=>c>0).sort((c,b)=>c-b).filter((c,b,C)=>C.indexOf(c)===b),f=h.length>0,u=i.dataZoom?.visible??!0,M=i.dataZoom?.position??"top",y=i.dataZoom?.height??6,m=i.dataZoom?.start??0,I=i.dataZoom?.end??100;let p=8,g=92,v=-1;if(o)if(o==="main")v=0;else{const c=t.get(o);c&&(v=c.paneIndex)}if(v!==-1){const c=[],b=[],C=[],L=[],N=i.dataZoom?.start??50,P=i.dataZoom?.end??100;L.push({type:"inside",xAxisIndex:"all",start:N,end:P});const S=f?Math.max(...h):0,Z=[];for(let D=0;D<=S;D++){const A=D===v;if(c.push({left:"10%",right:"10%",top:A?"5%":"0%",height:A?"90%":"0%",show:A,containLabel:!1}),b.push({type:"category",gridIndex:D,data:[],show:A,axisLabel:{show:A,color:"#94a3b8",fontFamily:i.fontFamily},axisLine:{show:A,lineStyle:{color:"#334155"}},splitLine:{show:A,lineStyle:{color:"#334155",opacity:.5}}}),C.push({position:"right",gridIndex:D,show:A,scale:!0,axisLabel:{show:A,color:"#94a3b8",fontFamily:i.fontFamily},splitLine:{show:A,lineStyle:{color:"#334155",opacity:.5}}}),D>0){const Y=Array.from(t.values()).find(F=>F.paneIndex===D);Y&&Z.push({index:D,height:A?90:0,top:A?5:0,isCollapsed:!1,indicatorId:Y.id,titleColor:Y.titleColor,controls:Y.controls})}}return{grid:c,xAxis:b,yAxis:C,dataZoom:L,paneLayout:Z,mainPaneHeight:v===0?90:0,mainPaneTop:v===0?5:0,pixelToPercent:n}}u?M==="top"?(p=y+4,g=95):(g=100-y-2,p=8):(p=5,g=95);let z=5;e>0&&(z=20/e*100);let $=75,T=[];if(f){const c=h.map(P=>{const S=Array.from(t.values()).find(Z=>Z.paneIndex===P);return{index:P,requestedHeight:S?.height,isCollapsed:S?.collapsed??!1,indicatorId:S?.id,titleColor:S?.titleColor,controls:S?.controls}}).map(P=>({...P,height:P.isCollapsed?3:P.requestedHeight!==void 0?P.requestedHeight:15})),b=c.reduce((P,S)=>P+S.height,0),C=c.length*z,L=b+C;$=g-p-L,s?$=3:$<20&&($=Math.max($,10));let N=p+$+z;T=c.map(P=>{const S={index:P.index,height:P.height,top:N,isCollapsed:P.isCollapsed,indicatorId:P.indicatorId,titleColor:P.titleColor,controls:P.controls};return N+=P.height+z,S})}else $=g-p,s&&($=3);const w=[];w.push({left:"10%",right:"10%",top:p+"%",height:$+"%",containLabel:!1}),T.forEach(c=>{w.push({left:"10%",right:"10%",top:c.top+"%",height:c.height+"%",containLabel:!1})});const k=[0,...T.map((c,b)=>b+1)],r=[],a=T.length===0;r.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"},axisTick:{show:!s},axisPointer:{label:{show:a,fontSize:11,backgroundColor:"#475569"}}}),T.forEach((c,b)=>{const C=b===T.length-1;r.push({type:"category",gridIndex:b+1,data:[],axisLabel:{show:!1},axisLine:{show:!c.isCollapsed,lineStyle:{color:"#334155"}},axisTick:{show:!1},splitLine:{show:!1},axisPointer:{label:{show:C,fontSize:11,backgroundColor:"#475569"}}})});const d=[];d.push({position:"right",scale:!0,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"}}),T.forEach((c,b)=>{d.push({position:"right",scale:!0,gridIndex:b+1,splitLine:{show:!c.isCollapsed,lineStyle:{color:"#334155",opacity:.3}},axisLabel:{show:!c.isCollapsed,color:"#94a3b8",fontFamily:i.fontFamily||"sans-serif",fontSize:10},axisLine:{show:!c.isCollapsed,lineStyle:{color:"#334155"}}})});const x=[];return u&&(x.push({type:"inside",xAxisIndex:k,start:m,end:I}),M==="top"?x.push({type:"slider",xAxisIndex:k,top:"1%",height:y+"%",start:m,end:I,borderColor:"#334155",textStyle:{color:"#cbd5e1"},brushSelect:!1}):x.push({type:"slider",xAxisIndex:k,bottom:"1%",height:y+"%",start:m,end:I,borderColor:"#334155",textStyle:{color:"#cbd5e1"},brushSelect:!1})),{grid:w,xAxis:r,yAxis:d,dataZoom:x,paneLayout:T,mainPaneHeight:$,mainPaneTop:p,pixelToPercent:n}}static calculateMaximized(e,t,i){return{grid:[],xAxis:[],yAxis:[],dataZoom:[],paneLayout:[],mainPaneHeight:0,mainPaneTop:0,pixelToPercent:0}}}const ct=new Map;function xt(l,e="#00da3c",t="64px"){if(typeof document>"u")return"";const i=`${l}-${e}-${t}`;if(ct.has(i))return ct.get(i);const s=document.createElement("canvas"),o=s.getContext("2d");if(s.width=32,s.height=32,o){o.font="bold "+t+" Arial",o.fillStyle=e,o.textAlign="center",o.textBaseline="middle",o.fillText(l,16,16);const n=s.toDataURL("image/png");return ct.set(i,n),n}return""}class U{static buildCandlestickSeries(e,t,i){const s=t.upColor||"#00da3c",o=t.downColor||"#ec0000",n=e.map(h=>[h.open,h.close,h.low,h.high]);if(i&&i>n.length){const h=i-n.length;for(let f=0;f<h;f++)n.push(null)}return{type:"candlestick",name:t.title||"Market",data:n,itemStyle:{color:s,color0:o,borderColor:s,borderColor0:o},xAxisIndex:0,yAxisIndex:0,z:5}}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://M4 2h16a2 2 0 0 1 2 2v12a2 2 0 0 1 -2 2h-6l-2 4l-2 -4h-6a2 2 0 0 1 -2 -2v-12a2 2 0 0 1 2 -2z";case"labelup":return"path://M12 2l2 4h6a2 2 0 0 1 2 2v12a2 2 0 0 1 -2 2h-16a2 2 0 0 1 -2 -2v-12a2 2 0 0 1 2 -2h6z";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}}}static buildIndicatorSeries(e,t,i,s,o=0,n){const h=[],f=new Array(s).fill(null);return e.forEach((u,M)=>{if(u.collapsed)return;let y=0,m=0;if(u.paneIndex>0){const I=i.findIndex(p=>p.index===u.paneIndex);I!==-1&&(y=I+1,m=I+1)}Object.keys(u.plots).forEach(I=>{const p=u.plots[I],g=`${M}::${I}`,v=new Array(s).fill(null),z=new Array(s).fill(null),$=new Array(s).fill(null);switch(p.data.forEach(T=>{const w=t.get(T.time);if(w!==void 0){const k=T.options?.offset??p.options.offset??0,r=w+o+k;if(r>=0&&r<s){let a=T.value;const d=T.options?.color;(d===null||d==="na"||d==="NaN"||typeof d=="number"&&isNaN(d))&&(a=null),v[r]=a,z[r]=d||p.options.color,$[r]=T.options||{}}}}),p.options.style){case"histogram":case"columns":h.push({name:g,type:"bar",xAxisIndex:y,yAxisIndex:m,data:v.map((r,a)=>({value:r,itemStyle:z[a]?{color:z[a]}:void 0})),itemStyle:{color:p.options.color}});break;case"circles":case"cross":const T=v.map((r,a)=>{if(r===null)return null;const d=z[a]||p.options.color,x={value:[a,r],itemStyle:{color:d}};return p.options.style==="cross"?(x.symbol=`image://${xt("+",d,"24px")}`,x.symbolSize=16):(x.symbol="circle",x.symbolSize=6),x}).filter(r=>r!==null);h.push({name:g,type:"scatter",xAxisIndex:y,yAxisIndex:m,data:T});break;case"bar":case"candle":const w=v.map((r,a)=>{if(r===null||!Array.isArray(r)||r.length!==4)return null;const[d,x,c,b]=r,C=$[a]||{},L=C.color||z[a]||p.options.color,N=C.wickcolor||p.options.wickcolor||L,P=C.bordercolor||p.options.bordercolor||N;return[a,d,b,c,x,L,N,P]}).filter(r=>r!==null);h.push({name:g,type:"custom",xAxisIndex:y,yAxisIndex:m,renderItem:(r,a)=>{const d=a.value(0),x=a.value(1),c=a.value(2),b=a.value(3),C=a.value(4),L=a.value(5),N=a.value(6),P=a.value(7);if(isNaN(x)||isNaN(c)||isNaN(b)||isNaN(C))return null;const S=a.coord([d,0])[0],Z=a.coord([d,x])[1],D=a.coord([d,c])[1],A=a.coord([d,b])[1],Y=a.coord([d,C])[1],F=a.size([1,0])[0]*.6;if(p.options.style==="candle"){const O=Math.min(Z,D),R=Math.max(Z,D),j=Math.abs(D-Z);return{type:"group",children:[{type:"line",shape:{x1:S,y1:Y,x2:S,y2:O},style:{stroke:N,lineWidth:1}},{type:"line",shape:{x1:S,y1:R,x2:S,y2:A},style:{stroke:N,lineWidth:1}},{type:"rect",shape:{x:S-F/2,y:O,width:F,height:j||1},style:{fill:L,stroke:P,lineWidth:1}}]}}else{const O=F*.5;return{type:"group",children:[{type:"line",shape:{x1:S,y1:A,x2:S,y2:Y},style:{stroke:L,lineWidth:1}},{type:"line",shape:{x1:S-O,y1:Z,x2:S,y2:Z},style:{stroke:L,lineWidth:1}},{type:"line",shape:{x1:S,y1:D,x2:S+O,y2:D},style:{stroke:L,lineWidth:1}}]}}},data:w});break;case"shape":const k=v.map((r,a)=>{const d=$[a]||{},x=p.options,c=d.location||x.location||"absolute";if(c!=="absolute"&&!r||r==null)return null;const b=d.color||x.color||"blue",C=d.shape||x.shape||"circle",L=d.size||x.size||"normal",N=d.text||x.text,P=d.textcolor||x.textcolor||"white",S=d.width||x.width,Z=d.height||x.height;let D=r,A=[0,0];c==="abovebar"?(n&&n[a]&&(D=n[a].high),A=[0,"-150%"]):c==="belowbar"?(n&&n[a]&&(D=n[a].low),A=[0,"150%"]):c==="top"?(D=r,A=[0,0]):c==="bottom"&&(D=r,A=[0,0]);const Y=U.getShapeSymbol(C),F=U.getShapeSize(L,S,Z),O=U.getShapeRotation(C);let R=F;C.includes("label")&&(Array.isArray(F)?R=[F[0]*2.5,F[1]*2.5]:R=F*2.5);const j=U.getLabelConfig(C,c);return{value:[a,D],symbol:Y,symbolSize:R,symbolRotate:O,symbolOffset:A,itemStyle:{color:b},label:{show:!!N,position:j.position,distance:j.distance,formatter:N,color:P,fontSize:10,fontWeight:"bold"}}}).filter(r=>r!==null);h.push({name:g,type:"scatter",xAxisIndex:y,yAxisIndex:m,data:k});break;case"background":h.push({name:g,type:"custom",xAxisIndex:y,yAxisIndex:m,z:-10,renderItem:(r,a)=>{const d=a.value(0);if(isNaN(d))return;const x=a.coord([d,0]),c=a.size([1,0])[0],b=r.coordSys,C=x[0]-c/2,L=z[r.dataIndex],N=a.value(1);if(!(!L||!N))return{type:"rect",shape:{x:C,y:b.y,width:c,height:b.height},style:{fill:L,opacity:.3},silent:!0}},data:v.map((r,a)=>[a,r])});break;case"step":h.push({name:g,type:"custom",xAxisIndex:y,yAxisIndex:m,renderItem:(r,a)=>{const d=a.value(0),x=a.value(1);if(isNaN(x)||x===null)return;const c=a.coord([d,x]),b=a.size([1,0])[0];return{type:"line",shape:{x1:c[0]-b/2,y1:c[1],x2:c[0]+b/2,y2:c[1]},style:{stroke:z[r.dataIndex]||p.options.color,lineWidth:p.options.linewidth||1},silent:!0}},data:v.map((r,a)=>[a,r])});break;case"barcolor":p.data.forEach(r=>{const a=t.get(r.time);if(a!==void 0){const d=r.options?.offset??p.options.offset??0,x=a+o+d;if(x>=0&&x<s){const c=r.options?.color||p.options.color;!(c===null||c==="na"||c==="NaN"||typeof c=="number"&&isNaN(c))&&r.value&&(f[x]=c)}}});break;case"char":h.push({name:g,type:"scatter",xAxisIndex:y,yAxisIndex:m,symbolSize:0,data:v.map((r,a)=>({value:[a,r],itemStyle:{opacity:0}})),silent:!0});break;case"line":default:h.push({name:g,type:"custom",xAxisIndex:y,yAxisIndex:m,renderItem:(r,a)=>{const d=r.dataIndex;if(d===0)return;const x=a.value(1),c=a.value(2);if(x===null||isNaN(x)||c===null||isNaN(c))return;const b=a.coord([d-1,c]),C=a.coord([d,x]);return{type:"line",shape:{x1:b[0],y1:b[1],x2:C[0],y2:C[1]},style:{stroke:z[d]||p.options.color,lineWidth:p.options.linewidth||1},silent:!0}},data:v.map((r,a)=>[a,r,a>0?v[a-1]:null])});break}})}),{series:h,barColors:f}}}class mt{static build(e,t,i,s=!1,o=null){const n=[],h=e.pixelToPercent,f=e.mainPaneTop;if(!o||o==="main"){const u=10*h;if(n.push({type:"text",left:"8.5%",top:f+u+"%",z:10,style:{text:t.title||"Market",fill:t.titleColor||"#fff",font:`bold 16px ${t.fontFamily||"sans-serif"}`,textVerticalAlign:"top"}}),t.watermark!==!1){const y=e.mainPaneTop+e.mainPaneHeight;n.push({type:"text",right:"11%",top:y-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 M=[];if(t.controls?.collapse&&M.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 y=o==="main",m=t.controls?.collapse?25:0;M.push({type:"group",x:m,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:y?"\u2750":"\u25A1",fill:"#cbd5e1",font:`14px ${t.fontFamily}`,x:10,y:10,textAlign:"center",textVerticalAlign:"middle"},silent:!0}]})}if(t.controls?.fullscreen){let y=0;t.controls?.collapse&&(y+=25),t.controls?.maximize&&(y+=25),M.push({type:"group",x:y,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}]})}M.length>0&&n.push({type:"group",right:"10.5%",top:f+"%",children:M})}return e.paneLayout.forEach(u=>{if(o&&u.indicatorId!==o)return;n.push({type:"text",left:"8.5%",top:u.top+10*h+"%",z:10,style:{text:u.indicatorId||"",fill:u.titleColor||"#fff",font:`bold 12px ${t.fontFamily||"sans-serif"}`,textVerticalAlign:"top"}});const M=[];if(u.controls?.collapse&&M.push({type:"group",children:[{type:"rect",shape:{width:20,height:20,r:2},style:{fill:"#334155",stroke:"#475569",lineWidth:1},onclick:()=>u.indicatorId&&i(u.indicatorId,"collapse")},{type:"text",style:{text:u.isCollapsed?"+":"\u2212",fill:"#cbd5e1",font:`bold 14px ${t.fontFamily}`,x:10,y:10,textAlign:"center",textVerticalAlign:"middle"},silent:!0}]}),u.controls?.maximize){const y=o===u.indicatorId,m=u.controls?.collapse?25:0;M.push({type:"group",x:m,children:[{type:"rect",shape:{width:20,height:20,r:2},style:{fill:"#334155",stroke:"#475569",lineWidth:1},onclick:()=>u.indicatorId&&i(u.indicatorId,"maximize")},{type:"text",style:{text:y?"\u2750":"\u25A1",fill:"#cbd5e1",font:`14px ${t.fontFamily}`,x:10,y:10,textAlign:"center",textVerticalAlign:"middle"},silent:!0}]})}M.length>0&&n.push({type:"group",right:"10.5%",top:u.top+"%",children:M})}),n}}class bt{static format(e,t){if(!e||e.length===0)return"";const i=t.title||"Market",s=t.upColor||"#00da3c",o=t.downColor||"#ec0000",n=t.fontFamily||"sans-serif",h=e[0].axisValue;let f=`<div style="font-weight: bold; margin-bottom: 5px; color: #cbd5e1; font-family: ${n};">${h}</div>`;const u=e.find(y=>y.seriesType==="candlestick"),M=e.filter(y=>y.seriesType!=="candlestick");if(u){const[y,m,I,p,g]=u.value,v=I>=m?s:o;f+=`
|
|
18
|
+
<div style="margin-bottom: 8px; font-family: ${n};">
|
|
19
|
+
<div style="display:flex; justify-content:space-between; color:${v}; 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: ${
|
|
24
|
-
<span>High:</span> <span style="text-align: right; color: ${s}">${
|
|
25
|
-
<span>Low:</span> <span style="text-align: right; color: ${
|
|
26
|
-
<span>Close:</span> <span style="text-align: right; color: ${
|
|
23
|
+
<span>Open:</span> <span style="text-align: right; color: ${I>=m?s:o}">${m}</span>
|
|
24
|
+
<span>High:</span> <span style="text-align: right; color: ${s}">${g}</span>
|
|
25
|
+
<span>Low:</span> <span style="text-align: right; color: ${o}">${p}</span>
|
|
26
|
+
<span>Close:</span> <span style="text-align: right; color: ${I>=m?s:o}">${I}</span>
|
|
27
27
|
</div>
|
|
28
28
|
</div>
|
|
29
|
-
`}if(
|
|
30
|
-
<div style="margin-top: 8px; font-family: ${
|
|
29
|
+
`}if(M.length>0){f+='<div style="border-top: 1px solid #334155; margin: 5px 0; padding-top: 5px;"></div>';const y={};M.forEach(m=>{const I=m.seriesName.split("::"),p=I.length>1?I[0]:"Unknown",g=I.length>1?I[1]:m.seriesName;y[p]||(y[p]=[]),y[p].push({...m,displayName:g})}),Object.keys(y).forEach(m=>{f+=`
|
|
30
|
+
<div style="margin-top: 8px; font-family: ${n};">
|
|
31
31
|
<div style="font-weight:bold; color: #fff; margin-bottom: 2px;">${m}</div>
|
|
32
|
-
`,
|
|
32
|
+
`,y[m].forEach(I=>{let p=I.value;if(Array.isArray(p)&&(p=p[1]),p==null)return;const g=typeof p=="number"?p.toLocaleString(void 0,{maximumFractionDigits:4}):p;f+=`
|
|
33
33
|
<div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 2px; padding-left: 8px;">
|
|
34
|
-
<div>${
|
|
35
|
-
<div style="font-size: 10px; color: #fff;padding-left:10px;">${
|
|
36
|
-
</div>`}),p+="</div>"})}return p}}var bt=Object.defineProperty,vt=(a,e,t)=>e in a?bt(a,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):a[e]=t,K=(a,e,t)=>(vt(a,typeof e!="symbol"?e+"":e,t),t);class wt{constructor(e,t){K(this,"plugins",new Map),K(this,"activePluginId",null),K(this,"context"),K(this,"toolbarContainer"),K(this,"tooltipElement",null),K(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,o=i.right+10;this.tooltipElement.style.top=`${n}px`,this.tooltipElement.style.left=`${o}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.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 Ct=Object.defineProperty,St=(a,e,t)=>e in a?Ct(a,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):a[e]=t,$=(a,e,t)=>(St(a,typeof e!="symbol"?e+"":e,t),t);class kt{constructor(e){$(this,"context"),$(this,"isEditing",!1),$(this,"currentDrawing",null),$(this,"editingPointIndex",null),$(this,"zr"),$(this,"editGroup",null),$(this,"editLine",null),$(this,"editStartPoint",null),$(this,"editEndPoint",null),$(this,"isMovingShape",!1),$(this,"dragStart",null),$(this,"initialPixelPoints",[]),$(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))}),$(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))}),$(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,o=s-this.dragStart.y,r={x:this.initialPixelPoints[0].x+n,y:this.initialPixelPoints[0].y+o},p={x:this.initialPixelPoints[1].x+n,y:this.initialPixelPoints[1].y+o};this.editLine.setShape({x1:r.x,y1:r.y,x2:p.x,y2:p.y}),this.editStartPoint.setShape({cx:r.x,cy:r.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})))}),$(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 T.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 T.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 T.graphic.Circle({shape:{cx:i.x,cy:i.y,r:5},style:{fill:"#fff",stroke:"#3b82f6",lineWidth:2},z:1e3}),this.editEndPoint=new T.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((o,r)=>{const p=o.x+i,u=o.y+s;return this.context.coordinateConversion.pixelToData({x:p,y:u})});n.every(o=>o!==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 It=Object.defineProperty,Pt=(a,e,t)=>e in a?It(a,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):a[e]=t,Mt=(a,e,t)=>(Pt(a,typeof e!="symbol"?e+"":e,t),t);class Dt{constructor(){Mt(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 zt=Object.defineProperty,Et=(a,e,t)=>e in a?zt(a,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):a[e]=t,P=(a,e,t)=>(Et(a,typeof e!="symbol"?e+"":e,t),t);class At{constructor(e,t={}){P(this,"chart"),P(this,"options"),P(this,"marketData",[]),P(this,"indicators",new Map),P(this,"timeToIndex",new Map),P(this,"pluginManager"),P(this,"drawingEditor"),P(this,"events",new Dt),P(this,"isMainCollapsed",!1),P(this,"maximizedPaneId",null),P(this,"selectedDrawingId",null),P(this,"drawings",[]),P(this,"coordinateConversion",{pixelToData:n=>{const o=this.chart.getOption();if(!o||!o.grid)return null;const r=o.grid.length;for(let p=0;p<r;p++)if(this.chart.containPixel({gridIndex:p},[n.x,n.y])){this.chart.convertFromPixel({seriesIndex:p},[n.x,n.y]);const u=this.chart.convertFromPixel({gridIndex:p},[n.x,n.y]);if(u)return{timeIndex:Math.round(u[0]),value:u[1],paneIndex:p}}return null},dataToPixel:n=>{const o=n.paneIndex||0,r=this.chart.convertToPixel({gridIndex:o},[n.timeIndex,n.value]);return r?{x:r[0],y:r[1]}:null}}),P(this,"upColor","#00da3c"),P(this,"downColor","#ec0000"),P(this,"defaultPadding",0),P(this,"padding"),P(this,"dataIndexOffset",0),P(this,"rootContainer"),P(this,"layoutContainer"),P(this,"toolbarContainer"),P(this,"leftSidebar"),P(this,"rightSidebar"),P(this,"chartContainer"),P(this,"onKeyDown",n=>{(n.key==="Delete"||n.key==="Backspace")&&this.selectedDrawingId&&(this.removeDrawing(this.selectedDrawingId),this.selectedDrawingId=null,this.render())}),P(this,"onFullscreenChange",()=>{this.render()}),P(this,"isLocked",!1),P(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=T.init(this.chartContainer),this.pluginManager=new wt(this,this.toolbarContainer),this.drawingEditor=new kt(this),this.chart.on("dataZoom",n=>this.events.emit("chart:dataZoom",n)),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]),o=this.drawings.filter(p=>(p.paneIndex||0)===n)[i.dataIndex];if(!o)return null;const r=i.event?.target?.name;return{drawing:o,targetName:r,paneIdx:n}};this.chart.on("mouseover",i=>{const s=t(i);if(!s)return;const n=i.event?.target?.parent;if(n){const o=s.drawing.id===this.selectedDrawingId;e&&(clearTimeout(e),e=null),o||n.children().forEach(r=>{r.name&&r.name.startsWith("point")&&r.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 o=s.targetName==="point-start"?0:1;this.events.emit("drawing:point:hover",{id:s.drawing.id,pointIndex:o}),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(o=>{o.name&&o.name.startsWith("point")&&o.attr("style",{opacity:0})})}},50),s.targetName==="line")this.events.emit("drawing:mouseout",{id:s.drawing.id});else if(s.targetName?.startsWith("point")){const o=s.targetName==="point-start"?0:1;this.events.emit("drawing:point:mouseout",{id:s.drawing.id,pointIndex:o})}this.chart.getZr().setCursorStyle("default")}}),this.chart.on("mousedown",i=>{const s=t(i);if(!s)return;const n=i.event?.event||i.event,o=n?.offsetX,r=n?.offsetY;if(s.targetName==="line")this.events.emit("drawing:mousedown",{id:s.drawing.id,x:o,y:r});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:o,y:r})}}),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(d=>{t.set(d.time,d)}),e.forEach(d=>{t.has(d.time),t.set(d.time,d)}),this.marketData=Array.from(t.values()).sort((d,x)=>d.time-x.time),this.rebuildTimeIndex();const i=this.dataIndexOffset,s=this.marketData.map(d=>[d.open,d.close,d.low,d.high]),n={value:[NaN,NaN,NaN,NaN],itemStyle:{opacity:0}},o=[...Array(i).fill(n),...s,...Array(i).fill(n)],r=[...Array(i).fill(""),...this.marketData.map(d=>new Date(d.time).toLocaleString()),...Array(i).fill("")],p=this.chart.getOption(),u=pt.calculate(this.chart.getHeight(),this.indicators,this.options,this.isMainCollapsed,this.maximizedPaneId),v=[...Array(i).fill(null),...this.marketData,...Array(i).fill(null)],f=V.buildIndicatorSeries(this.indicators,this.timeToIndex,u.paneLayout,r.length,i,v),m={xAxis:p.xAxis.map((d,x)=>({data:r})),series:[{data:o},...f.map(d=>({data:d.data}))]};this.chart.setOption(m,{notMerge:!1})}addIndicator(e,t,i={isOverlay:!1}){const s=i.isOverlay??!1;let n=0;if(!s){let r=0;this.indicators.forEach(p=>{p.paneIndex>r&&(r=p.paneIndex)}),n=r+1}const o=new ft(e,t,n,{height:i.height,collapsed:!1,titleColor:i.titleColor,controls:i.controls});return this.indicators.set(e,o),this.render(),o}setIndicator(e,t,i=!1){this.addIndicator(e,{[e]:t},{isOverlay: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(){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 y=this.chart.getOption();if(y&&y.dataZoom&&y.dataZoom.length>0){const c=y.dataZoom.find(l=>l.type==="slider"||l.type==="inside");c&&(e={start:c.start,end:c.end})}}catch{}const t=this.options.databox?.position,i=this.leftSidebar.style.display,s=this.rightSidebar.style.display,n=t==="left"?"block":"none",o=t==="right"?"block":"none";(i!==n||s!==o)&&(this.leftSidebar.style.display=n,this.rightSidebar.style.display=o,this.chart.resize());const r=this.dataIndexOffset,p=[...Array(r).fill(""),...this.marketData.map(y=>new Date(y.time).toLocaleString()),...Array(r).fill("")],u=pt.calculate(this.chart.getHeight(),this.indicators,this.options,this.isMainCollapsed,this.maximizedPaneId);e&&u.dataZoom&&u.dataZoom.forEach(y=>{y.start=e.start,y.end=e.end}),u.xAxis.forEach(y=>{y.data=p,y.boundaryGap=!1});const v=V.buildCandlestickSeries(this.marketData,this.options),f={value:[NaN,NaN,NaN,NaN],itemStyle:{opacity:0}};v.data=[...Array(r).fill(f),...v.data,...Array(r).fill(f)];const m=[...Array(r).fill(null),...this.marketData,...Array(r).fill(null)],d=V.buildIndicatorSeries(this.indicators,this.timeToIndex,u.paneLayout,p.length,r,m),x=xt.build(u,this.options,this.toggleIndicator.bind(this),this.isMainCollapsed,this.maximizedPaneId),S=new Map;this.drawings.forEach(y=>{const c=y.paneIndex||0;S.has(c)||S.set(c,[]),S.get(c).push(y)});const k=[];S.forEach((y,c)=>{k.push({type:"custom",name:`drawings-pane-${c}`,xAxisIndex:c,yAxisIndex:c,clip:!0,renderItem:(l,b)=>{const h=y[l.dataIndex];if(!h)return;const C=h.points[0],E=h.points[1];if(!C||!E)return;const g=b.coord([C.timeIndex,C.value]),w=b.coord([E.timeIndex,E.value]),z=h.id===this.selectedDrawingId;if(h.type==="line")return{type:"group",children:[{type:"line",name:"line",shape:{x1:g[0],y1:g[1],x2:w[0],y2:w[1]},style:{stroke:h.style?.color||"#3b82f6",lineWidth:h.style?.lineWidth||2}},{type:"circle",name:"point-start",shape:{cx:g[0],cy:g[1],r:4},style:{fill:"#fff",stroke:h.style?.color||"#3b82f6",lineWidth:1,opacity:z?1:0}},{type:"circle",name:"point-end",shape:{cx:w[0],cy:w[1],r:4},style:{fill:"#fff",stroke:h.style?.color||"#3b82f6",lineWidth:1,opacity:z?1:0}}]};if(h.type==="fibonacci"){const F=g[0],H=g[1],I=w[0],M=w[1],Z=Math.min(F,I),N=Math.max(F,I),A=N-Z,R=M-H,O=[0,.236,.382,.5,.618,.786,1],X=["#787b86","#f44336","#ff9800","#4caf50","#2196f3","#00bcd4","#787b86"],J=[];J.push({type:"line",name:"line",shape:{x1:F,y1:H,x2:I,y2:M},style:{stroke:"#999",lineWidth:1,lineDash:[4,4]}}),J.push({type:"circle",name:"point-start",shape:{cx:F,cy:H,r:4},style:{fill:"#fff",stroke:h.style?.color||"#3b82f6",lineWidth:1,opacity:z?1:0},z:100}),J.push({type:"circle",name:"point-end",shape:{cx:I,cy:M,r:4},style:{fill:"#fff",stroke:h.style?.color||"#3b82f6",lineWidth:1,opacity:z?1:0},z:100}),O.forEach((q,B)=>{const j=M-R*q,Q=X[B%X.length];J.push({type:"line",name:"fib-line",shape:{x1:Z,y1:j,x2:N,y2:j},style:{stroke:Q,lineWidth:1},silent:!0});const nt=h.points[0].value,_=h.points[1].value,ot=_-nt,at=_-ot*q;if(J.push({type:"text",style:{text:`${q} (${at.toFixed(2)})`,x:Z+5,y:j-10,fill:Q,fontSize:10},silent:!0}),B<O.length-1){const rt=O[B+1],tt=M-R*rt,lt=Math.abs(tt-j),ht=Math.min(j,tt);J.push({type:"rect",shape:{x:Z,y:ht,width:A,height:lt},style:{fill:X[(B+1)%X.length],opacity:.1},silent:!0})}});const ct=[],st=[];return O.forEach((q,B)=>{const j=M-R*q,Q=X[B%X.length];st.push({type:"line",shape:{x1:Z,y1:j,x2:N,y2:j},style:{stroke:Q,lineWidth:1},silent:!0});const nt=h.points[0].value,_=h.points[1].value,ot=_-nt,at=_-ot*q;if(st.push({type:"text",style:{text:`${q} (${at.toFixed(2)})`,x:Z+5,y:j-10,fill:Q,fontSize:10},silent:!0}),B<O.length-1){const rt=O[B+1],tt=M-R*rt,lt=Math.abs(tt-j),ht=Math.min(j,tt);ct.push({type:"rect",name:"line",shape:{x:Z,y:ht,width:A,height:lt},style:{fill:X[(B+1)%X.length],opacity:.1}})}}),{type:"group",children:[...ct,...st,{type:"line",name:"line",shape:{x1:F,y1:H,x2:I,y2:M},style:{stroke:"#999",lineWidth:1,lineDash:[4,4]}},{type:"circle",name:"point-start",shape:{cx:F,cy:H,r:4},style:{fill:"#fff",stroke:h.style?.color||"#3b82f6",lineWidth:1,opacity:z?1:0},z:100},{type:"circle",name:"point-end",shape:{cx:I,cy:M,r:4},style:{fill:"#fff",stroke:h.style?.color||"#3b82f6",lineWidth:1,opacity:z?1:0},z:100}]}}},data:y.map(l=>[l.points[0].timeIndex,l.points[0].value,l.points[1].timeIndex,l.points[1].value]),z:100,silent:!1})});const L=y=>{const c=mt.format(y,this.options),l=this.options.databox?.position;return l==="left"?(this.leftSidebar.innerHTML=c,""):l==="right"?(this.rightSidebar.innerHTML=c,""):this.options.databox?`<div style="min-width: 200px;">${c}</div>`:""},D={backgroundColor:this.options.backgroundColor,animation:!1,legend:{show:!1},tooltip:{show:!0,showContent:!!this.options.databox,trigger:"axis",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:L,extraCssText:t!=="floating"&&t!==void 0?"display: none !important;":void 0,position:(y,c,l,b,h)=>{if(this.options.databox?.position==="floating"){const C={top:10};return C[["left","right"][+(y[0]<h.viewSize[0]/2)]]=30,C}return null}},axisPointer:{link:{xAxisIndex:"all"},label:{backgroundColor:"#475569"}},graphic:x,grid:u.grid,xAxis:u.xAxis,yAxis:u.yAxis,dataZoom:u.dataZoom,series:[v,...d,...k]};this.chart.setOption(D,!0)}}var Tt=Object.defineProperty,Lt=(a,e,t)=>e in a?Tt(a,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):a[e]=t,et=(a,e,t)=>(Lt(a,typeof e!="symbol"?e+"":e,t),t);class it{constructor(e){et(this,"id"),et(this,"name"),et(this,"icon"),et(this,"context"),et(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 Zt=Object.defineProperty,Gt=(a,e,t)=>e in a?Zt(a,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):a[e]=t,G=(a,e,t)=>(Gt(a,typeof e!="symbol"?e+"":e,t),t);class $t extends it{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>'}),G(this,"zr"),G(this,"state","idle"),G(this,"startPoint",null),G(this,"endPoint",null),G(this,"group",null),G(this,"rect",null),G(this,"labelRect",null),G(this,"labelText",null),G(this,"lineV",null),G(this,"lineH",null),G(this,"arrowStart",null),G(this,"arrowEnd",null),G(this,"onMouseDown",()=>{this.state==="finished"&&this.removeGraphic()}),G(this,"onChartInteraction",()=>{this.group&&this.removeGraphic()}),G(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())}),G(this,"clearHandlers",{}),G(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 T.graphic.Group,this.rect=new T.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 T.graphic.Line({shape:{x1:0,y1:0,x2:0,y2:0},style:{stroke:"#fff",lineWidth:1,lineDash:[4,4]},z:101}),this.lineH=new T.graphic.Line({shape:{x1:0,y1:0,x2:0,y2:0},style:{stroke:"#fff",lineWidth:1,lineDash:[4,4]},z:101}),this.arrowStart=new T.graphic.Polygon({shape:{points:[[0,0],[-5,10],[5,10]]},style:{fill:"#fff"},z:102}),this.arrowEnd=new T.graphic.Polygon({shape:{points:[[0,0],[-5,-10],[5,-10]]},style:{fill:"#fff"},z:102}),this.labelRect=new T.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 T.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}),o=this.context.coordinateConversion.pixelToData({x:i,y:s});if(!n||!o)return;const r=Math.round(n.timeIndex),p=Math.round(o.timeIndex),u=n.value,v=o.value,f=p-r,m=v-u,d=m/u*100,x=m>=0,S=x?"rgba(33, 150, 243, 0.2)":"rgba(236, 0, 0, 0.2)",k=x?"#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:S});const L=(e+i)/2,D=(t+s)/2;this.lineV.setShape({x1:L,y1:t,x2:L,y2:s}),this.lineV.setStyle({stroke:k}),this.lineH.setShape({x1:e,y1:D,x2:i,y2:D}),this.lineH.setStyle({stroke:k});const y=Math.min(t,s),c=Math.max(t,s);this.arrowStart.setStyle({fill:"none"}),this.arrowEnd.setStyle({fill:"none"}),x?(this.arrowStart.setShape({points:[[L,y],[L-4,y+6],[L+4,y+6]]}),this.arrowStart.setStyle({fill:k})):(this.arrowEnd.setShape({points:[[L,c],[L-4,c-6],[L+4,c-6]]}),this.arrowEnd.setStyle({fill:k}));const l=[`${m.toFixed(2)} (${d.toFixed(2)}%)`,`${f} bars, ${(f*0).toFixed(0)}d`].join(`
|
|
37
|
-
`),
|
|
34
|
+
<div>${I.marker} <span style="color: #cbd5e1;">${I.displayName}</span></div>
|
|
35
|
+
<div style="font-size: 10px; color: #fff;padding-left:10px;">${g}</div>
|
|
36
|
+
</div>`}),f+="</div>"})}return f}}var vt=Object.defineProperty,wt=(l,e,t)=>e in l?vt(l,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):l[e]=t,Q=(l,e,t)=>(wt(l,typeof e!="symbol"?e+"":e,t),t);class Ct{constructor(e,t){Q(this,"plugins",new Map),Q(this,"activePluginId",null),Q(this,"context"),Q(this,"toolbarContainer"),Q(this,"tooltipElement",null),Q(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(),o=i.top+(i.height-s.height)/2,n=i.right+10;this.tooltipElement.style.top=`${o}px`,this.tooltipElement.style.left=`${n}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.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 It=Object.defineProperty,kt=(l,e,t)=>e in l?It(l,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):l[e]=t,H=(l,e,t)=>(kt(l,typeof e!="symbol"?e+"":e,t),t);class St{constructor(e){H(this,"context"),H(this,"isEditing",!1),H(this,"currentDrawing",null),H(this,"editingPointIndex",null),H(this,"zr"),H(this,"editGroup",null),H(this,"editLine",null),H(this,"editStartPoint",null),H(this,"editEndPoint",null),H(this,"isMovingShape",!1),H(this,"dragStart",null),H(this,"initialPixelPoints",[]),H(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 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))}),H(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))}),H(this,"onMouseMove",t=>{if(!this.isEditing||!this.currentDrawing)return;const i=t.offsetX,s=t.offsetY;if(this.isMovingShape&&this.dragStart){const o=i-this.dragStart.x,n=s-this.dragStart.y,h={x:this.initialPixelPoints[0].x+o,y:this.initialPixelPoints[0].y+n},f={x:this.initialPixelPoints[1].x+o,y:this.initialPixelPoints[1].y+n};this.editLine.setShape({x1:h.x,y1:h.y,x2:f.x,y2:f.y}),this.editStartPoint.setShape({cx:h.x,cy:h.y}),this.editEndPoint.setShape({cx:f.x,cy:f.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})))}),H(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 G.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 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(e,t){if(this.currentDrawing){if(this.isMovingShape&&this.dragStart){const i=e-this.dragStart.x,s=t-this.dragStart.y,o=this.initialPixelPoints.map((n,h)=>{const f=n.x+i,u=n.y+s;return this.context.coordinateConversion.pixelToData({x:f,y:u})});o.every(n=>n!==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: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 Pt=Object.defineProperty,Mt=(l,e,t)=>e in l?Pt(l,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):l[e]=t,Dt=(l,e,t)=>(Mt(l,typeof e!="symbol"?e+"":e,t),t);class Et{constructor(){Dt(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(o){console.error(`Error in EventBus handler for ${e}:`,o)}})}clear(){this.handlers.clear()}}var zt=Object.defineProperty,At=(l,e,t)=>e in l?zt(l,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):l[e]=t,E=(l,e,t)=>(At(l,typeof e!="symbol"?e+"":e,t),t);class Tt{constructor(e,t={}){E(this,"chart"),E(this,"options"),E(this,"marketData",[]),E(this,"indicators",new Map),E(this,"timeToIndex",new Map),E(this,"pluginManager"),E(this,"drawingEditor"),E(this,"events",new Et),E(this,"isMainCollapsed",!1),E(this,"maximizedPaneId",null),E(this,"selectedDrawingId",null),E(this,"drawings",[]),E(this,"coordinateConversion",{pixelToData:o=>{const n=this.chart.getOption();if(!n||!n.grid)return null;const h=n.grid.length;for(let f=0;f<h;f++)if(this.chart.containPixel({gridIndex:f},[o.x,o.y])){this.chart.convertFromPixel({seriesIndex:f},[o.x,o.y]);const u=this.chart.convertFromPixel({gridIndex:f},[o.x,o.y]);if(u)return{timeIndex:Math.round(u[0]),value:u[1],paneIndex:f}}return null},dataToPixel:o=>{const n=o.paneIndex||0,h=this.chart.convertToPixel({gridIndex:n},[o.timeIndex,o.value]);return h?{x:h[0],y:h[1]}:null}}),E(this,"upColor","#00da3c"),E(this,"downColor","#ec0000"),E(this,"defaultPadding",0),E(this,"padding"),E(this,"dataIndexOffset",0),E(this,"rootContainer"),E(this,"layoutContainer"),E(this,"toolbarContainer"),E(this,"leftSidebar"),E(this,"rightSidebar"),E(this,"chartContainer"),E(this,"onKeyDown",o=>{(o.key==="Delete"||o.key==="Backspace")&&this.selectedDrawingId&&(this.removeDrawing(this.selectedDrawingId),this.selectedDrawingId=null,this.render())}),E(this,"onFullscreenChange",()=>{this.render()}),E(this,"isLocked",!1),E(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=G.init(this.chartContainer),this.pluginManager=new Ct(this,this.toolbarContainer),this.drawingEditor=new St(this),this.chart.on("dataZoom",o=>this.events.emit("chart:dataZoom",o)),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 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 o=parseInt(s[1]),n=this.drawings.filter(f=>(f.paneIndex||0)===o)[i.dataIndex];if(!n)return null;const h=i.event?.target?.name;return{drawing:n,targetName:h,paneIdx:o}};this.chart.on("mouseover",i=>{const s=t(i);if(!s)return;const o=i.event?.target?.parent;if(o){const n=s.drawing.id===this.selectedDrawingId;e&&(clearTimeout(e),e=null),n||o.children().forEach(h=>{h.name&&h.name.startsWith("point")&&h.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 n=s.targetName==="point-start"?0:1;this.events.emit("drawing:point:hover",{id:s.drawing.id,pointIndex:n}),this.chart.getZr().setCursorStyle("pointer")}}),this.chart.on("mouseout",i=>{const s=t(i);if(!s)return;const o=i.event?.target?.parent;if(s.drawing.id!==this.selectedDrawingId){if(e=setTimeout(()=>{if(o){if(this.selectedDrawingId===s.drawing.id)return;o.children().forEach(n=>{n.name&&n.name.startsWith("point")&&n.attr("style",{opacity:0})})}},50),s.targetName==="line")this.events.emit("drawing:mouseout",{id:s.drawing.id});else if(s.targetName?.startsWith("point")){const n=s.targetName==="point-start"?0:1;this.events.emit("drawing:point:mouseout",{id:s.drawing.id,pointIndex:n})}this.chart.getZr().setCursorStyle("default")}}),this.chart.on("mousedown",i=>{const s=t(i);if(!s)return;const o=i.event?.event||i.event,n=o?.offsetX,h=o?.offsetY;if(s.targetName==="line")this.events.emit("drawing:mousedown",{id:s.drawing.id,x:n,y:h});else if(s.targetName?.startsWith("point")){const f=s.targetName==="point-start"?0:1;this.events.emit("drawing:point:mousedown",{id:s.drawing.id,pointIndex:f,x:n,y:h})}}),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 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(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(g=>{t.set(g.time,g)}),e.forEach(g=>{t.has(g.time),t.set(g.time,g)}),this.marketData=Array.from(t.values()).sort((g,v)=>g.time-v.time),this.rebuildTimeIndex();const i=this.dataIndexOffset,s=this.marketData.map(g=>[g.open,g.close,g.low,g.high]),o={value:[NaN,NaN,NaN,NaN],itemStyle:{opacity:0}},n=[...Array(i).fill(o),...s,...Array(i).fill(o)],h=[...Array(i).fill(""),...this.marketData.map(g=>new Date(g.time).toLocaleString()),...Array(i).fill("")],f=this.chart.getOption(),u=ut.calculate(this.chart.getHeight(),this.indicators,this.options,this.isMainCollapsed,this.maximizedPaneId),M=[...Array(i).fill(null),...this.marketData,...Array(i).fill(null)],{series:y,barColors:m}=U.buildIndicatorSeries(this.indicators,this.timeToIndex,u.paneLayout,h.length,i,M),I=n.map((g,v)=>m[v]?{value:g.value||g,itemStyle:{color:m[v],color0:m[v],borderColor:m[v],borderColor0:m[v]}}:g),p={xAxis:f.xAxis.map((g,v)=>({data:h})),series:[{data:I},...y.map(g=>({data:g.data}))]};this.chart.setOption(p,{notMerge:!1})}addIndicator(e,t,i={isOverlay:!1}){const s=i.isOverlay??!1;let o=0;if(!s){let h=0;this.indicators.forEach(f=>{f.paneIndex>h&&(h=f.paneIndex)}),o=h+1}const n=new yt(e,t,o,{height:i.height,collapsed:!1,titleColor:i.titleColor,controls:i.controls});return this.indicators.set(e,n),this.render(),n}setIndicator(e,t,i=!1){this.addIndicator(e,{[e]:t},{isOverlay: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(){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 w=this.chart.getOption();if(w&&w.dataZoom&&w.dataZoom.length>0){const k=w.dataZoom.find(r=>r.type==="slider"||r.type==="inside");k&&(e={start:k.start,end:k.end})}}catch{}const t=this.options.databox?.position,i=this.leftSidebar.style.display,s=this.rightSidebar.style.display,o=t==="left"?"block":"none",n=t==="right"?"block":"none";(i!==o||s!==n)&&(this.leftSidebar.style.display=o,this.rightSidebar.style.display=n,this.chart.resize());const h=this.dataIndexOffset,f=[...Array(h).fill(""),...this.marketData.map(w=>new Date(w.time).toLocaleString()),...Array(h).fill("")],u=ut.calculate(this.chart.getHeight(),this.indicators,this.options,this.isMainCollapsed,this.maximizedPaneId);e&&u.dataZoom&&u.dataZoom.forEach(w=>{w.start=e.start,w.end=e.end}),u.xAxis.forEach(w=>{w.data=f,w.boundaryGap=!1});const M=U.buildCandlestickSeries(this.marketData,this.options),y={value:[NaN,NaN,NaN,NaN],itemStyle:{opacity:0}};M.data=[...Array(h).fill(y),...M.data,...Array(h).fill(y)];const m=[...Array(h).fill(null),...this.marketData,...Array(h).fill(null)],{series:I,barColors:p}=U.buildIndicatorSeries(this.indicators,this.timeToIndex,u.paneLayout,f.length,h,m);M.data=M.data.map((w,k)=>p[k]?{value:w.value||w,itemStyle:{color:p[k],color0:p[k],borderColor:p[k],borderColor0:p[k]}}:w);const g=mt.build(u,this.options,this.toggleIndicator.bind(this),this.isMainCollapsed,this.maximizedPaneId),v=new Map;this.drawings.forEach(w=>{const k=w.paneIndex||0;v.has(k)||v.set(k,[]),v.get(k).push(w)});const z=[];v.forEach((w,k)=>{z.push({type:"custom",name:`drawings-pane-${k}`,xAxisIndex:k,yAxisIndex:k,clip:!0,renderItem:(r,a)=>{const d=w[r.dataIndex];if(!d)return;const x=d.points[0],c=d.points[1];if(!x||!c)return;const b=a.coord([x.timeIndex,x.value]),C=a.coord([c.timeIndex,c.value]),L=d.id===this.selectedDrawingId;if(d.type==="line")return{type:"group",children:[{type:"line",name:"line",shape:{x1:b[0],y1:b[1],x2:C[0],y2:C[1]},style:{stroke:d.style?.color||"#3b82f6",lineWidth:d.style?.lineWidth||2}},{type:"circle",name:"point-start",shape:{cx:b[0],cy:b[1],r:4},style:{fill:"#fff",stroke:d.style?.color||"#3b82f6",lineWidth:1,opacity:L?1:0}},{type:"circle",name:"point-end",shape:{cx:C[0],cy:C[1],r:4},style:{fill:"#fff",stroke:d.style?.color||"#3b82f6",lineWidth:1,opacity:L?1:0}}]};if(d.type==="fibonacci"){const N=b[0],P=b[1],S=C[0],Z=C[1],D=Math.min(N,S),A=Math.max(N,S),Y=A-D,F=Z-P,O=[0,.236,.382,.5,.618,.786,1],R=["#787b86","#f44336","#ff9800","#4caf50","#2196f3","#00bcd4","#787b86"],j=[];j.push({type:"line",name:"line",shape:{x1:N,y1:P,x2:S,y2:Z},style:{stroke:"#999",lineWidth:1,lineDash:[4,4]}}),j.push({type:"circle",name:"point-start",shape:{cx:N,cy:P,r:4},style:{fill:"#fff",stroke:d.style?.color||"#3b82f6",lineWidth:1,opacity:L?1:0},z:100}),j.push({type:"circle",name:"point-end",shape:{cx:S,cy:Z,r:4},style:{fill:"#fff",stroke:d.style?.color||"#3b82f6",lineWidth:1,opacity:L?1:0},z:100}),O.forEach((J,B)=>{const q=Z-F*J,_=R[B%R.length];j.push({type:"line",name:"fib-line",shape:{x1:D,y1:q,x2:A,y2:q},style:{stroke:_,lineWidth:1},silent:!0});const nt=d.points[0].value,tt=d.points[1].value,at=tt-nt,rt=tt-at*J;if(j.push({type:"text",style:{text:`${J} (${rt.toFixed(2)})`,x:D+5,y:q-10,fill:_,fontSize:10},silent:!0}),B<O.length-1){const lt=O[B+1],et=Z-F*lt,ht=Math.abs(et-q),dt=Math.min(q,et);j.push({type:"rect",shape:{x:D,y:dt,width:Y,height:ht},style:{fill:R[(B+1)%R.length],opacity:.1},silent:!0})}});const pt=[],ot=[];return O.forEach((J,B)=>{const q=Z-F*J,_=R[B%R.length];ot.push({type:"line",shape:{x1:D,y1:q,x2:A,y2:q},style:{stroke:_,lineWidth:1},silent:!0});const nt=d.points[0].value,tt=d.points[1].value,at=tt-nt,rt=tt-at*J;if(ot.push({type:"text",style:{text:`${J} (${rt.toFixed(2)})`,x:D+5,y:q-10,fill:_,fontSize:10},silent:!0}),B<O.length-1){const lt=O[B+1],et=Z-F*lt,ht=Math.abs(et-q),dt=Math.min(q,et);pt.push({type:"rect",name:"line",shape:{x:D,y:dt,width:Y,height:ht},style:{fill:R[(B+1)%R.length],opacity:.1}})}}),{type:"group",children:[...pt,...ot,{type:"line",name:"line",shape:{x1:N,y1:P,x2:S,y2:Z},style:{stroke:"#999",lineWidth:1,lineDash:[4,4]}},{type:"circle",name:"point-start",shape:{cx:N,cy:P,r:4},style:{fill:"#fff",stroke:d.style?.color||"#3b82f6",lineWidth:1,opacity:L?1:0},z:100},{type:"circle",name:"point-end",shape:{cx:S,cy:Z,r:4},style:{fill:"#fff",stroke:d.style?.color||"#3b82f6",lineWidth:1,opacity:L?1:0},z:100}]}}},data:w.map(r=>[r.points[0].timeIndex,r.points[0].value,r.points[1].timeIndex,r.points[1].value]),z:100,silent:!1})});const $=w=>{const k=bt.format(w,this.options),r=this.options.databox?.position;return r==="left"?(this.leftSidebar.innerHTML=k,""):r==="right"?(this.rightSidebar.innerHTML=k,""):this.options.databox?`<div style="min-width: 200px;">${k}</div>`:""},T={backgroundColor:this.options.backgroundColor,animation:!1,legend:{show:!1},tooltip:{show:!0,showContent:!!this.options.databox,trigger:"axis",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:$,extraCssText:t!=="floating"&&t!==void 0?"display: none !important;":void 0,position:(w,k,r,a,d)=>{if(this.options.databox?.position==="floating"){const x={top:10};return x[["left","right"][+(w[0]<d.viewSize[0]/2)]]=30,x}return null}},axisPointer:{link:{xAxisIndex:"all"},label:{backgroundColor:"#475569"}},graphic:g,grid:u.grid,xAxis:u.xAxis,yAxis:u.yAxis,dataZoom:u.dataZoom,series:[M,...I,...z]};this.chart.setOption(T,!0)}}var Lt=Object.defineProperty,Nt=(l,e,t)=>e in l?Lt(l,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):l[e]=t,it=(l,e,t)=>(Nt(l,typeof e!="symbol"?e+"":e,t),t);class st{constructor(e){it(this,"id"),it(this,"name"),it(this,"icon"),it(this,"context"),it(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 Zt=Object.defineProperty,$t=(l,e,t)=>e in l?Zt(l,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):l[e]=t,W=(l,e,t)=>($t(l,typeof e!="symbol"?e+"":e,t),t);class Gt extends st{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>'}),W(this,"zr"),W(this,"state","idle"),W(this,"startPoint",null),W(this,"endPoint",null),W(this,"group",null),W(this,"rect",null),W(this,"labelRect",null),W(this,"labelText",null),W(this,"lineV",null),W(this,"lineH",null),W(this,"arrowStart",null),W(this,"arrowEnd",null),W(this,"onMouseDown",()=>{this.state==="finished"&&this.removeGraphic()}),W(this,"onChartInteraction",()=>{this.group&&this.removeGraphic()}),W(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())}),W(this,"clearHandlers",{}),W(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 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[e,t]=this.startPoint,[i,s]=this.endPoint,o=this.context.coordinateConversion.pixelToData({x:e,y:t}),n=this.context.coordinateConversion.pixelToData({x:i,y:s});if(!o||!n)return;const h=Math.round(o.timeIndex),f=Math.round(n.timeIndex),u=o.value,M=n.value,y=f-h,m=M-u,I=m/u*100,p=m>=0,g=p?"rgba(33, 150, 243, 0.2)":"rgba(236, 0, 0, 0.2)",v=p?"#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:g});const z=(e+i)/2,$=(t+s)/2;this.lineV.setShape({x1:z,y1:t,x2:z,y2:s}),this.lineV.setStyle({stroke:v}),this.lineH.setShape({x1:e,y1:$,x2:i,y2:$}),this.lineH.setStyle({stroke:v});const T=Math.min(t,s),w=Math.max(t,s);this.arrowStart.setStyle({fill:"none"}),this.arrowEnd.setStyle({fill:"none"}),p?(this.arrowStart.setShape({points:[[z,T],[z-4,T+6],[z+4,T+6]]}),this.arrowStart.setStyle({fill:v})):(this.arrowEnd.setShape({points:[[z,w],[z-4,w-6],[z+4,w-6]]}),this.arrowEnd.setStyle({fill:v}));const k=[`${m.toFixed(2)} (${I.toFixed(2)}%)`,`${y} bars, ${(y*0).toFixed(0)}d`].join(`
|
|
37
|
+
`),r=140,a=40,d=Math.max(t,s),x=Math.min(t,s);let c=(e+i)/2-r/2,b=d+10;const C=this.chart.getHeight();b+a>C&&(b=x-a-10),this.labelRect.setShape({x:c,y:b,width:r,height:a}),this.labelRect.setStyle({fill:"#1e293b",stroke:v,lineWidth:1}),this.labelText.setStyle({x:c+r/2,y:b+a/2,text:k,fill:"#fff"})}}var Wt=Object.defineProperty,Ft=(l,e,t)=>e in l?Wt(l,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):l[e]=t,X=(l,e,t)=>(Ft(l,typeof e!="symbol"?e+"":e,t),t);class Ht extends st{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>'}),X(this,"zr"),X(this,"state","idle"),X(this,"startPoint",null),X(this,"endPoint",null),X(this,"group",null),X(this,"line",null),X(this,"startCircle",null),X(this,"endCircle",null),X(this,"onMouseDown",()=>{}),X(this,"onChartInteraction",()=>{}),X(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 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()}}),X(this,"clearHandlers",{}),X(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 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[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 Ot=Object.defineProperty,Rt=(l,e,t)=>e in l?Ot(l,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):l[e]=t,V=(l,e,t)=>(Rt(l,typeof e!="symbol"?e+"":e,t),t);class Xt extends st{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>'}),V(this,"startPoint",null),V(this,"endPoint",null),V(this,"state","idle"),V(this,"graphicGroup",null),V(this,"levels",[0,.236,.382,.5,.618,.786,1]),V(this,"colors",["#787b86","#f44336","#ff9800","#4caf50","#2196f3","#00bcd4","#787b86"]),V(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())}),V(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 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 e=this.startPoint[0],t=this.startPoint[1],i=this.endPoint[0],s=this.endPoint[1],o=new G.graphic.Line({shape:{x1:e,y1:t,x2:i,y2:s},style:{stroke:"#999",lineWidth:1,lineDash:[4,4]},silent:!0});this.graphicGroup.add(o);const n=Math.min(e,i),h=Math.max(e,i),f=h-n,u=s-t;this.levels.forEach((M,y)=>{const m=s-u*M,I=this.colors[y%this.colors.length],p=new G.graphic.Line({shape:{x1:n,y1:m,x2:h,y2:m},style:{stroke:I,lineWidth:1},silent:!0});if(this.graphicGroup.add(p),y<this.levels.length-1){const g=this.levels[y+1],v=s-u*g,z=Math.abs(v-m),$=Math.min(m,v),T=new G.graphic.Rect({shape:{x:n,y:$,width:f,height:z},style:{fill:this.colors[(y+1)%this.colors.length],opacity:.1},silent:!0});this.graphicGroup.add(T)}})}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{st as AbstractPlugin,Xt as FibonacciTool,Ht as LineTool,Gt as MeasureTool,Tt as QFChart};
|
package/package.json
CHANGED
package/src/QFChart.ts
CHANGED
|
@@ -649,7 +649,7 @@ export class QFChart implements ChartContext {
|
|
|
649
649
|
|
|
650
650
|
const paddedOHLCVForShapes = [...Array(paddingPoints).fill(null), ...this.marketData, ...Array(paddingPoints).fill(null)];
|
|
651
651
|
|
|
652
|
-
const indicatorSeries = SeriesBuilder.buildIndicatorSeries(
|
|
652
|
+
const { series: indicatorSeries, barColors } = SeriesBuilder.buildIndicatorSeries(
|
|
653
653
|
this.indicators,
|
|
654
654
|
this.timeToIndex,
|
|
655
655
|
layout.paneLayout,
|
|
@@ -658,6 +658,22 @@ export class QFChart implements ChartContext {
|
|
|
658
658
|
paddedOHLCVForShapes // Pass padded OHLCV data
|
|
659
659
|
);
|
|
660
660
|
|
|
661
|
+
// Apply barColors to candlestick data
|
|
662
|
+
const coloredCandlestickData = paddedCandlestickData.map((candle: any, i: number) => {
|
|
663
|
+
if (barColors[i]) {
|
|
664
|
+
return {
|
|
665
|
+
value: candle.value || candle,
|
|
666
|
+
itemStyle: {
|
|
667
|
+
color: barColors[i],
|
|
668
|
+
color0: barColors[i],
|
|
669
|
+
borderColor: barColors[i],
|
|
670
|
+
borderColor0: barColors[i],
|
|
671
|
+
},
|
|
672
|
+
};
|
|
673
|
+
}
|
|
674
|
+
return candle;
|
|
675
|
+
});
|
|
676
|
+
|
|
661
677
|
// Update only the data arrays in the option, not the full config
|
|
662
678
|
const updateOption: any = {
|
|
663
679
|
xAxis: currentOption.xAxis.map((axis: any, index: number) => ({
|
|
@@ -665,7 +681,7 @@ export class QFChart implements ChartContext {
|
|
|
665
681
|
})),
|
|
666
682
|
series: [
|
|
667
683
|
{
|
|
668
|
-
data:
|
|
684
|
+
data: coloredCandlestickData,
|
|
669
685
|
},
|
|
670
686
|
...indicatorSeries.map((s) => ({
|
|
671
687
|
data: s.data,
|
|
@@ -860,7 +876,7 @@ export class QFChart implements ChartContext {
|
|
|
860
876
|
// Build array of OHLCV aligned with indices for shape positioning
|
|
861
877
|
const paddedOHLCVForShapes = [...Array(paddingPoints).fill(null), ...this.marketData, ...Array(paddingPoints).fill(null)];
|
|
862
878
|
|
|
863
|
-
const indicatorSeries = SeriesBuilder.buildIndicatorSeries(
|
|
879
|
+
const { series: indicatorSeries, barColors } = SeriesBuilder.buildIndicatorSeries(
|
|
864
880
|
this.indicators,
|
|
865
881
|
this.timeToIndex,
|
|
866
882
|
layout.paneLayout,
|
|
@@ -869,6 +885,22 @@ export class QFChart implements ChartContext {
|
|
|
869
885
|
paddedOHLCVForShapes // Pass padded OHLCV
|
|
870
886
|
);
|
|
871
887
|
|
|
888
|
+
// Apply barColors to candlestick data
|
|
889
|
+
candlestickSeries.data = candlestickSeries.data.map((candle: any, i: number) => {
|
|
890
|
+
if (barColors[i]) {
|
|
891
|
+
return {
|
|
892
|
+
value: candle.value || candle,
|
|
893
|
+
itemStyle: {
|
|
894
|
+
color: barColors[i],
|
|
895
|
+
color0: barColors[i],
|
|
896
|
+
borderColor: barColors[i],
|
|
897
|
+
borderColor0: barColors[i],
|
|
898
|
+
},
|
|
899
|
+
};
|
|
900
|
+
}
|
|
901
|
+
return candle;
|
|
902
|
+
});
|
|
903
|
+
|
|
872
904
|
// 3. Build Graphics
|
|
873
905
|
const graphic = GraphicBuilder.build(layout, this.options, this.toggleIndicator.bind(this), this.isMainCollapsed, this.maximizedPaneId);
|
|
874
906
|
|
|
@@ -179,8 +179,9 @@ export class SeriesBuilder {
|
|
|
179
179
|
totalDataLength: number,
|
|
180
180
|
dataIndexOffset: number = 0,
|
|
181
181
|
candlestickData?: OHLCV[] // Add candlestick data to access High/Low for positioning
|
|
182
|
-
): any[] {
|
|
182
|
+
): { series: any[]; barColors: (string | null)[] } {
|
|
183
183
|
const series: any[] = [];
|
|
184
|
+
const barColors: (string | null)[] = new Array(totalDataLength).fill(null);
|
|
184
185
|
|
|
185
186
|
indicators.forEach((indicator, id) => {
|
|
186
187
|
if (indicator.collapsed) return; // Skip if collapsed
|
|
@@ -283,6 +284,162 @@ export class SeriesBuilder {
|
|
|
283
284
|
});
|
|
284
285
|
break;
|
|
285
286
|
|
|
287
|
+
case 'bar':
|
|
288
|
+
case 'candle':
|
|
289
|
+
// OHLC Bar/Candle rendering
|
|
290
|
+
const ohlcData = dataArray
|
|
291
|
+
.map((val, i) => {
|
|
292
|
+
if (val === null || !Array.isArray(val) || val.length !== 4) return null;
|
|
293
|
+
|
|
294
|
+
const [open, high, low, close] = val;
|
|
295
|
+
const pointOpts = optionsArray[i] || {};
|
|
296
|
+
const color = pointOpts.color || colorArray[i] || plot.options.color;
|
|
297
|
+
const wickColor = pointOpts.wickcolor || plot.options.wickcolor || color;
|
|
298
|
+
const borderColor = pointOpts.bordercolor || plot.options.bordercolor || wickColor;
|
|
299
|
+
|
|
300
|
+
// Store colors in value array at positions 5, 6, and 7 for access in renderItem
|
|
301
|
+
return [i, open, close, low, high, color, wickColor, borderColor];
|
|
302
|
+
})
|
|
303
|
+
.filter((item) => item !== null);
|
|
304
|
+
|
|
305
|
+
series.push({
|
|
306
|
+
name: seriesName,
|
|
307
|
+
type: 'custom',
|
|
308
|
+
xAxisIndex: xAxisIndex,
|
|
309
|
+
yAxisIndex: yAxisIndex,
|
|
310
|
+
renderItem: (params: any, api: any) => {
|
|
311
|
+
const xValue = api.value(0);
|
|
312
|
+
const openValue = api.value(1);
|
|
313
|
+
const closeValue = api.value(2);
|
|
314
|
+
const lowValue = api.value(3);
|
|
315
|
+
const highValue = api.value(4);
|
|
316
|
+
const color = api.value(5);
|
|
317
|
+
const wickColor = api.value(6);
|
|
318
|
+
const borderColor = api.value(7);
|
|
319
|
+
|
|
320
|
+
if (isNaN(openValue) || isNaN(closeValue) || isNaN(lowValue) || isNaN(highValue)) {
|
|
321
|
+
return null;
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
const xPos = api.coord([xValue, 0])[0];
|
|
325
|
+
const openPos = api.coord([xValue, openValue])[1];
|
|
326
|
+
const closePos = api.coord([xValue, closeValue])[1];
|
|
327
|
+
const lowPos = api.coord([xValue, lowValue])[1];
|
|
328
|
+
const highPos = api.coord([xValue, highValue])[1];
|
|
329
|
+
|
|
330
|
+
const barWidth = api.size([1, 0])[0] * 0.6;
|
|
331
|
+
|
|
332
|
+
if (plot.options.style === 'candle') {
|
|
333
|
+
// Classic candlestick rendering
|
|
334
|
+
const bodyTop = Math.min(openPos, closePos);
|
|
335
|
+
const bodyBottom = Math.max(openPos, closePos);
|
|
336
|
+
const bodyHeight = Math.abs(closePos - openPos);
|
|
337
|
+
|
|
338
|
+
return {
|
|
339
|
+
type: 'group',
|
|
340
|
+
children: [
|
|
341
|
+
// Upper wick
|
|
342
|
+
{
|
|
343
|
+
type: 'line',
|
|
344
|
+
shape: {
|
|
345
|
+
x1: xPos,
|
|
346
|
+
y1: highPos,
|
|
347
|
+
x2: xPos,
|
|
348
|
+
y2: bodyTop,
|
|
349
|
+
},
|
|
350
|
+
style: {
|
|
351
|
+
stroke: wickColor,
|
|
352
|
+
lineWidth: 1,
|
|
353
|
+
},
|
|
354
|
+
},
|
|
355
|
+
// Lower wick
|
|
356
|
+
{
|
|
357
|
+
type: 'line',
|
|
358
|
+
shape: {
|
|
359
|
+
x1: xPos,
|
|
360
|
+
y1: bodyBottom,
|
|
361
|
+
x2: xPos,
|
|
362
|
+
y2: lowPos,
|
|
363
|
+
},
|
|
364
|
+
style: {
|
|
365
|
+
stroke: wickColor,
|
|
366
|
+
lineWidth: 1,
|
|
367
|
+
},
|
|
368
|
+
},
|
|
369
|
+
// Body
|
|
370
|
+
{
|
|
371
|
+
type: 'rect',
|
|
372
|
+
shape: {
|
|
373
|
+
x: xPos - barWidth / 2,
|
|
374
|
+
y: bodyTop,
|
|
375
|
+
width: barWidth,
|
|
376
|
+
height: bodyHeight || 1, // Minimum height for doji
|
|
377
|
+
},
|
|
378
|
+
style: {
|
|
379
|
+
fill: color,
|
|
380
|
+
stroke: borderColor,
|
|
381
|
+
lineWidth: 1,
|
|
382
|
+
},
|
|
383
|
+
},
|
|
384
|
+
],
|
|
385
|
+
};
|
|
386
|
+
} else {
|
|
387
|
+
// Bar style (OHLC bar)
|
|
388
|
+
const tickWidth = barWidth * 0.5;
|
|
389
|
+
|
|
390
|
+
return {
|
|
391
|
+
type: 'group',
|
|
392
|
+
children: [
|
|
393
|
+
// Vertical line (low to high)
|
|
394
|
+
{
|
|
395
|
+
type: 'line',
|
|
396
|
+
shape: {
|
|
397
|
+
x1: xPos,
|
|
398
|
+
y1: lowPos,
|
|
399
|
+
x2: xPos,
|
|
400
|
+
y2: highPos,
|
|
401
|
+
},
|
|
402
|
+
style: {
|
|
403
|
+
stroke: color,
|
|
404
|
+
lineWidth: 1,
|
|
405
|
+
},
|
|
406
|
+
},
|
|
407
|
+
// Open tick (left)
|
|
408
|
+
{
|
|
409
|
+
type: 'line',
|
|
410
|
+
shape: {
|
|
411
|
+
x1: xPos - tickWidth,
|
|
412
|
+
y1: openPos,
|
|
413
|
+
x2: xPos,
|
|
414
|
+
y2: openPos,
|
|
415
|
+
},
|
|
416
|
+
style: {
|
|
417
|
+
stroke: color,
|
|
418
|
+
lineWidth: 1,
|
|
419
|
+
},
|
|
420
|
+
},
|
|
421
|
+
// Close tick (right)
|
|
422
|
+
{
|
|
423
|
+
type: 'line',
|
|
424
|
+
shape: {
|
|
425
|
+
x1: xPos,
|
|
426
|
+
y1: closePos,
|
|
427
|
+
x2: xPos + tickWidth,
|
|
428
|
+
y2: closePos,
|
|
429
|
+
},
|
|
430
|
+
style: {
|
|
431
|
+
stroke: color,
|
|
432
|
+
lineWidth: 1,
|
|
433
|
+
},
|
|
434
|
+
},
|
|
435
|
+
],
|
|
436
|
+
};
|
|
437
|
+
}
|
|
438
|
+
},
|
|
439
|
+
data: ohlcData,
|
|
440
|
+
});
|
|
441
|
+
break;
|
|
442
|
+
|
|
286
443
|
case 'shape':
|
|
287
444
|
const shapeData = dataArray
|
|
288
445
|
.map((val, i) => {
|
|
@@ -480,6 +637,49 @@ export class SeriesBuilder {
|
|
|
480
637
|
});
|
|
481
638
|
break;
|
|
482
639
|
|
|
640
|
+
case 'barcolor':
|
|
641
|
+
// Apply colors to main chart candlesticks
|
|
642
|
+
// Don't create a visual series, just store colors in barColors array
|
|
643
|
+
plot.data.forEach((point) => {
|
|
644
|
+
const index = timeToIndex.get(point.time);
|
|
645
|
+
if (index !== undefined) {
|
|
646
|
+
const plotOffset = point.options?.offset ?? plot.options.offset ?? 0;
|
|
647
|
+
const offsetIndex = index + dataIndexOffset + plotOffset;
|
|
648
|
+
|
|
649
|
+
if (offsetIndex >= 0 && offsetIndex < totalDataLength) {
|
|
650
|
+
const pointColor = point.options?.color || plot.options.color;
|
|
651
|
+
// Only apply if color is valid (not 'na')
|
|
652
|
+
const isNaColor =
|
|
653
|
+
pointColor === null ||
|
|
654
|
+
pointColor === 'na' ||
|
|
655
|
+
pointColor === 'NaN' ||
|
|
656
|
+
(typeof pointColor === 'number' && isNaN(pointColor));
|
|
657
|
+
|
|
658
|
+
if (!isNaColor && point.value) {
|
|
659
|
+
// Only apply color if value is truthy
|
|
660
|
+
barColors[offsetIndex] = pointColor;
|
|
661
|
+
}
|
|
662
|
+
}
|
|
663
|
+
}
|
|
664
|
+
});
|
|
665
|
+
break;
|
|
666
|
+
|
|
667
|
+
case 'char':
|
|
668
|
+
// Invisible series - data only shown in tooltip/sidebar
|
|
669
|
+
series.push({
|
|
670
|
+
name: seriesName,
|
|
671
|
+
type: 'scatter',
|
|
672
|
+
xAxisIndex: xAxisIndex,
|
|
673
|
+
yAxisIndex: yAxisIndex,
|
|
674
|
+
symbolSize: 0, // Invisible
|
|
675
|
+
data: dataArray.map((val, i) => ({
|
|
676
|
+
value: [i, val],
|
|
677
|
+
itemStyle: { opacity: 0 },
|
|
678
|
+
})),
|
|
679
|
+
silent: true, // No interaction
|
|
680
|
+
});
|
|
681
|
+
break;
|
|
682
|
+
|
|
483
683
|
case 'line':
|
|
484
684
|
default:
|
|
485
685
|
series.push({
|
|
@@ -522,6 +722,6 @@ export class SeriesBuilder {
|
|
|
522
722
|
});
|
|
523
723
|
});
|
|
524
724
|
|
|
525
|
-
return series;
|
|
725
|
+
return { series, barColors };
|
|
526
726
|
}
|
|
527
727
|
}
|
package/src/types.ts
CHANGED
|
@@ -11,14 +11,28 @@ export interface OHLCV {
|
|
|
11
11
|
|
|
12
12
|
export interface IndicatorPoint {
|
|
13
13
|
time: number;
|
|
14
|
-
value: number | null;
|
|
14
|
+
value: number | number[] | null;
|
|
15
15
|
options?: {
|
|
16
16
|
color?: string;
|
|
17
17
|
offset?: number;
|
|
18
|
+
wickcolor?: string;
|
|
19
|
+
bordercolor?: string;
|
|
18
20
|
};
|
|
19
21
|
}
|
|
20
22
|
|
|
21
|
-
export type IndicatorStyle =
|
|
23
|
+
export type IndicatorStyle =
|
|
24
|
+
| 'line'
|
|
25
|
+
| 'step'
|
|
26
|
+
| 'columns'
|
|
27
|
+
| 'histogram'
|
|
28
|
+
| 'circles'
|
|
29
|
+
| 'cross'
|
|
30
|
+
| 'background'
|
|
31
|
+
| 'shape'
|
|
32
|
+
| 'char'
|
|
33
|
+
| 'bar'
|
|
34
|
+
| 'candle'
|
|
35
|
+
| 'barcolor';
|
|
22
36
|
|
|
23
37
|
export interface IndicatorOptions {
|
|
24
38
|
style: IndicatorStyle;
|
|
@@ -33,6 +47,8 @@ export interface IndicatorOptions {
|
|
|
33
47
|
location?: string;
|
|
34
48
|
width?: number;
|
|
35
49
|
height?: number;
|
|
50
|
+
wickcolor?: string;
|
|
51
|
+
bordercolor?: string;
|
|
36
52
|
}
|
|
37
53
|
|
|
38
54
|
export interface IndicatorPlot {
|