@qfo/qfchart 0.7.3 → 0.8.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 +49 -2
- package/dist/qfchart.min.browser.js +18 -16
- package/dist/qfchart.min.es.js +18 -16
- package/package.json +1 -1
- package/src/QFChart.ts +372 -59
- package/src/components/GraphicBuilder.ts +284 -263
- package/src/components/LayoutManager.ts +33 -22
- package/src/components/SeriesBuilder.ts +104 -0
- package/src/components/TableCanvasRenderer.ts +467 -0
- package/src/components/TableOverlayRenderer.ts +38 -9
- package/src/components/TooltipFormatter.ts +97 -97
- package/src/components/renderers/BackgroundRenderer.ts +59 -47
- package/src/components/renderers/BoxRenderer.ts +113 -17
- package/src/components/renderers/FillRenderer.ts +118 -3
- package/src/components/renderers/LabelRenderer.ts +35 -9
- package/src/components/renderers/OHLCBarRenderer.ts +171 -161
- package/src/components/renderers/PolylineRenderer.ts +26 -19
- package/src/types.ts +11 -2
- package/src/utils/ColorUtils.ts +1 -1
|
@@ -14,25 +14,27 @@
|
|
|
14
14
|
* See the License for the specific language governing permissions and
|
|
15
15
|
* limitations under the License.
|
|
16
16
|
*/
|
|
17
|
-
(function(nt,ut){typeof exports=="object"&&typeof module<"u"?ut(exports,require("echarts")):typeof define=="function"&&define.amd?define(["exports","echarts"],ut):(nt=typeof globalThis<"u"?globalThis:nt||self,ut(nt.QFChart={},nt.echarts))})(this,function(nt,ut){"use strict";function Pt(x){var t=Object.create(null);return x&&Object.keys(x).forEach(function(e){if(e!=="default"){var i=Object.getOwnPropertyDescriptor(x,e);Object.defineProperty(t,e,i.get?i:{enumerable:!0,get:function(){return x[e]}})}}),t.default=x,Object.freeze(t)}var H=Pt(ut),Dt=Object.defineProperty,Mt=(x,t,e)=>t in x?Dt(x,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):x[t]=e,ht=(x,t,e)=>(Mt(x,typeof t!="symbol"?t+"":t,e),e);class zt{constructor(t,e,i,s={}){ht(this,"id"),ht(this,"plots"),ht(this,"paneIndex"),ht(this,"height"),ht(this,"collapsed"),ht(this,"titleColor"),ht(this,"controls"),this.id=t,this.plots=e,this.paneIndex=i,this.height=s.height,this.collapsed=s.collapsed||!1,this.titleColor=s.titleColor,this.controls=s.controls}toggleCollapse(){this.collapsed=!this.collapsed}isVisible(){return!this.collapsed}updateData(t){Object.keys(t).forEach(e=>{if(!this.plots[e])this.plots[e]=t[e];else{const i=this.plots[e],s=t[e];if(!i.data)return;s.options&&(i.options={...i.options,...s.options});const a=new Map;i.data?.forEach(o=>{a.set(o.time,o)}),s.data?.forEach(o=>{a.set(o.time,o)}),i.data=Array.from(a.values()).sort((o,u)=>o.time-u.time)}})}}class Z{static createMinFunction(t){return e=>{const i=(e.max-e.min)*(t/100);return e.min-i}}static createMaxFunction(t){return e=>{const i=(e.max-e.min)*(t/100);return e.max+i}}static autoDetectDecimals(t){if(!t||t.length===0)return 2;const e=t[t.length-1].close;if(e===0||!isFinite(e)||isNaN(e))return 2;const i=Math.abs(e);if(i>=1)return 2;const s=Math.ceil(-Math.log10(i));return Math.min(s+4,10)}static formatValue(t,e){return typeof t=="number"?t.toFixed(e):String(t)}}class At{static calculate(t,e,i,s=!1,a=null,o,u){let d=0;t>0&&(d=1/t*100);const p=i.yAxisPadding!==void 0?i.yAxisPadding:5,g=Array.from(e.values()).map(S=>S.paneIndex).filter(S=>S>0).sort((S,L)=>S-L).filter((S,L,N)=>N.indexOf(S)===L),r=g.length>0,l=i.dataZoom?.visible??!0,h=i.dataZoom?.position??"top",n=i.dataZoom?.height??6,c=i.dataZoom?.start??0,f=i.dataZoom?.end??100;let m=8,w=92,C=-1;if(a)if(a==="main")C=0;else{const S=e.get(a);S&&(C=S.paneIndex)}if(C!==-1){const S=[],L=[],N=[],R=[],V=i.dataZoom?.start??50,E=i.dataZoom?.end??100;(i.dataZoom?.zoomOnTouch??!0)&&R.push({type:"inside",xAxisIndex:"all",start:V,end:E,filterMode:"weakFilter"});const T=r?Math.max(...g):0,B=[];for(let O=0;O<=T;O++){const j=O===C;S.push({left:"10%",right:"10%",top:j?"5%":"0%",height:j?"90%":"0%",show:j,containLabel:!1}),L.push({type:"category",gridIndex:O,data:[],show:j,axisLabel:{show:j,color:"#94a3b8",fontFamily:i.fontFamily},axisLine:{show:j,lineStyle:{color:"#334155"}},splitLine:{show:j,lineStyle:{color:"#334155",opacity:.5}}});let st,at;if(O===0&&C===0?(st=i.yAxisMin!==void 0&&i.yAxisMin!=="auto"?i.yAxisMin:Z.createMinFunction(p),at=i.yAxisMax!==void 0&&i.yAxisMax!=="auto"?i.yAxisMax:Z.createMaxFunction(p)):(st=Z.createMinFunction(p),at=Z.createMaxFunction(p)),N.push({position:"right",gridIndex:O,show:j,scale:!0,min:st,max:at,axisLabel:{show:j,color:"#94a3b8",fontFamily:i.fontFamily,formatter:Q=>{if(i.yAxisLabelFormatter)return i.yAxisLabelFormatter(Q);const rt=i.yAxisDecimalPlaces!==void 0?i.yAxisDecimalPlaces:Z.autoDetectDecimals(o);return Z.formatValue(Q,rt)}},splitLine:{show:j,lineStyle:{color:"#334155",opacity:.5}}}),O>0){const Q=Array.from(e.values()).find(rt=>rt.paneIndex===O);Q&&B.push({index:O,height:j?90:0,top:j?5:0,isCollapsed:!1,indicatorId:Q.id,titleColor:Q.titleColor,controls:Q.controls})}}return{grid:S,xAxis:L,yAxis:N,dataZoom:R,paneLayout:B,mainPaneHeight:C===0?90:0,mainPaneTop:C===0?5:0,pixelToPercent:d,overlayYAxisMap:new Map,separatePaneYAxisOffset:1}}l?h==="top"?(m=n+4,w=95):(w=100-n-2,m=8):(m=5,w=95);let A=5;t>0&&(A=20/t*100);let v=75,y=[];if(r){const S=g.map(E=>{const T=Array.from(e.values()).find(B=>B.paneIndex===E);return{index:E,requestedHeight:T?.height,isCollapsed:T?.collapsed??!1,indicatorId:T?.id,titleColor:T?.titleColor,controls:T?.controls}}).map(E=>({...E,height:E.isCollapsed?3:E.requestedHeight!==void 0?E.requestedHeight:15})),L=S.reduce((E,T)=>E+T.height,0),N=S.length*A,R=L+N;v=w-m-R,u!==void 0&&u>0&&!s?v=u:s?v=3:v<20&&(v=Math.max(v,10));let V=m+v+A;y=S.map(E=>{const T={index:E.index,height:E.height,top:V,isCollapsed:E.isCollapsed,indicatorId:E.indicatorId,titleColor:E.titleColor,controls:E.controls};return V+=E.height+A,T})}else v=w-m,s&&(v=3);const b=[];if(y.length>0){b.push({yPercent:m+v+A/2,aboveId:"main",belowId:y[0].indicatorId||""});for(let S=0;S<y.length-1;S++)b.push({yPercent:y[S].top+y[S].height+A/2,aboveId:y[S].indicatorId||"",belowId:y[S+1].indicatorId||""})}const _=[];_.push({left:"10%",right:"10%",top:m+"%",height:v+"%",containLabel:!1}),y.forEach(S=>{_.push({left:"10%",right:"10%",top:S.top+"%",height:S.height+"%",containLabel:!1})});const I=[0,...y.map((S,L)=>L+1)],P=[],k=y.length===0;P.push({type:"category",data:[],gridIndex:0,scale:!0,axisLine:{onZero:!1,show:!s,lineStyle:{color:"#334155"}},splitLine:{show:!s,lineStyle:{color:"#334155",opacity:.5}},axisLabel:{show:!s,color:"#94a3b8",fontFamily:i.fontFamily||"sans-serif",formatter:S=>{if(i.yAxisLabelFormatter)return i.yAxisLabelFormatter(S);const L=i.yAxisDecimalPlaces!==void 0?i.yAxisDecimalPlaces:Z.autoDetectDecimals(o);return Z.formatValue(S,L)}},axisTick:{show:!s},axisPointer:{label:{show:k,fontSize:11,backgroundColor:"#475569"}}}),y.forEach((S,L)=>{const N=L===y.length-1;P.push({type:"category",gridIndex:L+1,data:[],axisLabel:{show:!1},axisLine:{show:!S.isCollapsed,lineStyle:{color:"#334155"}},axisTick:{show:!1},splitLine:{show:!1},axisPointer:{label:{show:N,fontSize:11,backgroundColor:"#475569"}}})});const D=[];let M,$;i.yAxisMin!==void 0&&i.yAxisMin!=="auto"?M=i.yAxisMin:M=Z.createMinFunction(p),i.yAxisMax!==void 0&&i.yAxisMax!=="auto"?$=i.yAxisMax:$=Z.createMaxFunction(p),D.push({position:"right",scale:!0,min:M,max:$,gridIndex:0,splitLine:{show:!s,lineStyle:{color:"#334155",opacity:.5}},axisLine:{show:!s,lineStyle:{color:"#334155"}},axisLabel:{show:!s,color:"#94a3b8",fontFamily:i.fontFamily||"sans-serif",formatter:S=>{if(i.yAxisLabelFormatter)return i.yAxisLabelFormatter(S);const L=i.yAxisDecimalPlaces!==void 0?i.yAxisDecimalPlaces:Z.autoDetectDecimals(o);return Z.formatValue(S,L)}}});let F=1,U=-1/0,tt=1/0;o&&o.length>0&&(U=Math.min(...o.map(S=>S.low)),tt=Math.max(...o.map(S=>S.high)));const W=new Map;e.forEach((S,L)=>{S.paneIndex===0&&!S.collapsed&&o&&o.length>0&&Object.entries(S.plots).forEach(([N,R])=>{const V=`${L}::${N}`,E=["background","barcolor","char"],T=R.options.style==="shape"&&(R.options.location==="abovebar"||R.options.location==="AboveBar"||R.options.location==="belowbar"||R.options.location==="BelowBar");if(E.includes(R.options.style)){W.has(V)||(W.set(V,F),F++);return}if(R.options.style==="shape"&&!T){W.has(V)||(W.set(V,F),F++);return}const B=[];if(R.data&&Object.values(R.data).forEach(O=>{typeof O=="number"&&!isNaN(O)&&isFinite(O)&&B.push(O)}),B.length>0){const O=Math.min(...B),j=Math.max(...B),st=j-O,at=tt-U,Q=O>=U*.5&&j<=tt*1.5,rt=st>at*.01;Q&&rt||W.has(V)||(W.set(V,F),F++)}})});const et=W.size>0?F-1:0,ot=new Set;W.forEach((S,L)=>{e.forEach(N=>{Object.entries(N.plots).forEach(([R,V])=>{`${N.id}::${R}`===L&&["background","barcolor","char"].includes(V.options.style)&&ot.add(S)})})});for(let S=0;S<et;S++){const L=S+1,N=ot.has(L);D.push({position:"left",scale:!N,min:N?0:Z.createMinFunction(p),max:N?1:Z.createMaxFunction(p),gridIndex:0,show:!1,splitLine:{show:!1},axisLine:{show:!1},axisLabel:{show:!1}})}const it=F;y.forEach((S,L)=>{D.push({position:"right",scale:!0,min:Z.createMinFunction(p),max:Z.createMaxFunction(p),gridIndex:L+1,splitLine:{show:!S.isCollapsed,lineStyle:{color:"#334155",opacity:.3}},axisLabel:{show:!S.isCollapsed,color:"#94a3b8",fontFamily:i.fontFamily||"sans-serif",fontSize:10,formatter:N=>{if(i.yAxisLabelFormatter)return i.yAxisLabelFormatter(N);const R=i.yAxisDecimalPlaces!==void 0?i.yAxisDecimalPlaces:Z.autoDetectDecimals(o);return Z.formatValue(N,R)}},axisLine:{show:!S.isCollapsed,lineStyle:{color:"#334155"}}})});const G=[];return l&&((i.dataZoom?.zoomOnTouch??!0)&&G.push({type:"inside",xAxisIndex:I,start:c,end:f,filterMode:"weakFilter"}),h==="top"?G.push({type:"slider",xAxisIndex:I,top:"1%",height:n+"%",start:c,end:f,borderColor:"#334155",textStyle:{color:"#cbd5e1"},brushSelect:!1,filterMode:"weakFilter"}):G.push({type:"slider",xAxisIndex:I,bottom:"1%",height:n+"%",start:c,end:f,borderColor:"#334155",textStyle:{color:"#cbd5e1"},brushSelect:!1,filterMode:"weakFilter"})),{grid:_,xAxis:P,yAxis:D,dataZoom:G,paneLayout:y,mainPaneHeight:v,mainPaneTop:m,pixelToPercent:d,paneBoundaries:b,overlayYAxisMap:W,separatePaneYAxisOffset:it}}static calculateMaximized(t,e,i){return{grid:[],xAxis:[],yAxis:[],dataZoom:[],paneLayout:[],mainPaneHeight:0,mainPaneTop:0,pixelToPercent:0,paneBoundaries:[]}}}class Lt{render(t){const{seriesName:e,xAxisIndex:i,yAxisIndex:s,dataArray:a,colorArray:o,plotOptions:u}=t,d="#2962ff";return{name:e,type:"custom",xAxisIndex:i,yAxisIndex:s,renderItem:(p,g)=>{const r=p.dataIndex;if(r===0)return;const l=g.value(1),h=g.value(2);if(l===null||isNaN(l)||h===null||isNaN(h))return;const n=g.coord([r-1,h]),c=g.coord([r,l]);return{type:"line",shape:{x1:n[0],y1:n[1],x2:c[0],y2:c[1]},style:{stroke:o[r]||u.color||d,lineWidth:u.linewidth||1},silent:!0}},data:a.map((p,g)=>[g,p,g>0?a[g-1]:null])}}}class $t{render(t){const{seriesName:e,xAxisIndex:i,yAxisIndex:s,dataArray:a,colorArray:o,plotOptions:u}=t,d="#2962ff";return{name:e,type:"custom",xAxisIndex:i,yAxisIndex:s,renderItem:(p,g)=>{const r=g.value(0),l=g.value(1);if(isNaN(l)||l===null)return;const h=g.coord([r,l]),n=g.size([1,0])[0];return{type:"line",shape:{x1:h[0]-n/2,y1:h[1],x2:h[0]+n/2,y2:h[1]},style:{stroke:o[p.dataIndex]||u.color||d,lineWidth:u.linewidth||1},silent:!0}},data:a.map((p,g)=>[g,p])}}}class St{render(t){const{seriesName:e,xAxisIndex:i,yAxisIndex:s,dataArray:a,colorArray:o,plotOptions:u}=t,d="#2962ff",p=u.histbase??0,g=u.style==="columns",r=u.linewidth??1,l=a.map((h,n)=>h==null||typeof h=="number"&&isNaN(h)?null:[n,h,o[n]||u.color||d]);return{name:e,type:"custom",xAxisIndex:i,yAxisIndex:s,renderItem:(h,n)=>{const c=n.value(0),f=n.value(1),m=n.value(2);if(f==null||isNaN(f))return null;const w=n.coord([c,p]),C=n.coord([c,f]),A=n.size([1,0])[0];let v;g?v=A*.6:v=Math.max(1,r);const y=w[0],b=w[1],_=C[1],I=Math.min(b,_),P=Math.abs(_-b);return{type:"rect",shape:{x:y-v/2,y:I,width:v,height:P||1},style:{fill:m}}},data:l.filter(h=>h!==null)}}}const mt=new Map;function Et(x,t="#00da3c",e="64px"){if(typeof document>"u")return"";const i=`${x}-${t}-${e}`;if(mt.has(i))return mt.get(i);const s=document.createElement("canvas"),a=s.getContext("2d");if(s.width=32,s.height=32,a){a.font="bold "+e+" Arial",a.fillStyle=t,a.textAlign="center",a.textBaseline="middle",a.fillText(x,16,16);const o=s.toDataURL("image/png");return mt.set(i,o),o}return""}class bt{render(t){const{seriesName:e,xAxisIndex:i,yAxisIndex:s,dataArray:a,colorArray:o,plotOptions:u}=t,d="#2962ff",p=u.style;if(p==="char")return{name:e,type:"scatter",xAxisIndex:i,yAxisIndex:s,symbolSize:0,data:a.map((r,l)=>({value:[l,r],itemStyle:{opacity:0}})),silent:!0};const g=a.map((r,l)=>{if(r===null)return null;const h=o[l]||u.color||d,n={value:[l,r],itemStyle:{color:h}};return p==="cross"?(n.symbol=`image://${Et("+",h,"24px")}`,n.symbolSize=16):(n.symbol="circle",n.symbolSize=6),n}).filter(r=>r!==null);return{name:e,type:"scatter",xAxisIndex:i,yAxisIndex:s,data:g}}}class _t{render(t){const{seriesName:e,xAxisIndex:i,yAxisIndex:s,dataArray:a,colorArray:o,optionsArray:u,plotOptions:d}=t,p="#2962ff",g=d.style==="candle",r=a.map((l,h)=>{if(l===null||!Array.isArray(l)||l.length!==4)return null;const[n,c,f,m]=l,w=u[h]||{},C=w.color||o[h]||d.color||p,A=w.wickcolor||d.wickcolor||C,v=w.bordercolor||d.bordercolor||A;return[h,n,m,f,c,C,A,v]}).filter(l=>l!==null);return{name:e,type:"custom",xAxisIndex:i,yAxisIndex:s,renderItem:(l,h)=>{const n=h.value(0),c=h.value(1),f=h.value(2),m=h.value(3),w=h.value(4),C=h.value(5),A=h.value(6),v=h.value(7);if(isNaN(c)||isNaN(f)||isNaN(m)||isNaN(w))return null;const y=h.coord([n,0])[0],b=h.coord([n,c])[1],_=h.coord([n,f])[1],I=h.coord([n,m])[1],P=h.coord([n,w])[1],k=h.size([1,0])[0]*.6;if(g){const D=Math.min(b,_),M=Math.max(b,_),$=Math.abs(_-b);return{type:"group",children:[{type:"line",shape:{x1:y,y1:P,x2:y,y2:D},style:{stroke:A,lineWidth:1}},{type:"line",shape:{x1:y,y1:M,x2:y,y2:I},style:{stroke:A,lineWidth:1}},{type:"rect",shape:{x:y-k/2,y:D,width:k,height:$||1},style:{fill:C,stroke:v,lineWidth:1}}]}}else{const D=k*.5;return{type:"group",children:[{type:"line",shape:{x1:y,y1:I,x2:y,y2:P},style:{stroke:C,lineWidth:1}},{type:"line",shape:{x1:y-D,y1:b,x2:y,y2:b},style:{stroke:C,lineWidth:1}},{type:"line",shape:{x1:y,y1:_,x2:y+D,y2:_},style:{stroke:C,lineWidth:1}}]}}},data:r}}}class dt{static getShapeSymbol(t){switch(t){case"arrowdown":case"shape_arrow_down":return"path://M12 24l-12-12h8v-12h8v12h8z";case"arrowup":case"shape_arrow_up":return"path://M12 0l12 12h-8v12h-8v-12h-8z";case"circle":case"shape_circle":return"circle";case"cross":case"shape_cross":return"path://M11 2h2v9h9v2h-9v9h-2v-9h-9v-2h9z";case"diamond":case"shape_diamond":return"diamond";case"flag":case"shape_flag":return"path://M6 2v20h2v-8h12l-2-6 2-6h-12z";case"labeldown":case"shape_label_down":return"path://M2 1h20a1 1 0 0 1 1 1v14a1 1 0 0 1-1 1h-8l-2 3-2-3h-8a1 1 0 0 1-1-1v-14a1 1 0 0 1 1-1z";case"labelleft":case"shape_label_left":return"path://M0 10l3-3v-5a1 1 0 0 1 1-1h18a1 1 0 0 1 1 1v16a1 1 0 0 1-1 1h-18a1 1 0 0 1-1-1v-5z";case"labelright":case"shape_label_right":return"path://M24 10l-3-3v-5a1 1 0 0 0-1-1h-18a1 1 0 0 0-1 1v16a1 1 0 0 0 1 1h18a1 1 0 0 0 1-1v-5z";case"labelup":case"shape_label_up":return"path://M12 1l2 3h8a1 1 0 0 1 1 1v14a1 1 0 0 1-1 1h-20a1 1 0 0 1-1-1v-14a1 1 0 0 1 1-1h8z";case"square":case"shape_square":return"rect";case"triangledown":case"shape_triangle_down":return"path://M12 21l-10-18h20z";case"triangleup":case"shape_triangle_up":return"triangle";case"xcross":case"shape_xcross":return"path://M19 6.41L17.59 5 12 10.59 6.41 5 5 6.41 10.59 12 5 17.59 6.41 19 12 13.41 17.59 19 19 17.59 13.41 12z";default:return"circle"}}static getShapeRotation(t){return 0}static getShapeSize(t,e,i){if(e!==void 0&&i!==void 0)return[e,i];let s;switch(t){case"tiny":s=8;break;case"small":s=12;break;case"normal":case"auto":s=16;break;case"large":s=24;break;case"huge":s=32;break;default:s=16}return e!==void 0?[e,e]:i!==void 0?[i,i]:s}static getLabelConfig(t,e){switch(e){case"abovebar":case"AboveBar":return{position:"top",distance:5};case"belowbar":case"BelowBar":return{position:"bottom",distance:5};case"top":case"Top":return{position:"bottom",distance:5};case"bottom":case"Bottom":return{position:"top",distance:5};case"absolute":case"Absolute":default:return t==="labelup"||t==="labeldown"||t==="shape_label_up"||t==="shape_label_down"?{position:"inside",distance:0}:{position:"top",distance:5}}}}class Nt{render(t){const{seriesName:e,xAxisIndex:i,yAxisIndex:s,dataArray:a,colorArray:o,optionsArray:u,plotOptions:d,candlestickData:p}=t,g="#2962ff",r=a.map((l,h)=>{const n=u[h]||{},c=d,f=n.location||c.location||"absolute";if(f!=="absolute"&&f!=="Absolute"&&!l||l==null)return null;const m=n.color||c.color||g,w=n.shape||c.shape||"circle",C=n.size||c.size||"normal",A=n.text||c.text,v=n.textcolor||c.textcolor||"white",y=n.width||c.width,b=n.height||c.height;let _=l,I=[0,0];f==="abovebar"||f==="AboveBar"||f==="ab"?(p&&p[h]&&(_=p[h].high),I=[0,"-150%"]):f==="belowbar"||f==="BelowBar"||f==="bl"?(p&&p[h]&&(_=p[h].low),I=[0,"150%"]):f==="top"||f==="Top"?(_=l,I=[0,0]):(f==="bottom"||f==="Bottom")&&(_=l,I=[0,0]);const P=dt.getShapeSymbol(w),k=dt.getShapeSize(C,y,b),D=dt.getShapeRotation(w);let M=k;w.includes("label")&&(Array.isArray(k)?M=[k[0]*2.5,k[1]*2.5]:M=k*2.5);const $=dt.getLabelConfig(w,f);return{value:[h,_],symbol:P,symbolSize:M,symbolRotate:D,symbolOffset:I,itemStyle:{color:m},label:{show:!!A,position:$.position,distance:$.distance,formatter:A,color:v,fontSize:10,fontWeight:"bold"}}}).filter(l=>l!==null);return{name:e,type:"scatter",xAxisIndex:i,yAxisIndex:s,data:r}}}class Ft{render(t){const{seriesName:e,xAxisIndex:i,yAxisIndex:s,dataArray:a,colorArray:o}=t;return{name:e,type:"custom",xAxisIndex:i,yAxisIndex:s,z:-10,renderItem:(u,d)=>{const p=d.value(0);if(isNaN(p))return;const g=d.coord([p,.5]),r=d.size([1,0])[0],l=u.coordSys,h=g[0]-r/2,n=o[u.dataIndex],c=d.value(1);if(!(!n||c===null||c===void 0||isNaN(c)))return{type:"rect",shape:{x:h,y:l.y,width:r,height:l.height},style:{fill:n,opacity:.3},silent:!0}},data:a.map((u,d)=>[d,u!=null&&!isNaN(u)?.5:null])}}}class ct{static parseColor(t){if(!t)return{color:"#888888",opacity:.2};const e=t.match(/rgba?\((\d+),\s*(\d+),\s*(\d+)(?:,\s*([\d.]+))?\)/);if(e){const s=e[1],a=e[2],o=e[3],u=e[4]?parseFloat(e[4]):1;return{color:`rgb(${s},${a},${o})`,opacity:u}}const i=t.match(/^#([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})$/);if(i){const s=parseInt(i[1],16),a=parseInt(i[2],16),o=parseInt(i[3],16),u=parseInt(i[4],16)/255;return{color:`rgb(${s},${a},${o})`,opacity:u}}return{color:t,opacity:.3}}static toRgba(t,e){const i=t.match(/rgb\((\d+),\s*(\d+),\s*(\d+)\)/);if(i)return`rgba(${i[1]},${i[2]},${i[3]},${e})`;const s=t.match(/^#([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})$/);if(s){const o=parseInt(s[1],16),u=parseInt(s[2],16),d=parseInt(s[3],16);return`rgba(${o},${u},${d},${e})`}const a=t.match(/^#([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})$/);if(a){const o=parseInt(a[1],16),u=parseInt(a[2],16),d=parseInt(a[3],16);return`rgba(${o},${u},${d},${e})`}return t}}class Tt{render(t){const{seriesName:e,xAxisIndex:i,yAxisIndex:s,plotOptions:a,plotDataArrays:o,indicatorId:u,plotName:d,optionsArray:p}=t,g=t.dataArray.length,r=a.plot1?`${u}::${a.plot1}`:null,l=a.plot2?`${u}::${a.plot2}`:null;if(!r||!l)return console.warn(`Fill plot "${d}" missing plot1 or plot2 reference`),null;const h=o?.get(r),n=o?.get(l);if(!h||!n)return console.warn(`Fill plot "${d}" references non-existent plots: ${a.plot1}, ${a.plot2}`),null;if(a.gradient===!0)return this.renderGradientFill(e,i,s,h,n,g,p,a);const{color:c,opacity:f}=ct.parseColor(a.color||"rgba(128, 128, 128, 0.2)"),m=[];for(let w=0;w<g;w++){const C=h[w],A=n[w],v=w>0?h[w-1]:null,y=w>0?n[w-1]:null;m.push([w,C,A,v,y])}return{name:e,type:"custom",xAxisIndex:i,yAxisIndex:s,z:1,renderItem:(w,C)=>{const A=w.dataIndex;if(A===0)return null;const v=C.value(1),y=C.value(2),b=C.value(3),_=C.value(4);if(v===null||y===null||b===null||_===null||isNaN(v)||isNaN(y)||isNaN(b)||isNaN(_))return null;const I=C.coord([A-1,b]),P=C.coord([A,v]),k=C.coord([A,y]),D=C.coord([A-1,_]);return{type:"polygon",shape:{points:[I,P,k,D]},style:{fill:c,opacity:f},silent:!0}},data:m}}renderGradientFill(t,e,i,s,a,o,u,d){const p=[];for(let r=0;r<o;r++){const l=u?.[r];if(l&&l.top_color!==void 0){const h=ct.parseColor(l.top_color),n=ct.parseColor(l.bottom_color);p[r]={topColor:h.color,topOpacity:h.opacity,bottomColor:n.color,bottomOpacity:n.opacity}}else p[r]={topColor:"rgba(128,128,128,0.2)",topOpacity:.2,bottomColor:"rgba(128,128,128,0.2)",bottomOpacity:.2}}const g=[];for(let r=0;r<o;r++){const l=s[r],h=a[r],n=r>0?s[r-1]:null,c=r>0?a[r-1]:null;g.push([r,l,h,n,c])}return{name:t,type:"custom",xAxisIndex:e,yAxisIndex:i,z:1,renderItem:(r,l)=>{const h=r.dataIndex;if(h===0)return null;const n=l.value(1),c=l.value(2),f=l.value(3),m=l.value(4);if(n===null||c===null||f===null||m===null||isNaN(n)||isNaN(c)||isNaN(f)||isNaN(m))return null;const w=l.coord([h-1,f]),C=l.coord([h,n]),A=l.coord([h,c]),v=l.coord([h-1,m]),y=p[h]||p[h-1];if(!y)return null;const b=ct.toRgba(y.topColor,y.topOpacity),_=ct.toRgba(y.bottomColor,y.bottomOpacity),I=n>=c;return{type:"polygon",shape:{points:[w,C,A,v]},style:{fill:{type:"linear",x:0,y:0,x2:0,y2:1,colorStops:[{offset:0,color:I?b:_},{offset:1,color:I?_:b}]}},silent:!0}},data:g}}}class Ot{render(t){const{seriesName:e,xAxisIndex:i,yAxisIndex:s,dataArray:a,candlestickData:o,dataIndexOffset:u}=t,d=u||0,p=[];for(let r=0;r<a.length;r++){const l=a[r];if(!l)continue;const h=Array.isArray(l)?l:[l];for(const n of h)n&&typeof n=="object"&&!n._deleted&&p.push(n)}const g=p.map(r=>{const l=r.text||"",h=r.color||"#2962ff",n=r.textcolor||"#ffffff",c=r.yloc||"price",f=r.style||"style_label_down",m=r.size||"normal",w=r.textalign||"align_center",C=r.tooltip||"",A=this.styleToShape(f),v=r.xloc==="bar_index"||r.xloc==="bi"?r.x+d:r.x;let y=r.y,b=[0,0];c==="abovebar"||c==="AboveBar"||c==="ab"?(o&&o[v]&&(y=o[v].high),b=[0,"-150%"]):(c==="belowbar"||c==="BelowBar"||c==="bl")&&(o&&o[v]&&(y=o[v].low),b=[0,"150%"]);const _=dt.getShapeSymbol(A),I=dt.getShapeSize(m),P=this.getSizePx(m);let k;const D=A==="labeldown"||A==="shape_label_down"||A==="labelup"||A==="shape_label_up"||A==="labelleft"||A==="labelright";let M=[0,0];if(D){const tt=l.length*P*.65,W=P*2.5,et=Math.max(W,tt+P*1.6),ot=P*2.8,it=3/24;if(A==="labelleft"||A==="labelright"){const G=et/(1-it);k=[G,ot];const S=typeof b[0]=="string"?0:b[0];A==="labelleft"?(b=[S+G*.42,b[1]],M=[G*it*.5,0]):(b=[S-G*.42,b[1]],M=[-G*it*.5,0])}else{const G=ot/(1-it);k=[et,G],A==="labeldown"?(b=[b[0],typeof b[1]=="string"?b[1]:b[1]-G*.42],M=[0,-G*it*.5]):(b=[b[0],typeof b[1]=="string"?b[1]:b[1]+G*.42],M=[0,G*it*.5])}}else A==="none"?k=0:Array.isArray(I)?k=[I[0]*1.5,I[1]*1.5]:k=I*1.5;const $=this.getLabelPosition(f,c),F=$==="inside"||$.startsWith("inside"),U={value:[v,y],symbol:_,symbolSize:k,symbolOffset:b,itemStyle:{color:h},label:{show:!!l,position:$,distance:F?0:5,offset:M,formatter:l,color:n,fontSize:P,fontWeight:"bold",align:F?"center":w==="align_left"||w==="left"?"left":w==="align_right"||w==="right"?"right":"center",verticalAlign:"middle",padding:[2,6]}};return C&&(U.tooltip={formatter:C}),U}).filter(r=>r!==null);return{name:e,type:"scatter",xAxisIndex:i,yAxisIndex:s,data:g,z:20}}styleToShape(t){switch(t.startsWith("style_")?t.substring(6):t){case"label_down":return"labeldown";case"label_up":return"labelup";case"label_left":return"labelleft";case"label_right":return"labelright";case"label_lower_left":return"labeldown";case"label_lower_right":return"labeldown";case"label_upper_left":return"labelup";case"label_upper_right":return"labelup";case"label_center":return"labeldown";case"circle":return"circle";case"square":return"square";case"diamond":return"diamond";case"flag":return"flag";case"arrowup":return"arrowup";case"arrowdown":return"arrowdown";case"cross":return"cross";case"xcross":return"xcross";case"triangleup":return"triangleup";case"triangledown":return"triangledown";case"text_outline":return"none";case"none":return"none";default:return"labeldown"}}getLabelPosition(t,e){switch(t.startsWith("style_")?t.substring(6):t){case"label_down":case"label_up":case"label_left":case"label_right":case"label_lower_left":case"label_lower_right":case"label_upper_left":case"label_upper_right":case"label_center":return"inside";case"text_outline":case"none":return e==="abovebar"||e==="AboveBar"||e==="ab"?"top":e==="belowbar"||e==="BelowBar"||e==="bl"?"bottom":"top";default:return e==="belowbar"||e==="BelowBar"||e==="bl"?"bottom":"top"}}getSizePx(t){switch(t){case"tiny":return 8;case"small":return 9;case"normal":case"auto":return 10;case"large":return 12;case"huge":return 14;default:return 10}}}class Zt{render(t){const{seriesName:e,xAxisIndex:i,yAxisIndex:s,dataArray:a,dataIndexOffset:o}=t,u=o||0,d="#2962ff",p=[];for(let l=0;l<a.length;l++){const h=a[l];if(!h)continue;const n=Array.isArray(h)?h:[h];for(const c of n)c&&typeof c=="object"&&!c._deleted&&p.push(c)}if(p.length===0)return{name:e,type:"custom",xAxisIndex:i,yAxisIndex:s,data:[],silent:!0};const g=(t.candlestickData?.length||0)+u,r=Math.max(0,g-1);return{name:e,type:"custom",xAxisIndex:i,yAxisIndex:s,renderItem:(l,h)=>{const n=[];for(const c of p){if(c._deleted)continue;const f=c.xloc==="bar_index"||c.xloc==="bi"?u:0;let m=h.coord([c.x1+f,c.y1]),w=h.coord([c.x2+f,c.y2]);const C=c.extend||"none";if(C!=="none"&&C!=="n"){const b=l.coordSys;[m,w]=this.extendLine(m,w,C,b.x,b.x+b.width,b.y,b.y+b.height)}const A=c.color||d,v=c.width||1;n.push({type:"line",shape:{x1:m[0],y1:m[1],x2:w[0],y2:w[1]},style:{fill:"none",stroke:A,lineWidth:v,lineDash:this.getDashPattern(c.style)}});const y=c.style||"style_solid";if(y==="style_arrow_left"||y==="style_arrow_both"){const b=this.arrowHead(w,m,v,A);b&&n.push(b)}if(y==="style_arrow_right"||y==="style_arrow_both"){const b=this.arrowHead(m,w,v,A);b&&n.push(b)}}return{type:"group",children:n}},data:[[0,r]],clip:!0,encode:{x:[0,1]},itemStyle:{color:"transparent",borderColor:"transparent"},z:15,silent:!0,emphasis:{disabled:!0}}}getDashPattern(t){switch(t){case"style_dotted":return[2,2];case"style_dashed":return[6,4];default:return}}extendLine(t,e,i,s,a,o,u){const d=e[0]-t[0],p=e[1]-t[1];if(d===0&&p===0)return[t,e];const g=(h,n)=>{let c=1/0;if(n[0]!==0){const f=n[0]>0?(a-h[0])/n[0]:(s-h[0])/n[0];c=Math.min(c,f)}if(n[1]!==0){const f=n[1]>0?(u-h[1])/n[1]:(o-h[1])/n[1];c=Math.min(c,f)}return isFinite(c)||(c=0),[h[0]+c*n[0],h[1]+c*n[1]]};let r=t,l=e;return(i==="right"||i==="r"||i==="both"||i==="b")&&(l=g(t,[d,p])),(i==="left"||i==="l"||i==="both"||i==="b")&&(r=g(e,[-d,-p])),[r,l]}arrowHead(t,e,i,s){const a=e[0]-t[0],o=e[1]-t[1],u=Math.sqrt(a*a+o*o);if(u<1)return null;const d=Math.max(8,i*4),p=a/u,g=o/u,r=e[0]-p*d,l=e[1]-g*d,h=-g*d*.4,n=p*d*.4;return{type:"polygon",shape:{points:[[e[0],e[1]],[r+h,l+n],[r-h,l-n]]},style:{fill:s}}}}class Ht{render(t){const{seriesName:e,xAxisIndex:i,yAxisIndex:s,dataArray:a,dataIndexOffset:o}=t,u=o||0,d=[];for(let r=0;r<a.length;r++){const l=a[r];if(!l)continue;const h=Array.isArray(l)?l:[l];for(const n of h){if(!n||typeof n!="object"||n._deleted)continue;const c=n.line1,f=n.line2;!c||!f||c._deleted||f._deleted||d.push(n)}}if(d.length===0)return{name:e,type:"custom",xAxisIndex:i,yAxisIndex:s,data:[],silent:!0};const p=(t.candlestickData?.length||0)+u,g=Math.max(0,p-1);return{name:e,type:"custom",xAxisIndex:i,yAxisIndex:s,renderItem:(r,l)=>{const h=[];for(const n of d){if(n._deleted)continue;const c=n.line1,f=n.line2;if(!c||!f||c._deleted||f._deleted)continue;const m=c.xloc==="bar_index"||c.xloc==="bi"?u:0,w=f.xloc==="bar_index"||f.xloc==="bi"?u:0;let C=l.coord([c.x1+m,c.y1]),A=l.coord([c.x2+m,c.y2]),v=l.coord([f.x1+w,f.y1]),y=l.coord([f.x2+w,f.y2]);const b=c.extend||"none",_=f.extend||"none";if(b!=="none"||_!=="none"){const k=r.coordSys,D=k.x,M=k.x+k.width,$=k.y,F=k.y+k.height;b!=="none"&&([C,A]=this.extendLine(C,A,b,D,M,$,F)),_!=="none"&&([v,y]=this.extendLine(v,y,_,D,M,$,F))}const{color:I,opacity:P}=ct.parseColor(n.color||"rgba(128, 128, 128, 0.2)");h.push({type:"polygon",shape:{points:[C,A,y,v]},style:{fill:I,opacity:P},silent:!0})}return{type:"group",children:h}},data:[[0,g]],clip:!0,encode:{x:[0,1]},z:10,silent:!0,emphasis:{disabled:!0}}}extendLine(t,e,i,s,a,o,u){const d=e[0]-t[0],p=e[1]-t[1];if(d===0&&p===0)return[t,e];const g=(h,n)=>{let c=1/0;if(n[0]!==0){const f=n[0]>0?(a-h[0])/n[0]:(s-h[0])/n[0];c=Math.min(c,f)}if(n[1]!==0){const f=n[1]>0?(u-h[1])/n[1]:(o-h[1])/n[1];c=Math.min(c,f)}return isFinite(c)||(c=0),[h[0]+c*n[0],h[1]+c*n[1]]};let r=t,l=e;return(i==="right"||i==="both")&&(l=g(t,[d,p])),(i==="left"||i==="both")&&(r=g(e,[-d,-p])),[r,l]}}class Wt{render(t){const{seriesName:e,xAxisIndex:i,yAxisIndex:s,dataArray:a,dataIndexOffset:o}=t,u=o||0,d=[];for(let r=0;r<a.length;r++){const l=a[r];if(!l)continue;const h=Array.isArray(l)?l:[l];for(const n of h)n&&typeof n=="object"&&!n._deleted&&n.points&&n.points.length>=2&&d.push(n)}if(d.length===0)return{name:e,type:"custom",xAxisIndex:i,yAxisIndex:s,data:[],silent:!0};const p=(t.candlestickData?.length||0)+u,g=Math.max(0,p-1);return{name:e,type:"custom",xAxisIndex:i,yAxisIndex:s,renderItem:(r,l)=>{const h=[];for(const n of d){if(n._deleted)continue;const c=n.points;if(!c||c.length<2)continue;const f=n.xloc==="bi"||n.xloc==="bar_index",m=f?u:0,w=[];for(const y of c){const b=f?(y.index??0)+m:y.time??0,_=y.price??0;w.push(l.coord([b,_]))}if(w.length<2)continue;const C=n.line_color||"#2962ff",A=n.line_width||1,v=this.getDashPattern(n.line_style);if(n.fill_color&&n.fill_color!==""&&n.fill_color!=="na"){const{color:y,opacity:b}=ct.parseColor(n.fill_color);if(n.curved){const _=this.buildCurvedPath(w,n.closed);h.push({type:"path",shape:{pathData:_+" Z"},style:{fill:y,opacity:b,stroke:"none"},silent:!0})}else h.push({type:"polygon",shape:{points:w},style:{fill:y,opacity:b,stroke:"none"},silent:!0})}if(n.curved){const y=this.buildCurvedPath(w,n.closed);h.push({type:"path",shape:{pathData:y},style:{fill:"none",stroke:C,lineWidth:A,lineDash:v},silent:!0})}else{const y=n.closed?[...w,w[0]]:w;h.push({type:"polyline",shape:{points:y},style:{fill:"none",stroke:C,lineWidth:A,lineDash:v},silent:!0})}}return{type:"group",children:h}},data:[[0,g]],clip:!0,encode:{x:[0,1]},itemStyle:{color:"transparent",borderColor:"transparent"},z:12,silent:!0,emphasis:{disabled:!0}}}buildCurvedPath(t,e){const i=t.length;if(i<2)return"";if(i===2)return`M ${t[0][0]} ${t[0][1]} L ${t[1][0]} ${t[1][1]}`;const s=.5;let a=`M ${t[0][0]} ${t[0][1]}`;const o=d=>e?t[(d%i+i)%i]:d<0?t[0]:d>=i?t[i-1]:t[d],u=e?i:i-1;for(let d=0;d<u;d++){const p=o(d-1),g=o(d),r=o(d+1),l=o(d+2),h=g[0]+(r[0]-p[0])*s/3,n=g[1]+(r[1]-p[1])*s/3,c=r[0]-(l[0]-g[0])*s/3,f=r[1]-(l[1]-g[1])*s/3;a+=` C ${h} ${n}, ${c} ${f}, ${r[0]} ${r[1]}`}return e&&(a+=" Z"),a}getDashPattern(t){switch(t){case"style_dotted":return[2,2];case"style_dashed":return[6,4];default:return}}}function vt(x){if(!x||typeof x!="string")return x;if(x.startsWith("#")){const t=x.slice(1);if(t.length===8){const e=parseInt(t.slice(0,2),16),i=parseInt(t.slice(2,4),16),s=parseInt(t.slice(4,6),16),a=parseInt(t.slice(6,8),16)/255;return`rgba(${e},${i},${s},${a.toFixed(3)})`}}return x}class Gt{render(t){const{seriesName:e,xAxisIndex:i,yAxisIndex:s,dataArray:a,dataIndexOffset:o}=t,u=o||0,d=[];for(let r=0;r<a.length;r++){const l=a[r];if(!l)continue;const h=Array.isArray(l)?l:[l];for(const n of h)n&&typeof n=="object"&&!n._deleted&&d.push(n)}if(d.length===0)return{name:e,type:"custom",xAxisIndex:i,yAxisIndex:s,data:[],silent:!0};const p=(t.candlestickData?.length||0)+u,g=Math.max(0,p-1);return{name:e,type:"custom",xAxisIndex:i,yAxisIndex:s,renderItem:(r,l)=>{const h=[];for(const n of d){if(n._deleted)continue;const c=n.xloc==="bar_index"||n.xloc==="bi"?u:0,f=l.coord([n.left+c,n.top]),m=l.coord([n.right+c,n.bottom]);let w=f[0],C=f[1],A=m[0]-f[0],v=m[1]-f[1];const y=n.extend||"none";if(y!=="none"&&y!=="n"){const k=r.coordSys;(y==="left"||y==="l"||y==="both"||y==="b")&&(w=k.x,A=y==="both"||y==="b"?k.width:m[0]-k.x),(y==="right"||y==="r"||y==="both"||y==="b")&&(y==="right"||y==="r")&&(A=k.x+k.width-f[0])}const b=vt(n.bgcolor)||"#2962ff";h.push({type:"rect",shape:{x:w,y:C,width:A,height:v},style:{fill:b,stroke:"none"}});const _=n.border_color,I=_==null||typeof _=="number"&&isNaN(_)||_==="na"||_==="NaN"?null:vt(_)||"#2962ff",P=n.border_width??1;if(P>0&&I&&h.push({type:"rect",shape:{x:w,y:C,width:A,height:v},style:{fill:"none",stroke:I,lineWidth:P,lineDash:this.getDashPattern(n.border_style)}}),n.text){const k=this.getTextX(w,A,n.text_halign),D=this.getTextY(C,v,n.text_valign);h.push({type:"text",style:{x:k,y:D,text:n.text,fill:vt(n.text_color)||"#000000",fontSize:this.getSizePixels(n.text_size),fontFamily:n.text_font_family==="monospace"?"monospace":"sans-serif",fontWeight:n.text_formatting==="format_bold"?"bold":"normal",fontStyle:n.text_formatting==="format_italic"?"italic":"normal",textAlign:this.mapHAlign(n.text_halign),textVerticalAlign:this.mapVAlign(n.text_valign)}})}}return{type:"group",children:h}},data:[[0,g]],clip:!0,encode:{x:[0,1]},itemStyle:{color:"transparent",borderColor:"transparent"},z:14,silent:!0,emphasis:{disabled:!0}}}getDashPattern(t){switch(t){case"style_dotted":return[2,2];case"style_dashed":return[6,4];default:return}}getSizePixels(t){if(typeof t=="number"&&t>0)return t;switch(t){case"auto":case"size.auto":return 12;case"tiny":case"size.tiny":return 8;case"small":case"size.small":return 10;case"normal":case"size.normal":return 14;case"large":case"size.large":return 20;case"huge":case"size.huge":return 36;default:return 12}}mapHAlign(t){switch(t){case"left":case"text.align_left":return"left";case"right":case"text.align_right":return"right";case"center":case"text.align_center":default:return"center"}}mapVAlign(t){switch(t){case"top":case"text.align_top":return"top";case"bottom":case"text.align_bottom":return"bottom";case"center":case"text.align_center":default:return"middle"}}getTextX(t,e,i){switch(i){case"left":case"text.align_left":return t+4;case"right":case"text.align_right":return t+e-4;case"center":case"text.align_center":default:return t+e/2}}getTextY(t,e,i){switch(i){case"top":case"text.align_top":return t+4;case"bottom":case"text.align_bottom":return t+e-4;case"center":case"text.align_center":default:return t+e/2}}}var Rt=Object.defineProperty,Bt=(x,t,e)=>t in x?Rt(x,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):x[t]=e,Yt=(x,t,e)=>(Bt(x,typeof t!="symbol"?t+"":t,e),e);const Y=class{static register(t,e){this.renderers.set(t,e)}static get(t){return this.renderers.get(t)||this.renderers.get("line")}};Yt(Y,"renderers",new Map),Y.register("line",new Lt),Y.register("step",new $t),Y.register("histogram",new St),Y.register("columns",new St),Y.register("circles",new bt),Y.register("cross",new bt),Y.register("char",new bt),Y.register("bar",new _t),Y.register("candle",new _t),Y.register("shape",new Nt),Y.register("background",new Ft),Y.register("fill",new Tt),Y.register("label",new Ot),Y.register("drawing_line",new Zt),Y.register("linefill",new Ht),Y.register("drawing_polyline",new Wt),Y.register("drawing_box",new Gt);let jt=Y;var qt=Object.defineProperty,Vt=(x,t,e)=>t in x?qt(x,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):x[t]=e,Xt=(x,t,e)=>(Vt(x,typeof t!="symbol"?t+"":t,e),e);const kt=class Ct{static buildCandlestickSeries(t,e,i){const s=e.upColor||"#00da3c",a=e.downColor||"#ec0000",o=t.map(d=>[d.open,d.close,d.low,d.high]);if(i&&i>o.length){const d=i-o.length;for(let p=0;p<d;p++)o.push(null)}let u;if(e.lastPriceLine?.visible!==!1&&t.length>0){const d=t[t.length-1],p=d.close,g=d.close>=d.open,r=e.lastPriceLine?.color||(g?s:a);let l=e.lastPriceLine?.lineStyle||"dashed";l.startsWith("linestyle_")&&(l=l.replace("linestyle_",""));const h=e.yAxisDecimalPlaces!==void 0?e.yAxisDecimalPlaces:Z.autoDetectDecimals(t);u={symbol:["none","none"],precision:h,data:[{yAxis:p,label:{show:!0,position:"end",formatter:n=>e.yAxisLabelFormatter?e.yAxisLabelFormatter(n.value):Z.formatValue(n.value,h),color:"#fff",backgroundColor:r,padding:[2,4],borderRadius:2,fontSize:11,fontWeight:"bold"},lineStyle:{color:r,type:l,width:1,opacity:.8}}],animation:!1,silent:!0}}return{type:"candlestick",name:e.title||"Market",data:o,itemStyle:{color:s,color0:a,borderColor:s,borderColor0:a},markLine:u,xAxisIndex:0,yAxisIndex:0,z:5}}static buildIndicatorSeries(t,e,i,s,a=0,o,u,d=1){const p=[],g=new Array(s).fill(null),r=new Map;return t.forEach((l,h)=>{l.collapsed||Object.keys(l.plots).sort((n,c)=>{const f=l.plots[n],m=l.plots[c],w=f.options.style==="fill",C=m.options.style==="fill";return w&&!C?1:!w&&C?-1:0}).forEach(n=>{const c=l.plots[n],f=`${h}::${n}`;let m=0,w=0,C=c.options.overlay;if(c.options.style==="fill"&&C===void 0){const I=c.options.plot1,P=c.options.plot2;if(I&&P){const k=l.plots[I],D=l.plots[P];k?.options?.overlay===!0&&D?.options?.overlay===!0&&(C=!0)}}if(l.paneIndex===0||C===!0)m=0,u&&u.has(f)?w=u.get(f):w=0;else{const I=i.findIndex(P=>P.index===l.paneIndex);I!==-1&&(m=I+1,w=d+I)}const A=new Array(s).fill(null),v=new Array(s).fill(null),y=new Array(s).fill(null),b=new Array(s).fill(null);if(c.data?.forEach(I=>{const P=e.get(I.time);if(P!==void 0){const k=I.options?.offset??c.options.offset??0,D=P+a+k;if(D>=0&&D<s){let M=I.value;const $=I.options?.color;v[D]=M;const F=I.options!=null&&"color"in I.options,U=$===null||$==="na"||$==="NaN"||typeof $=="number"&&isNaN($)||F&&$===void 0;U&&(M=null),A[D]=M,y[D]=U?null:$||c.options.color||Ct.DEFAULT_COLOR,b[D]=I.options||{}}}}),r.set(`${h}::${n}`,v),c.options?.style?.startsWith("style_")&&(c.options.style=c.options.style.replace("style_","")),c.options.style==="barcolor"){c.data?.forEach(I=>{const P=e.get(I.time);if(P!==void 0){const k=I.options?.offset??c.options.offset??0,D=P+a+k;if(D>=0&&D<s){const M=I.options?.color||c.options.color||Ct.DEFAULT_COLOR;!(M===null||M==="na"||M==="NaN"||typeof M=="number"&&isNaN(M))&&I.value!==null&&I.value!==void 0&&(g[D]=M)}}});return}if(c.options.style==="table")return;const _=jt.get(c.options.style).render({seriesName:f,xAxisIndex:m,yAxisIndex:w,dataArray:A,colorArray:y,optionsArray:b,plotOptions:c.options,candlestickData:o,plotDataArrays:r,indicatorId:h,plotName:n,dataIndexOffset:a});_&&p.push(_)})}),{series:p,barColors:g}}};Xt(kt,"DEFAULT_COLOR","#2962ff");let gt=kt;class Ut{static build(t,e,i,s=!1,a=null){const o=[],u=t.pixelToPercent,d=t.mainPaneTop;if(!a||a==="main"){const p=10*u;if(o.push({type:"text",left:"8.5%",top:d+p+"%",z:10,style:{text:e.title||"Market",fill:e.titleColor||"#fff",font:`bold 16px ${e.fontFamily||"sans-serif"}`,textVerticalAlign:"top"}}),e.watermark!==!1){const r=t.mainPaneTop+t.mainPaneHeight;o.push({type:"text",right:"11%",top:r-3+"%",z:10,style:{text:"QFChart",fill:e.fontColor||"#cbd5e1",font:"bold 16px sans-serif",opacity:.1},cursor:"pointer",onclick:()=>{window.open("https://quantforge.org","_blank")}})}const g=[];if(e.controls?.collapse&&g.push({type:"group",children:[{type:"rect",shape:{width:20,height:20,r:2},style:{fill:"#334155",stroke:"#475569",lineWidth:1},onclick:()=>i("main","collapse")},{type:"text",style:{text:s?"+":"\u2212",fill:"#cbd5e1",font:`bold 14px ${e.fontFamily}`,x:10,y:10,textAlign:"center",textVerticalAlign:"middle"},silent:!0}]}),e.controls?.maximize){const r=a==="main",l=e.controls?.collapse?25:0;g.push({type:"group",x:l,children:[{type:"rect",shape:{width:20,height:20,r:2},style:{fill:"#334155",stroke:"#475569",lineWidth:1},onclick:()=>i("main","maximize")},{type:"text",style:{text:r?"\u2750":"\u25A1",fill:"#cbd5e1",font:`14px ${e.fontFamily}`,x:10,y:10,textAlign:"center",textVerticalAlign:"middle"},silent:!0}]})}if(e.controls?.fullscreen){let r=0;e.controls?.collapse&&(r+=25),e.controls?.maximize&&(r+=25),g.push({type:"group",x:r,children:[{type:"rect",shape:{width:20,height:20,r:2},style:{fill:"#334155",stroke:"#475569",lineWidth:1},onclick:()=>i("main","fullscreen")},{type:"text",style:{text:"\u26F6",fill:"#cbd5e1",font:`14px ${e.fontFamily}`,x:10,y:10,textAlign:"center",textVerticalAlign:"middle"},silent:!0}]})}g.length>0&&o.push({type:"group",right:"10.5%",top:d+"%",children:g})}return t.paneLayout.forEach(p=>{if(a&&p.indicatorId!==a)return;o.push({type:"text",left:"8.5%",top:p.top+10*u+"%",z:10,style:{text:p.indicatorId||"",fill:p.titleColor||"#fff",font:`bold 12px ${e.fontFamily||"sans-serif"}`,textVerticalAlign:"top"}});const g=[];if(p.controls?.collapse&&g.push({type:"group",children:[{type:"rect",shape:{width:20,height:20,r:2},style:{fill:"#334155",stroke:"#475569",lineWidth:1},onclick:()=>p.indicatorId&&i(p.indicatorId,"collapse")},{type:"text",style:{text:p.isCollapsed?"+":"\u2212",fill:"#cbd5e1",font:`bold 14px ${e.fontFamily}`,x:10,y:10,textAlign:"center",textVerticalAlign:"middle"},silent:!0}]}),p.controls?.maximize){const r=a===p.indicatorId,l=p.controls?.collapse?25:0;g.push({type:"group",x:l,children:[{type:"rect",shape:{width:20,height:20,r:2},style:{fill:"#334155",stroke:"#475569",lineWidth:1},onclick:()=>p.indicatorId&&i(p.indicatorId,"maximize")},{type:"text",style:{text:r?"\u2750":"\u25A1",fill:"#cbd5e1",font:`14px ${e.fontFamily}`,x:10,y:10,textAlign:"center",textVerticalAlign:"middle"},silent:!0}]})}g.length>0&&o.push({type:"group",right:"10.5%",top:p.top+"%",children:g})}),o}}class Jt{static format(t,e){if(!t||t.length===0)return"";const i=e.title||"Market",s=e.upColor||"#00da3c",a=e.downColor||"#ec0000",o=e.fontFamily||"sans-serif",u=t[0].axisValue;let d=`<div style="font-weight: bold; margin-bottom: 5px; color: #cbd5e1; font-family: ${o};">${u}</div>`;const p=t.find(r=>r.seriesType==="candlestick"),g=t.filter(r=>r.seriesType!=="candlestick");if(p){const[r,l,h,n,c]=p.value,f=h>=l?s:a;d+=`
|
|
18
|
-
|
|
19
|
-
|
|
17
|
+
(function(ct,vt){typeof exports=="object"&&typeof module<"u"?vt(exports,require("echarts")):typeof define=="function"&&define.amd?define(["exports","echarts"],vt):(ct=typeof globalThis<"u"?globalThis:ct||self,vt(ct.QFChart={},ct.echarts))})(this,function(ct,vt){"use strict";function $t(b){var t=Object.create(null);return b&&Object.keys(b).forEach(function(e){if(e!=="default"){var i=Object.getOwnPropertyDescriptor(b,e);Object.defineProperty(t,e,i.get?i:{enumerable:!0,get:function(){return b[e]}})}}),t.default=b,Object.freeze(t)}var q=$t(vt),Lt=Object.defineProperty,Ft=(b,t,e)=>t in b?Lt(b,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):b[t]=e,yt=(b,t,e)=>(Ft(b,typeof t!="symbol"?t+"":t,e),e);class Tt{constructor(t,e,i,s={}){yt(this,"id"),yt(this,"plots"),yt(this,"paneIndex"),yt(this,"height"),yt(this,"collapsed"),yt(this,"titleColor"),yt(this,"controls"),this.id=t,this.plots=e,this.paneIndex=i,this.height=s.height,this.collapsed=s.collapsed||!1,this.titleColor=s.titleColor,this.controls=s.controls}toggleCollapse(){this.collapsed=!this.collapsed}isVisible(){return!this.collapsed}updateData(t){Object.keys(t).forEach(e=>{if(!this.plots[e])this.plots[e]=t[e];else{const i=this.plots[e],s=t[e];if(!i.data)return;s.options&&(i.options={...i.options,...s.options});const n=new Map;i.data?.forEach(a=>{n.set(a.time,a)}),s.data?.forEach(a=>{n.set(a.time,a)}),i.data=Array.from(n.values()).sort((a,d)=>a.time-d.time)}})}}class V{static createMinFunction(t){return e=>{const i=(e.max-e.min)*(t/100);return e.min-i}}static createMaxFunction(t){return e=>{const i=(e.max-e.min)*(t/100);return e.max+i}}static autoDetectDecimals(t){if(!t||t.length===0)return 2;const e=t[t.length-1].close;if(e===0||!isFinite(e)||isNaN(e))return 2;const i=Math.abs(e);if(i>=1)return 2;const s=Math.ceil(-Math.log10(i));return Math.min(s+4,10)}static formatValue(t,e){return typeof t=="number"?t.toFixed(e):String(t)}}class _t{static calculate(t,e,i,s=!1,n=null,a,d){let h=0;t>0&&(h=1/t*100);const p=i.yAxisPadding!==void 0?i.yAxisPadding:5,g=i.grid?.show===!0,c=i.grid?.lineColor??"#334155",r=i.grid?.lineOpacity??.5,l=i.grid?.borderColor??"#334155",o=i.grid?.borderShow===!0,f=i.layout?.left??"10%",u=i.layout?.right??"10%",y=Array.from(e.values()).map(E=>E.paneIndex).filter(E=>E>0).sort((E,T)=>E-T).filter((E,T,G)=>G.indexOf(E)===T),I=y.length>0,P=i.dataZoom?.visible??!0,A=i.dataZoom?.position??"top",k=i.dataZoom?.height??6,x=i.dataZoom?.start??0,v=i.dataZoom?.end??100;let C=8,S=92,_=-1;if(n)if(n==="main")_=0;else{const E=e.get(n);E&&(_=E.paneIndex)}if(_!==-1){const E=[],T=[],G=[],j=[],st=i.dataZoom?.start??50,Y=i.dataZoom?.end??100;(i.dataZoom?.zoomOnTouch??!0)&&j.push({type:"inside",xAxisIndex:"all",start:st,end:Y,filterMode:"weakFilter"});const ot=I?Math.max(...y):0,ht=[];for(let U=0;U<=ot;U++){const K=U===_;E.push({left:f,right:u,top:K?"5%":"0%",height:K?"90%":"0%",show:K,containLabel:!1}),T.push({type:"category",gridIndex:U,data:[],show:K,axisLabel:{show:K,color:"#94a3b8",fontFamily:i.fontFamily},axisLine:{show:K&&o,lineStyle:{color:l}},splitLine:{show:K&&g,lineStyle:{color:c,opacity:r}}});let pt,ut;if(U===0&&_===0?(pt=i.yAxisMin!==void 0&&i.yAxisMin!=="auto"?i.yAxisMin:V.createMinFunction(p),ut=i.yAxisMax!==void 0&&i.yAxisMax!=="auto"?i.yAxisMax:V.createMaxFunction(p)):(pt=V.createMinFunction(p),ut=V.createMaxFunction(p)),G.push({position:"right",gridIndex:U,show:K,scale:!0,min:pt,max:ut,axisLabel:{show:K,color:"#94a3b8",fontFamily:i.fontFamily,formatter:ft=>{if(i.yAxisLabelFormatter)return i.yAxisLabelFormatter(ft);const At=i.yAxisDecimalPlaces!==void 0?i.yAxisDecimalPlaces:V.autoDetectDecimals(a);return V.formatValue(ft,At)}},splitLine:{show:K&&g,lineStyle:{color:c,opacity:r}}}),U>0){const ft=Array.from(e.values()).find(At=>At.paneIndex===U);ft&&ht.push({index:U,height:K?90:0,top:K?5:0,isCollapsed:!1,indicatorId:ft.id,titleColor:ft.titleColor,controls:ft.controls})}}return{grid:E,xAxis:T,yAxis:G,dataZoom:j,paneLayout:ht,mainPaneHeight:_===0?90:0,mainPaneTop:_===0?5:0,pixelToPercent:h,overlayYAxisMap:new Map,separatePaneYAxisOffset:1}}P?A==="top"?(C=k+4,S=95):(S=100-k-2,C=8):(C=5,S=95);let M=5;t>0&&(M=20/t*100);let D=75,N=[];if(I){const E=y.map(Y=>{const ot=Array.from(e.values()).find(ht=>ht.paneIndex===Y);return{index:Y,requestedHeight:ot?.height,isCollapsed:ot?.collapsed??!1,indicatorId:ot?.id,titleColor:ot?.titleColor,controls:ot?.controls}}).map(Y=>({...Y,height:Y.isCollapsed?3:Y.requestedHeight!==void 0?Y.requestedHeight:15})),T=E.reduce((Y,ot)=>Y+ot.height,0),G=E.length*M,j=T+G;D=S-C-j,d!==void 0&&d>0&&!s?D=d:s?D=3:D<20&&(D=Math.max(D,10));let st=C+D+M;N=E.map(Y=>{const ot={index:Y.index,height:Y.height,top:st,isCollapsed:Y.isCollapsed,indicatorId:Y.indicatorId,titleColor:Y.titleColor,controls:Y.controls};return st+=Y.height+M,ot})}else D=S-C,s&&(D=3);const L=[];if(N.length>0){L.push({yPercent:C+D+M/2,aboveId:"main",belowId:N[0].indicatorId||""});for(let E=0;E<N.length-1;E++)L.push({yPercent:N[E].top+N[E].height+M/2,aboveId:N[E].indicatorId||"",belowId:N[E+1].indicatorId||""})}const m=[];m.push({left:f,right:u,top:C+"%",height:D+"%",containLabel:!1}),N.forEach(E=>{m.push({left:f,right:u,top:E.top+"%",height:E.height+"%",containLabel:!1})});const z=[0,...N.map((E,T)=>T+1)],w=[],H=N.length===0;w.push({type:"category",data:[],gridIndex:0,scale:!0,axisLine:{onZero:!1,show:!s&&o,lineStyle:{color:l}},splitLine:{show:!s&&g,lineStyle:{color:c,opacity:r}},axisLabel:{show:!s,color:"#94a3b8",fontFamily:i.fontFamily||"sans-serif",formatter:E=>{if(i.yAxisLabelFormatter)return i.yAxisLabelFormatter(E);const T=i.yAxisDecimalPlaces!==void 0?i.yAxisDecimalPlaces:V.autoDetectDecimals(a);return V.formatValue(E,T)}},axisTick:{show:!s},axisPointer:{label:{show:H,fontSize:11,backgroundColor:"#475569"}}}),N.forEach((E,T)=>{const G=T===N.length-1;w.push({type:"category",gridIndex:T+1,data:[],axisLabel:{show:!1},axisLine:{show:!E.isCollapsed&&o,lineStyle:{color:l}},axisTick:{show:!1},splitLine:{show:!1},axisPointer:{label:{show:G,fontSize:11,backgroundColor:"#475569"}}})});const F=[];let W,O;i.yAxisMin!==void 0&&i.yAxisMin!=="auto"?W=i.yAxisMin:W=V.createMinFunction(p),i.yAxisMax!==void 0&&i.yAxisMax!=="auto"?O=i.yAxisMax:O=V.createMaxFunction(p),F.push({position:"right",scale:!0,min:W,max:O,gridIndex:0,splitLine:{show:!s&&g,lineStyle:{color:c,opacity:r}},axisLine:{show:!s&&o,lineStyle:{color:l}},axisLabel:{show:!s,color:"#94a3b8",fontFamily:i.fontFamily||"sans-serif",formatter:E=>{if(i.yAxisLabelFormatter)return i.yAxisLabelFormatter(E);const T=i.yAxisDecimalPlaces!==void 0?i.yAxisDecimalPlaces:V.autoDetectDecimals(a);return V.formatValue(E,T)}}});let Z=1,X=-1/0,B=1/0;a&&a.length>0&&(X=Math.min(...a.map(E=>E.low)),B=Math.max(...a.map(E=>E.high)));const R=new Map;e.forEach((E,T)=>{E.paneIndex===0&&!E.collapsed&&a&&a.length>0&&Object.entries(E.plots).forEach(([G,j])=>{const st=`${T}::${G}`,Y=["background","barcolor","char"],ot=j.options.style==="shape"&&(j.options.location==="abovebar"||j.options.location==="AboveBar"||j.options.location==="belowbar"||j.options.location==="BelowBar");if(Y.includes(j.options.style)){R.has(st)||(R.set(st,Z),Z++);return}if(j.options.style==="shape"&&!ot){R.has(st)||(R.set(st,Z),Z++);return}const ht=[];if(j.data&&Object.values(j.data).forEach(U=>{typeof U=="number"&&!isNaN(U)&&isFinite(U)&&ht.push(U)}),ht.length>0){const U=Math.min(...ht),K=Math.max(...ht),pt=K-U,ut=B-X,ft=U>=X*.5&&K<=B*1.5,At=pt>ut*.01;ft&&At||R.has(st)||(R.set(st,Z),Z++)}})});const J=R.size>0?Z-1:0,it=new Set;R.forEach((E,T)=>{e.forEach(G=>{Object.entries(G.plots).forEach(([j,st])=>{`${G.id}::${j}`===T&&["background","barcolor","char"].includes(st.options.style)&&it.add(E)})})});for(let E=0;E<J;E++){const T=E+1,G=it.has(T);F.push({position:"left",scale:!G,min:G?0:V.createMinFunction(p),max:G?1:V.createMaxFunction(p),gridIndex:0,show:!1,splitLine:{show:!1},axisLine:{show:!1},axisLabel:{show:!1}})}const wt=Z;N.forEach((E,T)=>{F.push({position:"right",scale:!0,min:V.createMinFunction(p),max:V.createMaxFunction(p),gridIndex:T+1,splitLine:{show:!E.isCollapsed&&g,lineStyle:{color:c,opacity:r*.6}},axisLabel:{show:!E.isCollapsed,color:"#94a3b8",fontFamily:i.fontFamily||"sans-serif",fontSize:10,formatter:G=>{if(i.yAxisLabelFormatter)return i.yAxisLabelFormatter(G);const j=i.yAxisDecimalPlaces!==void 0?i.yAxisDecimalPlaces:V.autoDetectDecimals(a);return V.formatValue(G,j)}},axisLine:{show:!E.isCollapsed&&o,lineStyle:{color:l}}})});const dt=[];return P&&((i.dataZoom?.zoomOnTouch??!0)&&dt.push({type:"inside",xAxisIndex:z,start:x,end:v,filterMode:"weakFilter"}),A==="top"?dt.push({type:"slider",xAxisIndex:z,top:"1%",height:k+"%",start:x,end:v,borderColor:"#334155",textStyle:{color:"#cbd5e1"},brushSelect:!1,filterMode:"weakFilter"}):dt.push({type:"slider",xAxisIndex:z,bottom:"1%",height:k+"%",start:x,end:v,borderColor:"#334155",textStyle:{color:"#cbd5e1"},brushSelect:!1,filterMode:"weakFilter"})),{grid:m,xAxis:w,yAxis:F,dataZoom:dt,paneLayout:N,mainPaneHeight:D,mainPaneTop:C,pixelToPercent:h,paneBoundaries:L,overlayYAxisMap:R,separatePaneYAxisOffset:wt}}static calculateMaximized(t,e,i){return{grid:[],xAxis:[],yAxis:[],dataZoom:[],paneLayout:[],mainPaneHeight:0,mainPaneTop:0,pixelToPercent:0,paneBoundaries:[]}}}class Ot{render(t){const{seriesName:e,xAxisIndex:i,yAxisIndex:s,dataArray:n,colorArray:a,plotOptions:d}=t,h="#2962ff";return{name:e,type:"custom",xAxisIndex:i,yAxisIndex:s,renderItem:(p,g)=>{const c=p.dataIndex;if(c===0)return;const r=g.value(1),l=g.value(2);if(r===null||isNaN(r)||l===null||isNaN(l))return;const o=g.coord([c-1,l]),f=g.coord([c,r]);return{type:"line",shape:{x1:o[0],y1:o[1],x2:f[0],y2:f[1]},style:{stroke:a[c]||d.color||h,lineWidth:d.linewidth||1},silent:!0}},data:n.map((p,g)=>[g,p,g>0?n[g-1]:null])}}}class Zt{render(t){const{seriesName:e,xAxisIndex:i,yAxisIndex:s,dataArray:n,colorArray:a,plotOptions:d}=t,h="#2962ff";return{name:e,type:"custom",xAxisIndex:i,yAxisIndex:s,renderItem:(p,g)=>{const c=g.value(0),r=g.value(1);if(isNaN(r)||r===null)return;const l=g.coord([c,r]),o=g.size([1,0])[0];return{type:"line",shape:{x1:l[0]-o/2,y1:l[1],x2:l[0]+o/2,y2:l[1]},style:{stroke:a[p.dataIndex]||d.color||h,lineWidth:d.linewidth||1},silent:!0}},data:n.map((p,g)=>[g,p])}}}class Pt{render(t){const{seriesName:e,xAxisIndex:i,yAxisIndex:s,dataArray:n,colorArray:a,plotOptions:d}=t,h="#2962ff",p=d.histbase??0,g=d.style==="columns",c=d.linewidth??1,r=n.map((l,o)=>l==null||typeof l=="number"&&isNaN(l)?null:[o,l,a[o]||d.color||h]);return{name:e,type:"custom",xAxisIndex:i,yAxisIndex:s,renderItem:(l,o)=>{const f=o.value(0),u=o.value(1),y=o.value(2);if(u==null||isNaN(u))return null;const I=o.coord([f,p]),P=o.coord([f,u]),A=o.size([1,0])[0];let k;g?k=A*.6:k=Math.max(1,c);const x=I[0],v=I[1],C=P[1],S=Math.min(v,C),_=Math.abs(C-v);return{type:"rect",shape:{x:x-k/2,y:S,width:k,height:_||1},style:{fill:y}}},data:r.filter(l=>l!==null)}}}const St=new Map;function Ht(b,t="#00da3c",e="64px"){if(typeof document>"u")return"";const i=`${b}-${t}-${e}`;if(St.has(i))return St.get(i);const s=document.createElement("canvas"),n=s.getContext("2d");if(s.width=32,s.height=32,n){n.font="bold "+e+" Arial",n.fillStyle=t,n.textAlign="center",n.textBaseline="middle",n.fillText(b,16,16);const a=s.toDataURL("image/png");return St.set(i,a),a}return""}class kt{render(t){const{seriesName:e,xAxisIndex:i,yAxisIndex:s,dataArray:n,colorArray:a,plotOptions:d}=t,h="#2962ff",p=d.style;if(p==="char")return{name:e,type:"scatter",xAxisIndex:i,yAxisIndex:s,symbolSize:0,data:n.map((c,r)=>({value:[r,c],itemStyle:{opacity:0}})),silent:!0};const g=n.map((c,r)=>{if(c===null)return null;const l=a[r]||d.color||h,o={value:[r,c],itemStyle:{color:l}};return p==="cross"?(o.symbol=`image://${Ht("+",l,"24px")}`,o.symbolSize=16):(o.symbol="circle",o.symbolSize=6),o}).filter(c=>c!==null);return{name:e,type:"scatter",xAxisIndex:i,yAxisIndex:s,data:g}}}class zt{render(t){const{seriesName:e,xAxisIndex:i,yAxisIndex:s,dataArray:n,colorArray:a,optionsArray:d,plotOptions:h}=t,p="#2962ff",g=h.style==="candle",c=[],r=n.map((l,o)=>{if(l===null||!Array.isArray(l)||l.length!==4)return null;const[f,u,y,I]=l,P=d[o]||{},A=P.color||a[o]||h.color||p,k=P.wickcolor||h.wickcolor||A,x=P.bordercolor||h.bordercolor||k;return c[o]={color:A,wickColor:k,borderColor:x},[o,f,I,y,u]}).filter(l=>l!==null);return{name:e,type:"custom",xAxisIndex:i,yAxisIndex:s,renderItem:(l,o)=>{const f=o.value(0),u=o.value(1),y=o.value(2),I=o.value(3),P=o.value(4);if(isNaN(u)||isNaN(y)||isNaN(I)||isNaN(P))return null;const A=c[f]||{color:p,wickColor:p,borderColor:p},k=A.color,x=A.wickColor,v=A.borderColor,C=o.coord([f,0])[0],S=o.coord([f,u])[1],_=o.coord([f,y])[1],M=o.coord([f,I])[1],D=o.coord([f,P])[1],N=o.size([1,0])[0]*.6;if(g){const L=Math.min(S,_),m=Math.max(S,_),z=Math.abs(_-S);return{type:"group",children:[{type:"line",shape:{x1:C,y1:D,x2:C,y2:L},style:{stroke:x,lineWidth:1}},{type:"line",shape:{x1:C,y1:m,x2:C,y2:M},style:{stroke:x,lineWidth:1}},{type:"rect",shape:{x:C-N/2,y:L,width:N,height:z||1},style:{fill:k,stroke:v,lineWidth:1}}]}}else{const L=N*.5;return{type:"group",children:[{type:"line",shape:{x1:C,y1:M,x2:C,y2:D},style:{stroke:k,lineWidth:1}},{type:"line",shape:{x1:C-L,y1:S,x2:C,y2:S},style:{stroke:k,lineWidth:1}},{type:"line",shape:{x1:C,y1:_,x2:C+L,y2:_},style:{stroke:k,lineWidth:1}}]}}},data:r}}}class xt{static getShapeSymbol(t){switch(t){case"arrowdown":case"shape_arrow_down":return"path://M12 24l-12-12h8v-12h8v12h8z";case"arrowup":case"shape_arrow_up":return"path://M12 0l12 12h-8v12h-8v-12h-8z";case"circle":case"shape_circle":return"circle";case"cross":case"shape_cross":return"path://M11 2h2v9h9v2h-9v9h-2v-9h-9v-2h9z";case"diamond":case"shape_diamond":return"diamond";case"flag":case"shape_flag":return"path://M6 2v20h2v-8h12l-2-6 2-6h-12z";case"labeldown":case"shape_label_down":return"path://M2 1h20a1 1 0 0 1 1 1v14a1 1 0 0 1-1 1h-8l-2 3-2-3h-8a1 1 0 0 1-1-1v-14a1 1 0 0 1 1-1z";case"labelleft":case"shape_label_left":return"path://M0 10l3-3v-5a1 1 0 0 1 1-1h18a1 1 0 0 1 1 1v16a1 1 0 0 1-1 1h-18a1 1 0 0 1-1-1v-5z";case"labelright":case"shape_label_right":return"path://M24 10l-3-3v-5a1 1 0 0 0-1-1h-18a1 1 0 0 0-1 1v16a1 1 0 0 0 1 1h18a1 1 0 0 0 1-1v-5z";case"labelup":case"shape_label_up":return"path://M12 1l2 3h8a1 1 0 0 1 1 1v14a1 1 0 0 1-1 1h-20a1 1 0 0 1-1-1v-14a1 1 0 0 1 1-1h8z";case"square":case"shape_square":return"rect";case"triangledown":case"shape_triangle_down":return"path://M12 21l-10-18h20z";case"triangleup":case"shape_triangle_up":return"triangle";case"xcross":case"shape_xcross":return"path://M19 6.41L17.59 5 12 10.59 6.41 5 5 6.41 10.59 12 5 17.59 6.41 19 12 13.41 17.59 19 19 17.59 13.41 12z";default:return"circle"}}static getShapeRotation(t){return 0}static getShapeSize(t,e,i){if(e!==void 0&&i!==void 0)return[e,i];let s;switch(t){case"tiny":s=8;break;case"small":s=12;break;case"normal":case"auto":s=16;break;case"large":s=24;break;case"huge":s=32;break;default:s=16}return e!==void 0?[e,e]:i!==void 0?[i,i]:s}static getLabelConfig(t,e){switch(e){case"abovebar":case"AboveBar":return{position:"top",distance:5};case"belowbar":case"BelowBar":return{position:"bottom",distance:5};case"top":case"Top":return{position:"bottom",distance:5};case"bottom":case"Bottom":return{position:"top",distance:5};case"absolute":case"Absolute":default:return t==="labelup"||t==="labeldown"||t==="shape_label_up"||t==="shape_label_down"?{position:"inside",distance:0}:{position:"top",distance:5}}}}class Gt{render(t){const{seriesName:e,xAxisIndex:i,yAxisIndex:s,dataArray:n,colorArray:a,optionsArray:d,plotOptions:h,candlestickData:p}=t,g="#2962ff",c=n.map((r,l)=>{const o=d[l]||{},f=h,u=o.location||f.location||"absolute";if(u!=="absolute"&&u!=="Absolute"&&!r||r==null)return null;const y=o.color||f.color||g,I=o.shape||f.shape||"circle",P=o.size||f.size||"normal",A=o.text||f.text,k=o.textcolor||f.textcolor||"white",x=o.width||f.width,v=o.height||f.height;let C=r,S=[0,0];u==="abovebar"||u==="AboveBar"||u==="ab"?(p&&p[l]&&(C=p[l].high),S=[0,"-150%"]):u==="belowbar"||u==="BelowBar"||u==="bl"?(p&&p[l]&&(C=p[l].low),S=[0,"150%"]):u==="top"||u==="Top"?(C=r,S=[0,0]):(u==="bottom"||u==="Bottom")&&(C=r,S=[0,0]);const _=xt.getShapeSymbol(I),M=xt.getShapeSize(P,x,v),D=xt.getShapeRotation(I);let N=M;I.includes("label")&&(Array.isArray(M)?N=[M[0]*2.5,M[1]*2.5]:N=M*2.5);const L=xt.getLabelConfig(I,u);return{value:[l,C],symbol:_,symbolSize:N,symbolRotate:D,symbolOffset:S,itemStyle:{color:y},label:{show:!!A,position:L.position,distance:L.distance,formatter:A,color:k,fontSize:10,fontWeight:"bold"}}}).filter(r=>r!==null);return{name:e,type:"scatter",xAxisIndex:i,yAxisIndex:s,data:c}}}class rt{static parseColor(t){if(!t||typeof t!="string")return{color:"#888888",opacity:.2};const e=t.match(/rgba?\((\d+),\s*(\d+),\s*(\d+)(?:,\s*([\d.]+))?\)/);if(e){const s=e[1],n=e[2],a=e[3],d=e[4]?parseFloat(e[4]):1;return{color:`rgb(${s},${n},${a})`,opacity:d}}const i=t.match(/^#([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})$/);if(i){const s=parseInt(i[1],16),n=parseInt(i[2],16),a=parseInt(i[3],16),d=parseInt(i[4],16)/255;return{color:`rgb(${s},${n},${a})`,opacity:d}}return{color:t,opacity:.3}}static toRgba(t,e){const i=t.match(/rgb\((\d+),\s*(\d+),\s*(\d+)\)/);if(i)return`rgba(${i[1]},${i[2]},${i[3]},${e})`;const s=t.match(/^#([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})$/);if(s){const a=parseInt(s[1],16),d=parseInt(s[2],16),h=parseInt(s[3],16);return`rgba(${a},${d},${h},${e})`}const n=t.match(/^#([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})$/);if(n){const a=parseInt(n[1],16),d=parseInt(n[2],16),h=parseInt(n[3],16);return`rgba(${a},${d},${h},${e})`}return t}}class Wt{render(t){const{seriesName:e,xAxisIndex:i,yAxisIndex:s,dataArray:n,colorArray:a}=t,d=[];for(let h=0;h<a.length;h++)d[h]=a[h]?rt.parseColor(a[h]):{color:"",opacity:0};return{name:e,type:"custom",xAxisIndex:i,yAxisIndex:s,z:-10,renderItem:(h,p)=>{const g=p.value(0);if(isNaN(g))return;const c=p.coord([g,.5]),r=p.size([1,0])[0],l=h.coordSys,o=c[0]-r/2,f=a[h.dataIndex],u=p.value(1);if(!f||u===null||u===void 0||isNaN(u))return;const y=d[h.dataIndex];if(!(!y||y.opacity<=0))return{type:"rect",shape:{x:o,y:l.y,width:r,height:l.height},style:{fill:y.color,opacity:y.opacity},silent:!0}},data:n.map((h,p)=>[p,h!=null&&!isNaN(h)?.5:null])}}}class Et{render(t){const{seriesName:e,xAxisIndex:i,yAxisIndex:s,plotOptions:n,plotDataArrays:a,indicatorId:d,plotName:h,optionsArray:p}=t,g=t.dataArray.length,c=n.plot1?`${d}::${n.plot1}`:null,r=n.plot2?`${d}::${n.plot2}`:null;if(!c||!r)return console.warn(`Fill plot "${h}" missing plot1 or plot2 reference`),null;const l=a?.get(c),o=a?.get(r);if(!l||!o)return console.warn(`Fill plot "${h}" references non-existent plots: ${n.plot1}, ${n.plot2}`),null;if(n.gradient===!0)return this.renderGradientFill(e,i,s,l,o,g,p,n);const{color:f,opacity:u}=rt.parseColor(n.color||"rgba(128, 128, 128, 0.2)"),y=p?.some(A=>A&&A.color!==void 0);let I=null;if(y){I=[];for(let A=0;A<g;A++){const k=p?.[A];k&&k.color!==void 0?I[A]=rt.parseColor(k.color):I[A]={color:f,opacity:u}}}const P=[];for(let A=0;A<g;A++){const k=l[A],x=o[A],v=A>0?l[A-1]:null,C=A>0?o[A-1]:null;P.push([A,k,x,v,C])}return{name:e,type:"custom",xAxisIndex:i,yAxisIndex:s,z:1,clip:!0,encode:{x:0},animation:!1,renderItem:(A,k)=>{const x=A.dataIndex;if(x===0)return null;const v=k.value(1),C=k.value(2),S=k.value(3),_=k.value(4);if(v===null||C===null||S===null||_===null||isNaN(v)||isNaN(C)||isNaN(S)||isNaN(_))return null;const M=I?I[x]:null,D=M?M.opacity:u;if(D<.01)return null;const N=k.coord([x-1,S]),L=k.coord([x,v]),m=k.coord([x,C]),z=k.coord([x-1,_]);return{type:"polygon",shape:{points:[N,L,m,z]},style:{fill:M?M.color:f,opacity:D},silent:!0}},data:P,silent:!0}}renderBatched(t,e,i,s,n){const a=Array.from({length:s},(d,h)=>[h]);return{name:t,type:"custom",xAxisIndex:e,yAxisIndex:i,z:1,clip:!0,encode:{x:0},animation:!1,renderItem:(d,h)=>{const p=d.dataIndex;if(p===0)return null;const g=[];for(let c=0;c<n.length;c++){const r=n[c],l=r.plot1Data[p],o=r.plot2Data[p],f=r.plot1Data[p-1],u=r.plot2Data[p-1];if(l==null||o==null||f==null||u==null||isNaN(l)||isNaN(o)||isNaN(f)||isNaN(u))continue;const y=r.barColors[p];if(!y||y.opacity<.01)continue;const I=h.coord([p-1,f]),P=h.coord([p,l]),A=h.coord([p,o]),k=h.coord([p-1,u]);g.push({type:"polygon",shape:{points:[I,P,A,k]},style:{fill:y.color,opacity:y.opacity},silent:!0})}return g.length>0?{type:"group",children:g,silent:!0}:null},data:a,silent:!0}}renderGradientFill(t,e,i,s,n,a,d,h){const p=[];for(let c=0;c<a;c++){const r=d?.[c];if(r&&r.top_color!==void 0){const l=rt.parseColor(r.top_color),o=rt.parseColor(r.bottom_color);p[c]={topColor:l.color,topOpacity:l.opacity,bottomColor:o.color,bottomOpacity:o.opacity}}else p[c]={topColor:"rgba(128,128,128,0.2)",topOpacity:.2,bottomColor:"rgba(128,128,128,0.2)",bottomOpacity:.2}}const g=[];for(let c=0;c<a;c++){const r=s[c],l=n[c],o=c>0?s[c-1]:null,f=c>0?n[c-1]:null;g.push([c,r,l,o,f])}return{name:t,type:"custom",xAxisIndex:e,yAxisIndex:i,z:1,clip:!0,encode:{x:0},animation:!1,renderItem:(c,r)=>{const l=c.dataIndex;if(l===0)return null;const o=r.value(1),f=r.value(2),u=r.value(3),y=r.value(4);if(o===null||f===null||u===null||y===null||isNaN(o)||isNaN(f)||isNaN(u)||isNaN(y))return null;const I=r.coord([l-1,u]),P=r.coord([l,o]),A=r.coord([l,f]),k=r.coord([l-1,y]),x=p[l]||p[l-1];if(!x||x.topOpacity<.01&&x.bottomOpacity<.01)return null;const v=rt.toRgba(x.topColor,x.topOpacity),C=rt.toRgba(x.bottomColor,x.bottomOpacity),S=o>=f;return{type:"polygon",shape:{points:[I,P,A,k]},style:{fill:{type:"linear",x:0,y:0,x2:0,y2:1,colorStops:[{offset:0,color:S?v:C},{offset:1,color:S?C:v}]}},silent:!0}},data:g,silent:!0}}}class Bt{render(t){const{seriesName:e,xAxisIndex:i,yAxisIndex:s,dataArray:n,candlestickData:a,dataIndexOffset:d}=t,h=d||0,p=[];for(let c=0;c<n.length;c++){const r=n[c];if(!r)continue;const l=Array.isArray(r)?r:[r];for(const o of l)o&&typeof o=="object"&&!o._deleted&&p.push(o)}const g=p.map(c=>{const r=F=>typeof F=="function"?F():F,l=r(c.text)||"",o=r(c.color),f=o!=null&&o!==""?o:"transparent",u=r(c.textcolor)||"#ffffff",y=r(c.yloc)||"price",I=r(c.style)||"style_label_down",P=r(c.size)||"normal",A=r(c.textalign)||"align_center",k=r(c.tooltip)||"",x=this.styleToShape(I),v=c.xloc==="bar_index"||c.xloc==="bi"?c.x+h:c.x;let C=c.y,S=[0,0];y==="abovebar"||y==="AboveBar"||y==="ab"?(a&&a[v]&&(C=a[v].high),S=[0,"-150%"]):(y==="belowbar"||y==="BelowBar"||y==="bl")&&(a&&a[v]&&(C=a[v].low),S=[0,"150%"]);const _=xt.getShapeSymbol(x),M=xt.getShapeSize(P),D=this.getSizePx(P);let N;const L=x==="labeldown"||x==="shape_label_down"||x==="labelup"||x==="shape_label_up"||x==="labelleft"||x==="labelright";let m=[0,0];if(L){const F=l.length*D*.65,W=D*2.5,O=Math.max(W,F+D*1.6),Z=D*2.8,X=3/24;if(x==="labelleft"||x==="labelright"){const B=O/(1-X);N=[B,Z];const R=typeof S[0]=="string"?0:S[0];x==="labelleft"?(S=[R+B*.42,S[1]],m=[B*X*.5,0]):(S=[R-B*.42,S[1]],m=[-B*X*.5,0])}else{const B=Z/(1-X);N=[O,B],x==="labeldown"?(S=[S[0],typeof S[1]=="string"?S[1]:S[1]-B*.42],m=[0,-B*X*.5]):(S=[S[0],typeof S[1]=="string"?S[1]:S[1]+B*.42],m=[0,B*X*.5])}}else x==="none"?N=0:Array.isArray(M)?N=[M[0]*1.5,M[1]*1.5]:N=M*1.5;const z=this.getLabelPosition(I,y),w=z==="inside"||z.startsWith("inside"),H={value:[v,C],symbol:_,symbolSize:N,symbolOffset:S,itemStyle:{color:f},label:{show:!!l,position:z,distance:w?0:5,offset:m,formatter:l,color:u,fontSize:D,fontWeight:"bold",align:w?"center":A==="align_left"||A==="left"?"left":A==="align_right"||A==="right"?"right":"center",verticalAlign:"middle",padding:[2,6]}};return k?(H._tooltipText=k,H.emphasis={scale:!1,itemStyle:{color:f},label:{show:H.label.show,color:u,fontSize:D,fontWeight:"bold"}}):H.emphasis={disabled:!0},H}).filter(c=>c!==null);return{name:e,type:"scatter",xAxisIndex:i,yAxisIndex:s,data:g,z:20,animation:!1,clip:!1}}styleToShape(t){switch(t.startsWith("style_")?t.substring(6):t){case"label_down":return"labeldown";case"label_up":return"labelup";case"label_left":return"labelleft";case"label_right":return"labelright";case"label_lower_left":return"labeldown";case"label_lower_right":return"labeldown";case"label_upper_left":return"labelup";case"label_upper_right":return"labelup";case"label_center":return"labeldown";case"circle":return"circle";case"square":return"square";case"diamond":return"diamond";case"flag":return"flag";case"arrowup":return"arrowup";case"arrowdown":return"arrowdown";case"cross":return"cross";case"xcross":return"xcross";case"triangleup":return"triangleup";case"triangledown":return"triangledown";case"text_outline":return"none";case"none":return"none";default:return"labeldown"}}getLabelPosition(t,e){switch(t.startsWith("style_")?t.substring(6):t){case"label_down":case"label_up":case"label_left":case"label_right":case"label_lower_left":case"label_lower_right":case"label_upper_left":case"label_upper_right":case"label_center":return"inside";case"text_outline":case"none":return e==="abovebar"||e==="AboveBar"||e==="ab"?"top":e==="belowbar"||e==="BelowBar"||e==="bl"?"bottom":"top";default:return e==="belowbar"||e==="BelowBar"||e==="bl"?"bottom":"top"}}getSizePx(t){switch(t){case"tiny":return 8;case"small":return 9;case"normal":case"auto":return 10;case"large":return 12;case"huge":return 14;default:return 10}}}class Rt{render(t){const{seriesName:e,xAxisIndex:i,yAxisIndex:s,dataArray:n,dataIndexOffset:a}=t,d=a||0,h="#2962ff",p=[];for(let r=0;r<n.length;r++){const l=n[r];if(!l)continue;const o=Array.isArray(l)?l:[l];for(const f of o)f&&typeof f=="object"&&!f._deleted&&p.push(f)}if(p.length===0)return{name:e,type:"custom",xAxisIndex:i,yAxisIndex:s,data:[],silent:!0};const g=(t.candlestickData?.length||0)+d,c=Math.max(0,g-1);return{name:e,type:"custom",xAxisIndex:i,yAxisIndex:s,renderItem:(r,l)=>{const o=[];for(const f of p){if(f._deleted)continue;const u=f.xloc==="bar_index"||f.xloc==="bi"?d:0;let y=l.coord([f.x1+u,f.y1]),I=l.coord([f.x2+u,f.y2]);const P=f.extend||"none";if(P!=="none"&&P!=="n"){const v=r.coordSys;[y,I]=this.extendLine(y,I,P,v.x,v.x+v.width,v.y,v.y+v.height)}const A=f.color||h,k=f.width||1;o.push({type:"line",shape:{x1:y[0],y1:y[1],x2:I[0],y2:I[1]},style:{fill:"none",stroke:A,lineWidth:k,lineDash:this.getDashPattern(f.style)}});const x=f.style||"style_solid";if(x==="style_arrow_left"||x==="style_arrow_both"){const v=this.arrowHead(I,y,k,A);v&&o.push(v)}if(x==="style_arrow_right"||x==="style_arrow_both"){const v=this.arrowHead(y,I,k,A);v&&o.push(v)}}return{type:"group",children:o}},data:[[0,c]],clip:!0,encode:{x:[0,1]},itemStyle:{color:"transparent",borderColor:"transparent"},z:15,silent:!0,emphasis:{disabled:!0}}}getDashPattern(t){switch(t){case"style_dotted":return[2,2];case"style_dashed":return[6,4];default:return}}extendLine(t,e,i,s,n,a,d){const h=e[0]-t[0],p=e[1]-t[1];if(h===0&&p===0)return[t,e];const g=(l,o)=>{let f=1/0;if(o[0]!==0){const u=o[0]>0?(n-l[0])/o[0]:(s-l[0])/o[0];f=Math.min(f,u)}if(o[1]!==0){const u=o[1]>0?(d-l[1])/o[1]:(a-l[1])/o[1];f=Math.min(f,u)}return isFinite(f)||(f=0),[l[0]+f*o[0],l[1]+f*o[1]]};let c=t,r=e;return(i==="right"||i==="r"||i==="both"||i==="b")&&(r=g(t,[h,p])),(i==="left"||i==="l"||i==="both"||i==="b")&&(c=g(e,[-h,-p])),[c,r]}arrowHead(t,e,i,s){const n=e[0]-t[0],a=e[1]-t[1],d=Math.sqrt(n*n+a*a);if(d<1)return null;const h=Math.max(8,i*4),p=n/d,g=a/d,c=e[0]-p*h,r=e[1]-g*h,l=-g*h*.4,o=p*h*.4;return{type:"polygon",shape:{points:[[e[0],e[1]],[c+l,r+o],[c-l,r-o]]},style:{fill:s}}}}class Yt{render(t){const{seriesName:e,xAxisIndex:i,yAxisIndex:s,dataArray:n,dataIndexOffset:a}=t,d=a||0,h=[];for(let c=0;c<n.length;c++){const r=n[c];if(!r)continue;const l=Array.isArray(r)?r:[r];for(const o of l){if(!o||typeof o!="object"||o._deleted)continue;const f=o.line1,u=o.line2;!f||!u||f._deleted||u._deleted||h.push(o)}}if(h.length===0)return{name:e,type:"custom",xAxisIndex:i,yAxisIndex:s,data:[],silent:!0};const p=(t.candlestickData?.length||0)+d,g=Math.max(0,p-1);return{name:e,type:"custom",xAxisIndex:i,yAxisIndex:s,renderItem:(c,r)=>{const l=[];for(const o of h){if(o._deleted)continue;const f=o.line1,u=o.line2;if(!f||!u||f._deleted||u._deleted)continue;const y=f.xloc==="bar_index"||f.xloc==="bi"?d:0,I=u.xloc==="bar_index"||u.xloc==="bi"?d:0;let P=r.coord([f.x1+y,f.y1]),A=r.coord([f.x2+y,f.y2]),k=r.coord([u.x1+I,u.y1]),x=r.coord([u.x2+I,u.y2]);const v=f.extend||"none",C=u.extend||"none";if(v!=="none"||C!=="none"){const M=c.coordSys,D=M.x,N=M.x+M.width,L=M.y,m=M.y+M.height;v!=="none"&&([P,A]=this.extendLine(P,A,v,D,N,L,m)),C!=="none"&&([k,x]=this.extendLine(k,x,C,D,N,L,m))}const{color:S,opacity:_}=rt.parseColor(o.color||"rgba(128, 128, 128, 0.2)");l.push({type:"polygon",shape:{points:[P,A,x,k]},style:{fill:S,opacity:_},silent:!0})}return{type:"group",children:l}},data:[[0,g]],clip:!0,encode:{x:[0,1]},z:10,silent:!0,emphasis:{disabled:!0}}}extendLine(t,e,i,s,n,a,d){const h=e[0]-t[0],p=e[1]-t[1];if(h===0&&p===0)return[t,e];const g=(l,o)=>{let f=1/0;if(o[0]!==0){const u=o[0]>0?(n-l[0])/o[0]:(s-l[0])/o[0];f=Math.min(f,u)}if(o[1]!==0){const u=o[1]>0?(d-l[1])/o[1]:(a-l[1])/o[1];f=Math.min(f,u)}return isFinite(f)||(f=0),[l[0]+f*o[0],l[1]+f*o[1]]};let c=t,r=e;return(i==="right"||i==="both")&&(r=g(t,[h,p])),(i==="left"||i==="both")&&(c=g(e,[-h,-p])),[c,r]}}class jt{render(t){const{seriesName:e,xAxisIndex:i,yAxisIndex:s,dataArray:n,dataIndexOffset:a}=t,d=a||0,h=[];for(let c=0;c<n.length;c++){const r=n[c];if(!r)continue;const l=Array.isArray(r)?r:[r];for(const o of l)o&&typeof o=="object"&&!o._deleted&&o.points&&o.points.length>=2&&h.push(o)}if(h.length===0)return{name:e,type:"custom",xAxisIndex:i,yAxisIndex:s,data:[],silent:!0};const p=(t.candlestickData?.length||0)+d,g=Math.max(0,p-1);return{name:e,type:"custom",xAxisIndex:i,yAxisIndex:s,renderItem:(c,r)=>{const l=[];for(const o of h){if(o._deleted)continue;const f=o.points;if(!f||f.length<2)continue;const u=o.xloc==="bi"||o.xloc==="bar_index",y=u?d:0,I=[];for(const v of f){const C=u?(v.index??0)+y:v.time??0,S=v.price??0;I.push(r.coord([C,S]))}if(I.length<2)continue;const P=o.line_color,A=P==null||typeof P=="number"&&isNaN(P)||P==="na"||P==="NaN"?null:P||"#2962ff",k=o.line_width||1,x=this.getDashPattern(o.line_style);if(o.fill_color&&o.fill_color!==""&&o.fill_color!=="na"){const{color:v,opacity:C}=rt.parseColor(o.fill_color);if(o.curved){const S=this.buildCurvedPath(I,o.closed);l.push({type:"path",shape:{pathData:S+" Z"},style:{fill:v,opacity:C,stroke:"none"},silent:!0})}else l.push({type:"polygon",shape:{points:I},style:{fill:v,opacity:C,stroke:"none"},silent:!0})}if(A&&k>0)if(o.curved){const v=this.buildCurvedPath(I,o.closed);l.push({type:"path",shape:{pathData:v},style:{fill:"none",stroke:A,lineWidth:k,lineDash:x},silent:!0})}else{const v=o.closed?[...I,I[0]]:I;l.push({type:"polyline",shape:{points:v},style:{fill:"none",stroke:A,lineWidth:k,lineDash:x},silent:!0})}}return{type:"group",children:l}},data:[[0,g]],clip:!0,encode:{x:[0,1]},itemStyle:{color:"transparent",borderColor:"transparent"},z:15,silent:!0,emphasis:{disabled:!0}}}buildCurvedPath(t,e){const i=t.length;if(i<2)return"";if(i===2)return`M ${t[0][0]} ${t[0][1]} L ${t[1][0]} ${t[1][1]}`;const s=.5;let n=`M ${t[0][0]} ${t[0][1]}`;const a=h=>e?t[(h%i+i)%i]:h<0?t[0]:h>=i?t[i-1]:t[h],d=e?i:i-1;for(let h=0;h<d;h++){const p=a(h-1),g=a(h),c=a(h+1),r=a(h+2),l=g[0]+(c[0]-p[0])*s/3,o=g[1]+(c[1]-p[1])*s/3,f=c[0]-(r[0]-g[0])*s/3,u=c[1]-(r[1]-g[1])*s/3;n+=` C ${l} ${o}, ${f} ${u}, ${c[0]} ${c[1]}`}return e&&(n+=" Z"),n}getDashPattern(t){switch(t){case"style_dotted":return[2,2];case"style_dashed":return[6,4];default:return}}}function Mt(b){if(!b||typeof b!="string")return b;if(b.startsWith("#")){const t=b.slice(1);if(t.length===8){const e=parseInt(t.slice(0,2),16),i=parseInt(t.slice(2,4),16),s=parseInt(t.slice(4,6),16),n=parseInt(t.slice(6,8),16)/255;return`rgba(${e},${i},${s},${n.toFixed(3)})`}}return b}function Vt(b){if(!b||typeof b!="string")return null;if(b.startsWith("#")){const e=b.slice(1);if(e.length>=6){const i=parseInt(e.slice(0,2),16),s=parseInt(e.slice(2,4),16),n=parseInt(e.slice(4,6),16);if(!isNaN(i)&&!isNaN(s)&&!isNaN(n))return{r:i,g:s,b:n}}if(e.length===3){const i=parseInt(e[0]+e[0],16),s=parseInt(e[1]+e[1],16),n=parseInt(e[2]+e[2],16);if(!isNaN(i)&&!isNaN(s)&&!isNaN(n))return{r:i,g:s,b:n}}return null}const t=b.match(/rgba?\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)/);return t?{r:+t[1],g:+t[2],b:+t[3]}:null}function Xt(b,t,e){return(.299*b+.587*t+.114*e)/255}class qt{render(t){const{seriesName:e,xAxisIndex:i,yAxisIndex:s,dataArray:n,dataIndexOffset:a}=t,d=a||0,h=[];for(let c=0;c<n.length;c++){const r=n[c];if(!r)continue;const l=Array.isArray(r)?r:[r];for(const o of l)o&&typeof o=="object"&&!o._deleted&&h.push(o)}if(h.length===0)return{name:e,type:"custom",xAxisIndex:i,yAxisIndex:s,data:[],silent:!0};const p=(t.candlestickData?.length||0)+d,g=Math.max(0,p-1);return{name:e,type:"custom",xAxisIndex:i,yAxisIndex:s,renderItem:(c,r)=>{const l=[];for(const o of h){if(o._deleted)continue;const f=o.xloc==="bar_index"||o.xloc==="bi"?d:0,u=r.coord([o.left+f,o.top]),y=r.coord([o.right+f,o.bottom]);let I=u[0],P=u[1],A=y[0]-u[0],k=y[1]-u[1];const x=o.extend||"none";if(x!=="none"&&x!=="n"){const D=c.coordSys;(x==="left"||x==="l"||x==="both"||x==="b")&&(I=D.x,A=x==="both"||x==="b"?D.width:y[0]-D.x),(x==="right"||x==="r"||x==="both"||x==="b")&&(x==="right"||x==="r")&&(A=D.x+D.width-u[0])}const v=o.bgcolor,C=v==null||typeof v=="number"&&isNaN(v)||v==="na"||v==="NaN"||v===""?null:Mt(v)||"#2962ff";C&&l.push({type:"rect",shape:{x:I,y:P,width:A,height:k},style:{fill:C,stroke:"none"}});const S=o.border_color,_=S==null||typeof S=="number"&&isNaN(S)||S==="na"||S==="NaN"?null:Mt(S)||"#2962ff",M=o.border_width??1;if(M>0&&_&&l.push({type:"rect",shape:{x:I,y:P,width:A,height:k},style:{fill:"none",stroke:_,lineWidth:M,lineDash:this.getDashPattern(o.border_style)}}),o.text){const D=this.getTextX(I,A,o.text_halign),N=this.getTextY(P,k,o.text_valign);let L=Mt(o.text_color)||"#000000";if((!o.text_color||o.text_color==="#000000"||o.text_color==="black"||o.text_color==="color.black")&&C){const w=Vt(C);w&&Xt(w.r,w.g,w.b)<.5&&(L="#FFFFFF")}const m=!o.text_formatting||o.text_formatting==="format_none"||o.text_formatting==="format_bold",z=this.computeFontSize(o.text_size,o.text,Math.abs(A),Math.abs(k),m);l.push({type:"text",style:{x:D,y:N,text:o.text,fill:L,fontSize:z,fontFamily:o.text_font_family==="monospace"?"monospace":"sans-serif",fontWeight:m?"bold":"normal",fontStyle:o.text_formatting==="format_italic"?"italic":"normal",textAlign:this.mapHAlign(o.text_halign),textVerticalAlign:this.mapVAlign(o.text_valign)}})}}return{type:"group",children:l}},data:[[0,g]],clip:!0,encode:{x:[0,1]},itemStyle:{color:"transparent",borderColor:"transparent"},z:14,silent:!0,emphasis:{disabled:!0}}}getDashPattern(t){switch(t){case"style_dotted":return[2,2];case"style_dashed":return[6,4];default:return}}computeFontSize(t,e,i,s,n){if(typeof t=="number"&&t>0)return t;switch(t){case"tiny":case"size.tiny":return 8;case"small":case"size.small":return 10;case"normal":case"size.normal":return 14;case"large":case"size.large":return 20;case"huge":case"size.huge":return 36}if(!e||i<=0||s<=0)return 12;const a=6,d=i-a*2,h=s-a*2;if(d<=0||h<=0)return 6;const p=e.split(`
|
|
18
|
+
`),g=p.length;let c=1;for(const f of p)f.length>c&&(c=f.length);const r=d/(c*(n?.62:.55)),l=h/(g*1.3),o=Math.min(r,l);return Math.max(6,Math.min(o,48))}mapHAlign(t){switch(t){case"left":case"text.align_left":return"left";case"right":case"text.align_right":return"right";case"center":case"text.align_center":default:return"center"}}mapVAlign(t){switch(t){case"top":case"text.align_top":return"top";case"bottom":case"text.align_bottom":return"bottom";case"center":case"text.align_center":default:return"middle"}}getTextX(t,e,i){switch(i){case"left":case"text.align_left":return t+4;case"right":case"text.align_right":return t+e-4;case"center":case"text.align_center":default:return t+e/2}}getTextY(t,e,i){switch(i){case"top":case"text.align_top":return t+4;case"bottom":case"text.align_bottom":return t+e-4;case"center":case"text.align_center":default:return t+e/2}}}var Ut=Object.defineProperty,Kt=(b,t,e)=>t in b?Ut(b,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):b[t]=e,Jt=(b,t,e)=>(Kt(b,typeof t!="symbol"?t+"":t,e),e);const Q=class{static register(t,e){this.renderers.set(t,e)}static get(t){return this.renderers.get(t)||this.renderers.get("line")}};Jt(Q,"renderers",new Map),Q.register("line",new Ot),Q.register("step",new Zt),Q.register("histogram",new Pt),Q.register("columns",new Pt),Q.register("circles",new kt),Q.register("cross",new kt),Q.register("char",new kt),Q.register("bar",new zt),Q.register("candle",new zt),Q.register("shape",new Gt),Q.register("background",new Wt),Q.register("fill",new Et),Q.register("label",new Bt),Q.register("drawing_line",new Rt),Q.register("linefill",new Yt),Q.register("drawing_polyline",new jt),Q.register("drawing_box",new qt);let Qt=Q;var te=Object.defineProperty,ee=(b,t,e)=>t in b?te(b,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):b[t]=e,ie=(b,t,e)=>(ee(b,typeof t!="symbol"?t+"":t,e),e);const Nt=class Dt{static buildCandlestickSeries(t,e,i){const s=e.upColor||"#00da3c",n=e.downColor||"#ec0000",a=t.map(h=>[h.open,h.close,h.low,h.high]);if(i&&i>a.length){const h=i-a.length;for(let p=0;p<h;p++)a.push(null)}let d;if(e.lastPriceLine?.visible!==!1&&t.length>0){const h=t[t.length-1],p=h.close,g=h.close>=h.open,c=e.lastPriceLine?.color||(g?s:n);let r=e.lastPriceLine?.lineStyle||"dashed";r.startsWith("linestyle_")&&(r=r.replace("linestyle_",""));const l=e.yAxisDecimalPlaces!==void 0?e.yAxisDecimalPlaces:V.autoDetectDecimals(t);d={symbol:["none","none"],precision:l,data:[{yAxis:p,label:{show:!0,position:"end",formatter:o=>e.yAxisLabelFormatter?e.yAxisLabelFormatter(o.value):V.formatValue(o.value,l),color:"#fff",backgroundColor:c,padding:[2,4],borderRadius:2,fontSize:11,fontWeight:"bold"},lineStyle:{color:c,type:r,width:1,opacity:.8}}],animation:!1,silent:!0}}return{type:"candlestick",name:e.title||"Market",data:a,itemStyle:{color:s,color0:n,borderColor:s,borderColor0:n},markLine:d,xAxisIndex:0,yAxisIndex:0,z:5}}static buildIndicatorSeries(t,e,i,s,n=0,a,d,h=1){const p=[],g=new Array(s).fill(null),c=new Map;return t.forEach((r,l)=>{if(r.collapsed)return;const o=Object.keys(r.plots).sort((u,y)=>{const I=r.plots[u],P=r.plots[y],A=I.options.style==="fill",k=P.options.style==="fill";return A&&!k?1:!A&&k?-1:0}),f=new Map;if(o.forEach(u=>{const y=r.plots[u],I=y.options.display==="none",P=`${l}::${u}`;let A=0,k=0,x=y.options.overlay;if(y.options.style==="fill"&&x===void 0){const D=y.options.plot1,N=y.options.plot2;if(D&&N){const L=r.plots[D],m=r.plots[N];L?.options?.overlay===!0&&m?.options?.overlay===!0&&(x=!0)}}if(r.paneIndex===0||x===!0)A=0,d&&d.has(P)?k=d.get(P):k=0;else{const D=i.findIndex(N=>N.index===r.paneIndex);D!==-1&&(A=D+1,k=h+D)}const v=new Array(s).fill(null),C=new Array(s).fill(null),S=new Array(s).fill(null),_=new Array(s).fill(null);if(y.data?.forEach(D=>{const N=e.get(D.time);if(N!==void 0){const L=D.options?.offset??y.options.offset??0,m=N+n+L;if(m>=0&&m<s){let z=D.value;const w=D.options?.color;C[m]=z;const H=D.options!=null&&"color"in D.options,F=w===null||w==="na"||w==="NaN"||typeof w=="number"&&isNaN(w)||H&&w===void 0;F&&(z=null),v[m]=z,S[m]=F?null:w||y.options.color||Dt.DEFAULT_COLOR,_[m]=D.options||{}}}}),c.set(`${l}::${u}`,C),I)return;if(y.options?.style?.startsWith("style_")&&(y.options.style=y.options.style.replace("style_","")),y.options.style==="barcolor"){y.data?.forEach(D=>{const N=e.get(D.time);if(N!==void 0){const L=D.options?.offset??y.options.offset??0,m=N+n+L;if(m>=0&&m<s){const z=D.options?.color||y.options.color||Dt.DEFAULT_COLOR;!(z===null||z==="na"||z==="NaN"||typeof z=="number"&&isNaN(z))&&D.value!==null&&D.value!==void 0&&(g[m]=z)}}});return}if(y.options.style==="table")return;if(y.options.style==="fill"&&y.options.gradient!==!0){const D=y.options.plot1?`${l}::${y.options.plot1}`:null,N=y.options.plot2?`${l}::${y.options.plot2}`:null;if(D&&N){const L=c.get(D),m=c.get(N);if(L&&m){const{color:z,opacity:w}=rt.parseColor(y.options.color||"rgba(128, 128, 128, 0.2)"),H=_.some(O=>O&&O.color!==void 0),F=[];for(let O=0;O<s;O++){const Z=_[O];H&&Z&&Z.color!==void 0?F[O]=rt.parseColor(Z.color):F[O]={color:z,opacity:w}}const W=`${A}:${k}`;f.has(W)||f.set(W,{entries:[],xAxisIndex:A,yAxisIndex:k}),f.get(W).entries.push({plot1Data:L,plot2Data:m,barColors:F});return}}}if(y.options.color&&typeof y.options.color=="string"&&rt.parseColor(y.options.color).opacity<.01&&!S.some(D=>D==null?!1:rt.parseColor(D).opacity>=.01))return;const M=Qt.get(y.options.style).render({seriesName:P,xAxisIndex:A,yAxisIndex:k,dataArray:v,colorArray:S,optionsArray:_,plotOptions:y.options,candlestickData:a,plotDataArrays:c,indicatorId:l,plotName:u,dataIndexOffset:n});M&&p.push(M)}),f.size>0){const u=new Et;f.forEach(({entries:y,xAxisIndex:I,yAxisIndex:P},A)=>{if(y.length>=2){const k=u.renderBatched(`${l}::fills_batch_${A}`,I,P,s,y);k&&p.push(k)}else if(y.length===1){const k=u.renderBatched(`${l}::fills_batch_${A}`,I,P,s,y);k&&p.push(k)}})}}),{series:p,barColors:g}}};ie(Nt,"DEFAULT_COLOR","#2962ff");let mt=Nt;class se{static build(t,e,i,s=!1,n=null,a=[]){const d=[],h=t.pixelToPercent,p=t.mainPaneTop;if(!n||n==="main"){const g=10*h;if(d.push({type:"text",left:"8.5%",top:p+g+"%",z:10,style:{text:e.title||"Market",fill:e.titleColor||"#fff",font:`bold 16px ${e.fontFamily||"sans-serif"}`,textVerticalAlign:"top"}}),a.length>0){const r=20*h,l=16*h;a.forEach((o,f)=>{d.push({type:"text",left:"8.5%",top:p+g+r+f*l+"%",z:10,style:{text:o.id,fill:o.titleColor||"#9e9e9e",font:`bold 12px ${e.fontFamily||"sans-serif"}`,textVerticalAlign:"top"}})})}if(e.watermark!==!1){const r=t.mainPaneTop+t.mainPaneHeight;d.push({type:"text",right:"11%",top:r-3+"%",z:10,style:{text:"QFChart",fill:e.fontColor||"#cbd5e1",font:"bold 16px sans-serif",opacity:.1},cursor:"pointer",onclick:()=>{window.open("https://quantforge.org","_blank")}})}const c=[];if(e.controls?.collapse&&c.push({type:"group",children:[{type:"rect",shape:{width:20,height:20,r:2},style:{fill:"#334155",stroke:"#475569",lineWidth:1},onclick:()=>i("main","collapse")},{type:"text",style:{text:s?"+":"\u2212",fill:"#cbd5e1",font:`bold 14px ${e.fontFamily}`,x:10,y:10,textAlign:"center",textVerticalAlign:"middle"},silent:!0}]}),e.controls?.maximize){const r=n==="main",l=e.controls?.collapse?25:0;c.push({type:"group",x:l,children:[{type:"rect",shape:{width:20,height:20,r:2},style:{fill:"#334155",stroke:"#475569",lineWidth:1},onclick:()=>i("main","maximize")},{type:"text",style:{text:r?"\u2750":"\u25A1",fill:"#cbd5e1",font:`14px ${e.fontFamily}`,x:10,y:10,textAlign:"center",textVerticalAlign:"middle"},silent:!0}]})}if(e.controls?.fullscreen){let r=0;e.controls?.collapse&&(r+=25),e.controls?.maximize&&(r+=25),c.push({type:"group",x:r,children:[{type:"rect",shape:{width:20,height:20,r:2},style:{fill:"#334155",stroke:"#475569",lineWidth:1},onclick:()=>i("main","fullscreen")},{type:"text",style:{text:"\u26F6",fill:"#cbd5e1",font:`14px ${e.fontFamily}`,x:10,y:10,textAlign:"center",textVerticalAlign:"middle"},silent:!0}]})}c.length>0&&d.push({type:"group",right:"10.5%",top:p+"%",children:c})}return t.paneLayout.forEach(g=>{if(n&&g.indicatorId!==n)return;d.push({type:"text",left:"8.5%",top:g.top+10*h+"%",z:10,style:{text:g.indicatorId||"",fill:g.titleColor||"#fff",font:`bold 12px ${e.fontFamily||"sans-serif"}`,textVerticalAlign:"top"}});const c=[];if(g.controls?.collapse&&c.push({type:"group",children:[{type:"rect",shape:{width:20,height:20,r:2},style:{fill:"#334155",stroke:"#475569",lineWidth:1},onclick:()=>g.indicatorId&&i(g.indicatorId,"collapse")},{type:"text",style:{text:g.isCollapsed?"+":"\u2212",fill:"#cbd5e1",font:`bold 14px ${e.fontFamily}`,x:10,y:10,textAlign:"center",textVerticalAlign:"middle"},silent:!0}]}),g.controls?.maximize){const r=n===g.indicatorId,l=g.controls?.collapse?25:0;c.push({type:"group",x:l,children:[{type:"rect",shape:{width:20,height:20,r:2},style:{fill:"#334155",stroke:"#475569",lineWidth:1},onclick:()=>g.indicatorId&&i(g.indicatorId,"maximize")},{type:"text",style:{text:r?"\u2750":"\u25A1",fill:"#cbd5e1",font:`14px ${e.fontFamily}`,x:10,y:10,textAlign:"center",textVerticalAlign:"middle"},silent:!0}]})}c.length>0&&d.push({type:"group",right:"10.5%",top:g.top+"%",children:c})}),d}}class oe{static format(t,e){if(!t||t.length===0)return"";const i=e.title||"Market",s=e.upColor||"#00da3c",n=e.downColor||"#ec0000",a=e.fontFamily||"sans-serif",d=t[0].axisValue;let h=`<div style="font-weight: bold; margin-bottom: 5px; color: #cbd5e1; font-family: ${a};">${d}</div>`;const p=t.find(c=>c.seriesType==="candlestick"),g=t.filter(c=>c.seriesType!=="candlestick");if(p){const[c,r,l,o,f]=p.value,u=l>=r?s:n;h+=`
|
|
19
|
+
<div style="margin-bottom: 8px; font-family: ${a};">
|
|
20
|
+
<div style="display:flex; justify-content:space-between; color:${u}; font-weight:bold;">
|
|
20
21
|
<span>${i}</span>
|
|
21
22
|
</div>
|
|
22
23
|
<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: ${
|
|
24
|
+
<span>Open:</span> <span style="text-align: right; color: ${l>=r?s:n}">${r}</span>
|
|
25
|
+
<span>High:</span> <span style="text-align: right; color: ${s}">${f}</span>
|
|
26
|
+
<span>Low:</span> <span style="text-align: right; color: ${n}">${o}</span>
|
|
27
|
+
<span>Close:</span> <span style="text-align: right; color: ${l>=r?s:n}">${l}</span>
|
|
27
28
|
</div>
|
|
28
29
|
</div>
|
|
29
|
-
`}if(g.length>0){
|
|
30
|
-
<div style="margin-top: 8px; font-family: ${
|
|
31
|
-
<div style="font-weight:bold; color: #fff; margin-bottom: 2px;">${
|
|
32
|
-
`,r
|
|
30
|
+
`}if(g.length>0){h+='<div style="border-top: 1px solid #334155; margin: 5px 0; padding-top: 5px;"></div>';const c={};g.forEach(r=>{const l=r.seriesName.split("::"),o=l.length>1?l[0]:"Unknown",f=l.length>1?l[1]:r.seriesName;c[o]||(c[o]=[]),c[o].push({...r,displayName:f})}),Object.keys(c).forEach(r=>{h+=`
|
|
31
|
+
<div style="margin-top: 8px; font-family: ${a};">
|
|
32
|
+
<div style="font-weight:bold; color: #fff; margin-bottom: 2px;">${r}</div>
|
|
33
|
+
`,c[r].forEach(l=>{let o=l.value;if(Array.isArray(o)&&(o=o[1]),o==null)return;const f=typeof o=="number"?o.toLocaleString(void 0,{maximumFractionDigits:4}):o;h+=`
|
|
33
34
|
<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>`}),d+="</div>"})}return d}}var Kt=Object.defineProperty,Qt=(x,t,e)=>t in x?Kt(x,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):x[t]=e,pt=(x,t,e)=>(Qt(x,typeof t!="symbol"?t+"":t,e),e);class te{constructor(t,e){pt(this,"plugins",new Map),pt(this,"activePluginId",null),pt(this,"context"),pt(this,"toolbarContainer"),pt(this,"tooltipElement",null),pt(this,"hideTimeout",null),this.context=t,this.toolbarContainer=e,this.createTooltip(),this.renderToolbar()}createTooltip(){this.tooltipElement=document.createElement("div"),Object.assign(this.tooltipElement.style,{position:"fixed",display:"none",backgroundColor:"#1e293b",color:"#e2e8f0",padding:"6px 10px",borderRadius:"6px",fontSize:"13px",lineHeight:"1.4",fontWeight:"500",border:"1px solid #334155",zIndex:"9999",pointerEvents:"none",whiteSpace:"nowrap",boxShadow:"0 4px 6px -1px rgba(0, 0, 0, 0.3), 0 2px 4px -1px rgba(0, 0, 0, 0.15)",fontFamily:this.context.getOptions().fontFamily||"sans-serif",transition:"opacity 0.15s ease-in-out, transform 0.15s ease-in-out",opacity:"0",transform:"translateX(-5px)"}),document.body.appendChild(this.tooltipElement)}destroy(){this.tooltipElement&&this.tooltipElement.parentNode&&this.tooltipElement.parentNode.removeChild(this.tooltipElement),this.tooltipElement=null}showTooltip(t,e){if(!this.tooltipElement)return;this.hideTimeout&&(clearTimeout(this.hideTimeout),this.hideTimeout=null);const i=t.getBoundingClientRect();this.tooltipElement.textContent=e,this.tooltipElement.style.display="block";const s=this.tooltipElement.getBoundingClientRect(),a=i.top+(i.height-s.height)/2,o=i.right+10;this.tooltipElement.style.top=`${a}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(t){if(this.plugins.has(t.id)){console.warn(`Plugin with id ${t.id} is already registered.`);return}this.plugins.set(t.id,t),t.init(this.context),this.addButton(t)}unregister(t){const e=this.plugins.get(t);e&&(this.activePluginId===t&&this.deactivatePlugin(),e.destroy?.(),this.plugins.delete(t),this.removeButton(t))}activatePlugin(t){if(this.activePluginId===t){this.deactivatePlugin();return}this.activePluginId&&this.deactivatePlugin();const e=this.plugins.get(t);e&&(this.activePluginId=t,this.setButtonActive(t,!0),e.activate?.())}deactivatePlugin(){this.activePluginId&&(this.plugins.get(this.activePluginId)?.deactivate?.(),this.setButtonActive(this.activePluginId,!1),this.activePluginId=null)}renderToolbar(){this.toolbarContainer.innerHTML="",this.toolbarContainer.classList.add("qfchart-toolbar"),this.toolbarContainer.style.display="flex",this.toolbarContainer.style.flexDirection="column",this.toolbarContainer.style.width="40px",this.toolbarContainer.style.backgroundColor=this.context.getOptions().backgroundColor||"#1e293b",this.toolbarContainer.style.borderRight="1px solid #334155",this.toolbarContainer.style.padding="5px",this.toolbarContainer.style.boxSizing="border-box",this.toolbarContainer.style.gap="5px",this.toolbarContainer.style.flexShrink="0"}addButton(t){const e=document.createElement("button");e.id=`qfchart-plugin-btn-${t.id}`,e.style.width="30px",e.style.height="30px",e.style.padding="4px",e.style.border="1px solid transparent",e.style.borderRadius="4px",e.style.backgroundColor="transparent",e.style.cursor="pointer",e.style.color=this.context.getOptions().fontColor||"#cbd5e1",e.style.display="flex",e.style.alignItems="center",e.style.justifyContent="center",t.icon?e.innerHTML=t.icon:e.innerText=(t.name||t.id).substring(0,2).toUpperCase(),e.addEventListener("mouseenter",()=>{this.activePluginId!==t.id&&(e.style.backgroundColor="rgba(255, 255, 255, 0.1)"),this.showTooltip(e,t.name||t.id)}),e.addEventListener("mouseleave",()=>{this.activePluginId!==t.id&&(e.style.backgroundColor="transparent"),this.hideTooltip()}),e.onclick=()=>this.activatePlugin(t.id),this.toolbarContainer.appendChild(e)}removeButton(t){const e=this.toolbarContainer.querySelector(`#qfchart-plugin-btn-${t}`);e&&e.remove()}setButtonActive(t,e){const i=this.toolbarContainer.querySelector(`#qfchart-plugin-btn-${t}`);i&&(e?(i.style.backgroundColor="#2563eb",i.style.color="#ffffff"):(i.style.backgroundColor="transparent",i.style.color=this.context.getOptions().fontColor||"#cbd5e1"))}}var ee=Object.defineProperty,ie=(x,t,e)=>t in x?ee(x,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):x[t]=e,X=(x,t,e)=>(ie(x,typeof t!="symbol"?t+"":t,e),e);class se{constructor(t){X(this,"context"),X(this,"isEditing",!1),X(this,"currentDrawing",null),X(this,"editingPointIndex",null),X(this,"zr"),X(this,"editGroup",null),X(this,"editLine",null),X(this,"editStartPoint",null),X(this,"editEndPoint",null),X(this,"isMovingShape",!1),X(this,"dragStart",null),X(this,"initialPixelPoints",[]),X(this,"onDrawingMouseDown",e=>{if(this.isEditing)return;const i=this.context.getDrawing(e.id);i&&(this.isEditing=!0,this.isMovingShape=!0,this.currentDrawing=JSON.parse(JSON.stringify(i)),this.dragStart={x:e.x,y:e.y},this.initialPixelPoints=i.points.map(s=>{const a=this.context.coordinateConversion.dataToPixel(s);return a?{x:a.x,y:a.y}:{x:0,y:0}}),this.context.lockChart(),this.createEditGraphic(),this.zr.on("mousemove",this.onMouseMove),this.zr.on("mouseup",this.onMouseUp))}),X(this,"onPointMouseDown",e=>{if(this.isEditing)return;const i=this.context.getDrawing(e.id);i&&(this.isEditing=!0,this.currentDrawing=JSON.parse(JSON.stringify(i)),this.editingPointIndex=e.pointIndex,this.context.lockChart(),this.createEditGraphic(),this.zr.on("mousemove",this.onMouseMove),this.zr.on("mouseup",this.onMouseUp))}),X(this,"onMouseMove",e=>{if(!this.isEditing||!this.currentDrawing)return;const i=e.offsetX,s=e.offsetY;if(this.isMovingShape&&this.dragStart){const a=i-this.dragStart.x,o=s-this.dragStart.y,u={x:this.initialPixelPoints[0].x+a,y:this.initialPixelPoints[0].y+o},d={x:this.initialPixelPoints[1].x+a,y:this.initialPixelPoints[1].y+o};this.editLine.setShape({x1:u.x,y1:u.y,x2:d.x,y2:d.y}),this.editStartPoint.setShape({cx:u.x,cy:u.y}),this.editEndPoint.setShape({cx:d.x,cy:d.y})}else this.editingPointIndex!==null&&(this.editingPointIndex===0?(this.editLine.setShape({x1:i,y1:s}),this.editStartPoint.setShape({cx:i,cy:s})):(this.editLine.setShape({x2:i,y2:s}),this.editEndPoint.setShape({cx:i,cy:s})))}),X(this,"onMouseUp",e=>{this.isEditing&&this.finishEditing(e.offsetX,e.offsetY)}),this.context=t,this.zr=this.context.getChart().getZr(),this.bindEvents()}bindEvents(){this.context.events.on("drawing:point:mousedown",this.onPointMouseDown),this.context.events.on("drawing:mousedown",this.onDrawingMouseDown)}createEditGraphic(){if(!this.currentDrawing)return;this.editGroup=new H.graphic.Group;const t=this.currentDrawing.points[0],e=this.currentDrawing.points[1],i=this.context.coordinateConversion.dataToPixel(t),s=this.context.coordinateConversion.dataToPixel(e);!i||!s||(this.editLine=new H.graphic.Line({shape:{x1:i.x,y1:i.y,x2:s.x,y2:s.y},style:{stroke:this.currentDrawing.style?.color||"#3b82f6",lineWidth:this.currentDrawing.style?.lineWidth||2,lineDash:[4,4]},silent:!0}),this.editStartPoint=new H.graphic.Circle({shape:{cx:i.x,cy:i.y,r:5},style:{fill:"#fff",stroke:"#3b82f6",lineWidth:2},z:1e3}),this.editEndPoint=new H.graphic.Circle({shape:{cx:s.x,cy:s.y,r:5},style:{fill:"#fff",stroke:"#3b82f6",lineWidth:2},z:1e3}),this.editGroup.add(this.editLine),this.editGroup.add(this.editStartPoint),this.editGroup.add(this.editEndPoint),this.zr.add(this.editGroup))}finishEditing(t,e){if(this.currentDrawing){if(this.isMovingShape&&this.dragStart){const i=t-this.dragStart.x,s=e-this.dragStart.y,a=this.initialPixelPoints.map((o,u)=>{const d=o.x+i,p=o.y+s;return this.context.coordinateConversion.pixelToData({x:d,y:p})});a.every(o=>o!==null)&&a[0]&&a[1]&&(this.currentDrawing.points[0]=a[0],this.currentDrawing.points[1]=a[1],a[0].paneIndex!==void 0&&(this.currentDrawing.paneIndex=a[0].paneIndex),this.context.updateDrawing(this.currentDrawing))}else if(this.editingPointIndex!==null){const i=this.context.coordinateConversion.pixelToData({x:t,y:e});i&&(this.currentDrawing.points[this.editingPointIndex]=i,this.editingPointIndex===0&&i.paneIndex!==void 0&&(this.currentDrawing.paneIndex=i.paneIndex),this.context.updateDrawing(this.currentDrawing))}this.isEditing=!1,this.isMovingShape=!1,this.dragStart=null,this.initialPixelPoints=[],this.currentDrawing=null,this.editingPointIndex=null,this.editGroup&&(this.zr.remove(this.editGroup),this.editGroup=null),this.zr.off("mousemove",this.onMouseMove),this.zr.off("mouseup",this.onMouseUp),this.context.unlockChart()}}}var ne=Object.defineProperty,oe=(x,t,e)=>t in x?ne(x,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):x[t]=e,ae=(x,t,e)=>(oe(x,typeof t!="symbol"?t+"":t,e),e);class re{constructor(){ae(this,"handlers",new Map)}on(t,e){this.handlers.has(t)||this.handlers.set(t,new Set),this.handlers.get(t).add(e)}off(t,e){const i=this.handlers.get(t);i&&i.delete(e)}emit(t,e){const i=this.handlers.get(t);i&&i.forEach(s=>{try{s(e)}catch(a){console.error(`Error in EventBus handler for ${t}:`,a)}})}clear(){this.handlers.clear()}}class J{static safeParseColor(t){if(!t||typeof t!="string")return{color:"#888888",opacity:1};const e=t.match(/rgba?\((\d+),\s*(\d+),\s*(\d+)(?:,\s*([\d.]+))?\)/);if(e){const i=e[4]?parseFloat(e[4]):1;return{color:`rgb(${e[1]},${e[2]},${e[3]})`,opacity:i}}return{color:t,opacity:1}}static render(t,e,i){J.clearAll(t);const s=new Map;for(const a of e)a&&!a._deleted&&s.set(a.position,a);s.forEach(a=>{const o=a._paneIndex??0,u=i?i(o):void 0,d=J.buildTable(a);J.positionTable(d,a.position,u),t.appendChild(d)})}static clearAll(t){for(;t.firstChild;)t.removeChild(t.firstChild)}static buildTable(t){const e=document.createElement("table"),i=t.border_width??0,s=t.frame_width??0;if(i>0&&t.border_color||s>0&&t.frame_color?(e.style.borderCollapse="separate",e.style.borderSpacing="0"):e.style.borderCollapse="collapse",e.style.pointerEvents="none",e.style.fontSize="14px",e.style.lineHeight="1.4",e.style.fontFamily="sans-serif",e.style.margin="4px",t.bgcolor){const{color:r,opacity:l}=J.safeParseColor(t.bgcolor);e.style.backgroundColor=r,l<1&&(e.style.opacity=String(l))}if(s>0&&t.frame_color){const{color:r}=J.safeParseColor(t.frame_color);e.style.border=`${s}px solid ${r}`}else e.style.border="none";const a=new Map,o=new Set;if(t.merges)for(const r of t.merges){const l=`${r.startCol},${r.startRow}`;a.set(l,{colspan:r.endCol-r.startCol+1,rowspan:r.endRow-r.startRow+1});for(let h=r.startRow;h<=r.endRow;h++)for(let n=r.startCol;n<=r.endCol;n++)h===r.startRow&&n===r.startCol||o.add(`${n},${h}`)}const u=i>0&&!!t.border_color,d=u?J.safeParseColor(t.border_color).color:"",p=t.rows||0,g=t.columns||0;for(let r=0;r<p;r++){const l=document.createElement("tr");for(let h=0;h<g;h++){const n=`${h},${r}`;if(o.has(n))continue;const c=document.createElement("td"),f=a.get(n);f&&(f.colspan>1&&(c.colSpan=f.colspan),f.rowspan>1&&(c.rowSpan=f.rowspan)),u?c.style.border=`${i}px solid ${d}`:c.style.border="none";const m=t.cells?.[r]?.[h];if(m&&!m._merged){if(c.textContent=m.text||"",m.bgcolor){const{color:w,opacity:C}=J.safeParseColor(m.bgcolor);c.style.backgroundColor=w,C<1&&(c.style.backgroundColor=m.bgcolor)}if(m.text_color){const{color:w}=J.safeParseColor(m.text_color);c.style.color=w}c.style.fontSize=J.getSizePixels(m.text_size)+"px",c.style.textAlign=J.mapHAlign(m.text_halign),c.style.verticalAlign=J.mapVAlign(m.text_valign),m.text_font_family==="monospace"&&(c.style.fontFamily="monospace"),m.width>0&&(c.style.width=m.width+"%"),m.height>0&&(c.style.height=m.height+"%"),m.tooltip&&(c.title=m.tooltip)}c.style.padding="4px 6px",c.style.whiteSpace="nowrap",l.appendChild(c)}e.appendChild(l)}return e}static positionTable(t,e,i){t.style.position="absolute";const s=8,a=i?i.y+"px":"0",o=i?i.x+"px":"0",u=i?i.y+i.height-s+"px":"0",d=i?i.x+i.width-s+"px":"0",p=i?i.x+i.width/2+"px":"50%",g=i?i.y+i.height/2+"px":"50%";switch(e){case"top_left":t.style.top=a,t.style.left=o;break;case"top_center":t.style.top=a,t.style.left=p,t.style.transform="translateX(-50%)";break;case"top_right":t.style.top=a,t.style.left=d,t.style.transform="translateX(-100%)";break;case"middle_left":t.style.top=g,t.style.left=o,t.style.transform="translateY(-50%)";break;case"middle_center":t.style.top=g,t.style.left=p,t.style.transform="translate(-50%, -50%)";break;case"middle_right":t.style.top=g,t.style.left=d,t.style.transform="translate(-100%, -50%)";break;case"bottom_left":t.style.top=u,t.style.left=o,t.style.transform="translateY(-100%)";break;case"bottom_center":t.style.top=u,t.style.left=p,t.style.transform="translate(-50%, -100%)";break;case"bottom_right":t.style.top=u,t.style.left=d,t.style.transform="translate(-100%, -100%)";break;default:t.style.top=a,t.style.left=d,t.style.transform="translateX(-100%)";break}}static getSizePixels(t){if(typeof t=="number"&&t>0)return t;switch(t){case"auto":case"size.auto":return 12;case"tiny":case"size.tiny":return 8;case"small":case"size.small":return 10;case"normal":case"size.normal":return 14;case"large":case"size.large":return 20;case"huge":case"size.huge":return 36;default:return 14}}static mapHAlign(t){switch(t){case"left":case"text.align_left":return"left";case"right":case"text.align_right":return"right";case"center":case"text.align_center":default:return"center"}}static mapVAlign(t){switch(t){case"top":case"text.align_top":return"top";case"bottom":case"text.align_bottom":return"bottom";case"center":case"text.align_center":default:return"middle"}}}var le=Object.defineProperty,he=(x,t,e)=>t in x?le(x,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):x[t]=e,z=(x,t,e)=>(he(x,typeof t!="symbol"?t+"":t,e),e);class ce{constructor(t,e={}){z(this,"chart"),z(this,"options"),z(this,"marketData",[]),z(this,"indicators",new Map),z(this,"timeToIndex",new Map),z(this,"pluginManager"),z(this,"drawingEditor"),z(this,"events",new re),z(this,"isMainCollapsed",!1),z(this,"maximizedPaneId",null),z(this,"countdownInterval",null),z(this,"selectedDrawingId",null),z(this,"drawings",[]),z(this,"coordinateConversion",{pixelToData:o=>{const u=this.chart.getOption();if(!u||!u.grid)return null;const d=u.grid.length;for(let p=0;p<d;p++)if(this.chart.containPixel({gridIndex:p},[o.x,o.y])){this.chart.convertFromPixel({seriesIndex:p},[o.x,o.y]);const g=this.chart.convertFromPixel({gridIndex:p},[o.x,o.y]);if(g)return{timeIndex:Math.round(g[0]),value:g[1],paneIndex:p}}return null},dataToPixel:o=>{const u=o.paneIndex||0,d=this.chart.convertToPixel({gridIndex:u},[o.timeIndex,o.value]);return d?{x:d[0],y:d[1]}:null}}),z(this,"upColor","#00da3c"),z(this,"downColor","#ec0000"),z(this,"defaultPadding",0),z(this,"padding"),z(this,"dataIndexOffset",0),z(this,"rootContainer"),z(this,"layoutContainer"),z(this,"toolbarContainer"),z(this,"leftSidebar"),z(this,"rightSidebar"),z(this,"chartContainer"),z(this,"overlayContainer"),z(this,"_lastTables",[]),z(this,"_lastLayout",null),z(this,"_mainHeightOverride",null),z(this,"_paneDragState",null),z(this,"_paneResizeRafId",null),z(this,"onKeyDown",o=>{(o.key==="Delete"||o.key==="Backspace")&&this.selectedDrawingId&&(this.removeDrawing(this.selectedDrawingId),this.selectedDrawingId=null,this.render())}),z(this,"onFullscreenChange",()=>{this.render()}),z(this,"isLocked",!1),z(this,"lockedState",null),this.rootContainer=t,this.options={title:"Market",height:"600px",backgroundColor:"#1e293b",upColor:"#00da3c",downColor:"#ec0000",fontColor:"#cbd5e1",fontFamily:"sans-serif",padding:.01,dataZoom:{visible:!0,position:"top",height:6},layout:{mainPaneHeight:"50%",gap:13},watermark:!0,...e},this.options.upColor&&(this.upColor=this.options.upColor),this.options.downColor&&(this.downColor=this.options.downColor),this.padding=this.options.padding!==void 0?this.options.padding:this.defaultPadding,this.options.height&&(typeof this.options.height=="number"?this.rootContainer.style.height=`${this.options.height}px`:this.rootContainer.style.height=this.options.height),this.rootContainer.innerHTML="",this.layoutContainer=document.createElement("div"),this.layoutContainer.style.display="flex",this.layoutContainer.style.width="100%",this.layoutContainer.style.height="100%",this.layoutContainer.style.overflow="hidden",this.rootContainer.appendChild(this.layoutContainer),this.leftSidebar=document.createElement("div"),this.leftSidebar.style.display="none",this.leftSidebar.style.width="250px",this.leftSidebar.style.flexShrink="0",this.leftSidebar.style.overflowY="auto",this.leftSidebar.style.backgroundColor=this.options.backgroundColor||"#1e293b",this.leftSidebar.style.borderRight="1px solid #334155",this.leftSidebar.style.padding="10px",this.leftSidebar.style.boxSizing="border-box",this.leftSidebar.style.color="#cbd5e1",this.leftSidebar.style.fontSize="12px",this.leftSidebar.style.fontFamily=this.options.fontFamily||"sans-serif",this.layoutContainer.appendChild(this.leftSidebar),this.toolbarContainer=document.createElement("div"),this.layoutContainer.appendChild(this.toolbarContainer),this.chartContainer=document.createElement("div"),this.chartContainer.style.flexGrow="1",this.chartContainer.style.height="100%",this.chartContainer.style.overflow="hidden",this.layoutContainer.appendChild(this.chartContainer),this.rightSidebar=document.createElement("div"),this.rightSidebar.style.display="none",this.rightSidebar.style.width="250px",this.rightSidebar.style.flexShrink="0",this.rightSidebar.style.overflowY="auto",this.rightSidebar.style.backgroundColor=this.options.backgroundColor||"#1e293b",this.rightSidebar.style.borderLeft="1px solid #334155",this.rightSidebar.style.padding="10px",this.rightSidebar.style.boxSizing="border-box",this.rightSidebar.style.color="#cbd5e1",this.rightSidebar.style.fontSize="12px",this.rightSidebar.style.fontFamily=this.options.fontFamily||"sans-serif",this.layoutContainer.appendChild(this.rightSidebar),this.chart=H.init(this.chartContainer),this.chartContainer.style.position="relative",this.overlayContainer=document.createElement("div"),this.overlayContainer.style.cssText="position:absolute;top:0;left:0;width:100%;height:100%;pointer-events:none;z-index:100;overflow:hidden;",this.chartContainer.appendChild(this.overlayContainer),this.pluginManager=new te(this,this.toolbarContainer),this.drawingEditor=new se(this),this.chart.on("dataZoom",o=>{this.events.emit("chart:dataZoom",o);const u=this.options.databox?.triggerOn,d=this.options.databox?.position;u==="click"&&d==="floating"&&this.chart.dispatchAction({type:"hideTip"})}),this.chart.on("finished",o=>this.events.emit("chart:updated",o)),this.chart.getZr().on("mousedown",o=>{this._paneDragState||this.events.emit("mouse:down",o)}),this.chart.getZr().on("mousemove",o=>{this._paneDragState||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._paneDragState||this.events.emit("mouse:click",o)});const i=this.chart.getZr(),s=i.setCursorStyle,a=this;i.setCursorStyle=function(o){if(a._paneDragState){s.call(this,"row-resize");return}o==="grab"&&(o="crosshair"),s.call(this,o)},this.bindDrawingEvents(),this.bindPaneResizeEvents(),window.addEventListener("resize",this.resize.bind(this)),document.addEventListener("fullscreenchange",this.onFullscreenChange),document.addEventListener("keydown",this.onKeyDown)}bindPaneResizeEvents(){const t=this.chart.getZr(),e=s=>{if(!this._lastLayout||this._lastLayout.paneBoundaries.length===0||this.maximizedPaneId)return null;const a=this.chart.getHeight();if(a<=0)return null;for(const o of this._lastLayout.paneBoundaries){const u=o.yPercent/100*a;if(Math.abs(s-u)<=6){if(o.aboveId==="main"&&this.isMainCollapsed||this.indicators.get(o.belowId)?.collapsed||o.aboveId!=="main"&&this.indicators.get(o.aboveId)?.collapsed)continue;return o}}return null},i=s=>s==="main"?this._lastLayout?.mainPaneHeight??50:this.indicators.get(s)?.height??15;t.on("mousemove",s=>{if(this._paneDragState){const a=s.offsetY-this._paneDragState.startY,o=this.chart.getHeight();if(o<=0)return;const u=a/o*100,d=this._paneDragState.aboveId==="main"?10:5,p=5;let g=this._paneDragState.startAboveHeight+u,r=this._paneDragState.startBelowHeight-u;if(g<d&&(g=d,r=this._paneDragState.startAboveHeight+this._paneDragState.startBelowHeight-d),r<p&&(r=p,g=this._paneDragState.startAboveHeight+this._paneDragState.startBelowHeight-p),this._paneDragState.aboveId==="main")this._mainHeightOverride=g;else{const h=this.indicators.get(this._paneDragState.aboveId);h&&(h.height=g)}const l=this.indicators.get(this._paneDragState.belowId);l&&(l.height=r),this._paneResizeRafId||(this._paneResizeRafId=requestAnimationFrame(()=>{this._paneResizeRafId=null,this.render()})),t.setCursorStyle("row-resize"),s.stop?.();return}e(s.offsetY)&&t.setCursorStyle("row-resize")}),t.on("mousedown",s=>{const a=e(s.offsetY);a&&(this._paneDragState={startY:s.offsetY,aboveId:a.aboveId,belowId:a.belowId,startAboveHeight:i(a.aboveId),startBelowHeight:i(a.belowId)},t.setCursorStyle("row-resize"),s.stop?.())}),t.on("mouseup",()=>{this._paneDragState&&(this._paneDragState=null,this._paneResizeRafId&&(cancelAnimationFrame(this._paneResizeRafId),this._paneResizeRafId=null),this.render())})}bindDrawingEvents(){let t=null;const e=i=>{if(!i||i.componentType!=="series"||!i.seriesName?.startsWith("drawings"))return null;i.seriesIndex;const s=i.seriesName.match(/drawings-pane-(\d+)/);if(!s)return null;const a=parseInt(s[1]),o=this.drawings.filter(d=>(d.paneIndex||0)===a)[i.dataIndex];if(!o)return null;const u=i.event?.target?.name;return{drawing:o,targetName:u,paneIdx:a}};this.chart.on("mouseover",i=>{const s=e(i);if(!s)return;const a=i.event?.target?.parent;if(a){const o=s.drawing.id===this.selectedDrawingId;t&&(clearTimeout(t),t=null),o||a.children().forEach(u=>{u.name&&u.name.startsWith("point")&&u.attr("style",{opacity:1})})}if(s.targetName==="line")this.events.emit("drawing:hover",{id:s.drawing.id,type:s.drawing.type}),this.chart.getZr().setCursorStyle("move");else if(s.targetName?.startsWith("point")){const 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=e(i);if(!s)return;const a=i.event?.target?.parent;if(s.drawing.id!==this.selectedDrawingId){if(t=setTimeout(()=>{if(a){if(this.selectedDrawingId===s.drawing.id)return;a.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=e(i);if(!s)return;const a=i.event?.event||i.event,o=a?.offsetX,u=a?.offsetY;if(s.targetName==="line")this.events.emit("drawing:mousedown",{id:s.drawing.id,x:o,y:u});else if(s.targetName?.startsWith("point")){const d=s.targetName==="point-start"?0:1;this.events.emit("drawing:point:mousedown",{id:s.drawing.id,pointIndex:d,x:o,y:u})}}),this.chart.on("click",i=>{const s=e(i);if(s){if(this.selectedDrawingId!==s.drawing.id&&(this.selectedDrawingId=s.drawing.id,this.events.emit("drawing:selected",{id:s.drawing.id}),this.render()),s.targetName==="line")this.events.emit("drawing:click",{id:s.drawing.id});else if(s.targetName?.startsWith("point")){const a=s.targetName==="point-start"?0:1;this.events.emit("drawing:point:click",{id:s.drawing.id,pointIndex:a})}}}),this.chart.getZr().on("click",i=>{i.target||this.selectedDrawingId&&(this.events.emit("drawing:deselected",{id:this.selectedDrawingId}),this.selectedDrawingId=null,this.render())})}getChart(){return this.chart}getMarketData(){return this.marketData}getTimeToIndex(){return this.timeToIndex}getOptions(){return this.options}disableTools(){this.pluginManager.deactivatePlugin()}registerPlugin(t){this.pluginManager.register(t)}addDrawing(t){this.drawings.push(t),this.render()}removeDrawing(t){const e=this.drawings.findIndex(i=>i.id===t);if(e!==-1){const i=this.drawings[e];this.drawings.splice(e,1),this.events.emit("drawing:deleted",{id:i.id}),this.render()}}getDrawing(t){return this.drawings.find(e=>e.id===t)}updateDrawing(t){const e=this.drawings.findIndex(i=>i.id===t.id);e!==-1&&(this.drawings[e]=t,this.render())}lockChart(){if(this.isLocked)return;this.isLocked=!0;const t=this.chart.getOption();this.chart.setOption({dataZoom:t.dataZoom.map(e=>({...e,disabled:!0})),tooltip:{show:!1}})}unlockChart(){if(!this.isLocked)return;this.isLocked=!1;const t=this.chart.getOption();(this.options.dataZoom||{}).visible,t.dataZoom&&this.chart.setOption({dataZoom:t.dataZoom.map(e=>({...e,disabled:!1})),tooltip:{show:!0}})}setZoom(t,e){this.chart.dispatchAction({type:"dataZoom",start:t,end:e})}setMarketData(t){this.marketData=t,this.rebuildTimeIndex(),this.render()}updateData(t){if(t.length===0)return;const e=new Map;this.marketData.forEach(f=>{e.set(f.time,f)}),t.forEach(f=>{e.has(f.time),e.set(f.time,f)}),this.marketData=Array.from(e.values()).sort((f,m)=>f.time-m.time),this.rebuildTimeIndex();const i=this.dataIndexOffset,s=gt.buildCandlestickSeries(this.marketData,this.options),a={value:[NaN,NaN,NaN,NaN],itemStyle:{opacity:0}},o=[...Array(i).fill(a),...s.data,...Array(i).fill(a)],u=[...Array(i).fill(""),...this.marketData.map(f=>new Date(f.time).toLocaleString()),...Array(i).fill("")],d=this.chart.getOption(),p=At.calculate(this.chart.getHeight(),this.indicators,this.options,this.isMainCollapsed,this.maximizedPaneId,this.marketData,this._mainHeightOverride??void 0);this._lastLayout=p;const g=[...Array(i).fill(null),...this.marketData,...Array(i).fill(null)],{series:r,barColors:l}=gt.buildIndicatorSeries(this.indicators,this.timeToIndex,p.paneLayout,u.length,i,g,p.overlayYAxisMap,p.separatePaneYAxisOffset),h=o.map((f,m)=>l[m]?{value:f.value||f,itemStyle:{color:l[m],color0:l[m],borderColor:l[m],borderColor0:l[m]}}:f),n={xAxis:d.xAxis.map((f,m)=>({data:u})),series:[{data:h,markLine:s.markLine},...r.map(f=>{const m={data:f.data};return f.renderItem&&(m.renderItem=f.renderItem),m})]};this.chart.setOption(n,{notMerge:!1});const c=[];this.indicators.forEach(f=>{Object.values(f.plots).forEach(m=>{m.options?.style==="table"&&m.data?.forEach(w=>{(Array.isArray(w.value)?w.value:[w.value]).forEach(C=>{C&&!C._deleted&&(C._paneIndex=C.force_overlay?0:f.paneIndex,c.push(C))})})})}),this._lastTables=c,this._renderTableOverlays(),this.startCountdown()}startCountdown(){if(this.stopCountdown(),!this.options.lastPriceLine?.showCountdown||!this.options.interval||this.marketData.length===0)return;const t=()=>{if(this.marketData.length===0)return;const e=this.marketData[this.marketData.length-1].time+(this.options.interval||0),i=Date.now(),s=e-i;if(s<=0)return;const a=Math.abs(s),o=Math.floor(a/36e5),u=Math.floor(a%36e5/6e4),d=Math.floor(a%6e4/1e3),p=`${o>0?o.toString().padStart(2,"0")+":":""}${u.toString().padStart(2,"0")}:${d.toString().padStart(2,"0")}`,g=this.chart.getOption();if(!g||!g.series)return;const r=g.series.findIndex(m=>m.type==="candlestick");if(r===-1)return;const l=g.series[r];if(!l.markLine||!l.markLine.data||!l.markLine.data[0])return;const h=l.markLine.data[0];h.label.formatter;const n=h.yAxis;let c="";if(this.options.yAxisLabelFormatter)c=this.options.yAxisLabelFormatter(n);else{const m=this.options.yAxisDecimalPlaces!==void 0?this.options.yAxisDecimalPlaces:Z.autoDetectDecimals(this.marketData);c=Z.formatValue(n,m)}const f=`${c}
|
|
37
|
-
${p}`;this.chart.setOption({series:[{name:this.options.title||"Market",markLine:{data:[{...h,label:{...h.label,formatter:f}}]}}]})};t(),this.countdownInterval=setInterval(t,1e3)}stopCountdown(){this.countdownInterval&&(clearInterval(this.countdownInterval),this.countdownInterval=null)}addIndicator(t,e,i={}){const s=i.overlay!==void 0?i.overlay:i.isOverlay??!1;let a=0;if(!s){let u=0;this.indicators.forEach(d=>{d.paneIndex>u&&(u=d.paneIndex)}),a=u+1}const o=new zt(t,e,a,{height:i.height,collapsed:!1,titleColor:i.titleColor,controls:i.controls});return this.indicators.set(t,o),this.render(),o}setIndicator(t,e,i=!1){this.addIndicator(t,{[t]:e},{overlay:i})}removeIndicator(t){this.indicators.delete(t),this.render()}toggleIndicator(t,e="collapse"){if(e==="fullscreen"){document.fullscreenElement?document.exitFullscreen():this.rootContainer.requestFullscreen();return}if(e==="maximize"){this.maximizedPaneId===t?this.maximizedPaneId=null:this.maximizedPaneId=t,this.render();return}if(t==="main"){this.isMainCollapsed=!this.isMainCollapsed,this.render();return}const i=this.indicators.get(t);i&&(i.toggleCollapse(),this.render())}resize(){this.chart.resize(),this._renderTableOverlays()}_renderTableOverlays(){const t=this.chart.getModel(),e=i=>t.getComponent("grid",i)?.coordinateSystem?.getRect();J.render(this.overlayContainer,this._lastTables,e)}destroy(){this.stopCountdown(),window.removeEventListener("resize",this.resize.bind(this)),document.removeEventListener("fullscreenchange",this.onFullscreenChange),document.removeEventListener("keydown",this.onKeyDown),this.pluginManager.deactivatePlugin(),this.pluginManager.destroy(),this.chart.dispose()}rebuildTimeIndex(){this.timeToIndex.clear(),this.marketData.forEach((i,s)=>{this.timeToIndex.set(i.time,s)});const t=this.marketData.length,e=Math.ceil(t*this.padding);this.dataIndexOffset=e}render(){if(this.marketData.length===0)return;let t=null;try{const v=this.chart.getOption();if(v&&v.dataZoom&&v.dataZoom.length>0){const y=v.dataZoom.find(b=>b.type==="slider"||b.type==="inside");y&&(t={start:y.start,end:y.end})}}catch{}const e=this.options.databox?.position,i=this.leftSidebar.style.display,s=this.rightSidebar.style.display,a=e==="left"?"block":"none",o=e==="right"?"block":"none";(i!==a||s!==o)&&(this.leftSidebar.style.display=a,this.rightSidebar.style.display=o,this.chart.resize());const u=this.dataIndexOffset,d=[...Array(u).fill(""),...this.marketData.map(v=>new Date(v.time).toLocaleString()),...Array(u).fill("")],p=At.calculate(this.chart.getHeight(),this.indicators,this.options,this.isMainCollapsed,this.maximizedPaneId,this.marketData,this._mainHeightOverride??void 0);if(this._lastLayout=p,!t&&p.dataZoom&&this.marketData.length>0){const v=this.marketData.length,y=d.length,b=u/y,_=v/y;p.dataZoom.forEach(I=>{if(I.start!==void 0){const P=I.start/100,k=b+P*_;I.start=k*100}if(I.end!==void 0){const P=I.end/100,k=b+P*_;I.end=k*100}})}t&&p.dataZoom&&p.dataZoom.forEach(v=>{v.start=t.start,v.end=t.end}),p.xAxis.forEach(v=>{v.data=d,v.boundaryGap=!1});const g=gt.buildCandlestickSeries(this.marketData,this.options),r={value:[NaN,NaN,NaN,NaN],itemStyle:{opacity:0}};g.data=[...Array(u).fill(r),...g.data,...Array(u).fill(r)];const l=[...Array(u).fill(null),...this.marketData,...Array(u).fill(null)],{series:h,barColors:n}=gt.buildIndicatorSeries(this.indicators,this.timeToIndex,p.paneLayout,d.length,u,l,p.overlayYAxisMap,p.separatePaneYAxisOffset);g.data=g.data.map((v,y)=>n[y]?{value:v.value||v,itemStyle:{color:n[y],color0:n[y],borderColor:n[y],borderColor0:n[y]}}:v);const c=Ut.build(p,this.options,this.toggleIndicator.bind(this),this.isMainCollapsed,this.maximizedPaneId),f=new Map;this.drawings.forEach(v=>{const y=v.paneIndex||0;f.has(y)||f.set(y,[]),f.get(y).push(v)});const m=[];f.forEach((v,y)=>{m.push({type:"custom",name:`drawings-pane-${y}`,xAxisIndex:y,yAxisIndex:y,clip:!0,renderItem:(b,_)=>{const I=v[b.dataIndex];if(!I)return;const P=I.points[0],k=I.points[1];if(!P||!k)return;const D=_.coord([P.timeIndex,P.value]),M=_.coord([k.timeIndex,k.value]),$=I.id===this.selectedDrawingId;if(I.type==="line")return{type:"group",children:[{type:"line",name:"line",shape:{x1:D[0],y1:D[1],x2:M[0],y2:M[1]},style:{stroke:I.style?.color||"#3b82f6",lineWidth:I.style?.lineWidth||2}},{type:"circle",name:"point-start",shape:{cx:D[0],cy:D[1],r:4},style:{fill:"#fff",stroke:I.style?.color||"#3b82f6",lineWidth:1,opacity:$?1:0}},{type:"circle",name:"point-end",shape:{cx:M[0],cy:M[1],r:4},style:{fill:"#fff",stroke:I.style?.color||"#3b82f6",lineWidth:1,opacity:$?1:0}}]};if(I.type==="fibonacci"){const F=D[0],U=D[1],tt=M[0],W=M[1],et=Math.min(F,tt),ot=Math.max(F,tt),it=ot-et,G=W-U,S=[0,.236,.382,.5,.618,.786,1],L=["#787b86","#f44336","#ff9800","#4caf50","#2196f3","#00bcd4","#787b86"],N=[];N.push({type:"line",name:"line",shape:{x1:F,y1:U,x2:tt,y2:W},style:{stroke:"#999",lineWidth:1,lineDash:[4,4]}}),N.push({type:"circle",name:"point-start",shape:{cx:F,cy:U,r:4},style:{fill:"#fff",stroke:I.style?.color||"#3b82f6",lineWidth:1,opacity:$?1:0},z:100}),N.push({type:"circle",name:"point-end",shape:{cx:tt,cy:W,r:4},style:{fill:"#fff",stroke:I.style?.color||"#3b82f6",lineWidth:1,opacity:$?1:0},z:100}),S.forEach((E,T)=>{const B=W-G*E,O=L[T%L.length];N.push({type:"line",name:"fib-line",shape:{x1:et,y1:B,x2:ot,y2:B},style:{stroke:O,lineWidth:1},silent:!0});const j=I.points[0].value,st=I.points[1].value,at=st-j,Q=st-at*E;if(N.push({type:"text",style:{text:`${E} (${Q.toFixed(2)})`,x:et+5,y:B-10,fill:O,fontSize:10},silent:!0}),T<S.length-1){const rt=S[T+1],yt=W-G*rt,wt=Math.abs(yt-B),It=Math.min(B,yt);N.push({type:"rect",shape:{x:et,y:It,width:it,height:wt},style:{fill:L[(T+1)%L.length],opacity:.1},silent:!0})}});const R=[],V=[];return S.forEach((E,T)=>{const B=W-G*E,O=L[T%L.length];V.push({type:"line",shape:{x1:et,y1:B,x2:ot,y2:B},style:{stroke:O,lineWidth:1},silent:!0});const j=I.points[0].value,st=I.points[1].value,at=st-j,Q=st-at*E;if(V.push({type:"text",style:{text:`${E} (${Q.toFixed(2)})`,x:et+5,y:B-10,fill:O,fontSize:10},silent:!0}),T<S.length-1){const rt=S[T+1],yt=W-G*rt,wt=Math.abs(yt-B),It=Math.min(B,yt);R.push({type:"rect",name:"line",shape:{x:et,y:It,width:it,height:wt},style:{fill:L[(T+1)%L.length],opacity:.1}})}}),{type:"group",children:[...R,...V,{type:"line",name:"line",shape:{x1:F,y1:U,x2:tt,y2:W},style:{stroke:"#999",lineWidth:1,lineDash:[4,4]}},{type:"circle",name:"point-start",shape:{cx:F,cy:U,r:4},style:{fill:"#fff",stroke:I.style?.color||"#3b82f6",lineWidth:1,opacity:$?1:0},z:100},{type:"circle",name:"point-end",shape:{cx:tt,cy:W,r:4},style:{fill:"#fff",stroke:I.style?.color||"#3b82f6",lineWidth:1,opacity:$?1:0},z:100}]}}},data:v.map(b=>[b.points[0].timeIndex,b.points[0].value,b.points[1].timeIndex,b.points[1].value]),encode:{x:[0,2],y:[1,3]},z:100,silent:!1})});const w=v=>{const y=Jt.format(v,this.options),b=this.options.databox?.position;return b==="left"?(this.leftSidebar.innerHTML=y,""):b==="right"?(this.rightSidebar.innerHTML=y,""):this.options.databox?`<div style="min-width: 200px;">${y}</div>`:""},C=[];this.indicators.forEach(v=>{Object.values(v.plots).forEach(y=>{y.options?.style==="table"&&y.data?.forEach(b=>{(Array.isArray(b.value)?b.value:[b.value]).forEach(_=>{_&&!_._deleted&&(_._paneIndex=_.force_overlay?0:v.paneIndex,C.push(_))})})})});const A={backgroundColor:this.options.backgroundColor,animation:!1,legend:{show:!1},tooltip:{show:!0,showContent:!!this.options.databox,trigger:"axis",triggerOn:this.options.databox?.triggerOn??"mousemove",axisPointer:{type:"cross",label:{backgroundColor:"#475569"}},backgroundColor:"rgba(30, 41, 59, 0.9)",borderWidth:1,borderColor:"#334155",padding:10,textStyle:{color:"#fff",fontFamily:this.options.fontFamily||"sans-serif"},formatter:w,extraCssText:e!=="floating"&&e!==void 0?"display: none !important;":void 0,position:(v,y,b,_,I)=>{if(this.options.databox?.position==="floating"){const P={top:10};return P[["left","right"][+(v[0]<I.viewSize[0]/2)]]=30,P}return null}},axisPointer:{link:{xAxisIndex:"all"},label:{backgroundColor:"#475569"}},graphic:c,grid:p.grid,xAxis:p.xAxis,yAxis:p.yAxis,dataZoom:p.dataZoom,series:[g,...h,...m]};this.chart.setOption(A,!0),this._lastTables=C,this._renderTableOverlays()}}var de=Object.defineProperty,pe=(x,t,e)=>t in x?de(x,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):x[t]=e,ft=(x,t,e)=>(pe(x,typeof t!="symbol"?t+"":t,e),e);class xt{constructor(t){ft(this,"id"),ft(this,"name"),ft(this,"icon"),ft(this,"context"),ft(this,"eventListeners",[]),this.id=t.id,this.name=t.name,this.icon=t.icon}init(t){this.context=t,this.onInit()}onInit(){}activate(){this.onActivate(),this.context.events.emit("plugin:activated",this.id)}onActivate(){}deactivate(){this.onDeactivate(),this.context.events.emit("plugin:deactivated",this.id)}onDeactivate(){}destroy(){this.removeAllListeners(),this.onDestroy()}onDestroy(){}on(t,e){this.context.events.on(t,e),this.eventListeners.push({event:t,handler:e})}off(t,e){this.context.events.off(t,e),this.eventListeners=this.eventListeners.filter(i=>i.event!==t||i.handler!==e)}removeAllListeners(){this.eventListeners.forEach(({event:t,handler:e})=>{this.context.events.off(t,e)}),this.eventListeners=[]}get chart(){return this.context.getChart()}get marketData(){return this.context.getMarketData()}}var ue=Object.defineProperty,fe=(x,t,e)=>t in x?ue(x,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):x[t]=e,q=(x,t,e)=>(fe(x,typeof t!="symbol"?t+"":t,e),e);class ye extends xt{constructor(t){super({id:"measure",name:t?.name||"Measure",icon:t?.icon||'<svg xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 -960 960 960" width="24px" fill="#e3e3e3"><path d="M160-240q-33 0-56.5-23.5T80-320v-320q0-33 23.5-56.5T160-720h640q33 0 56.5 23.5T880-640v320q0 33-23.5 56.5T800-240H160Zm0-80h640v-320H680v160h-80v-160h-80v160h-80v-160h-80v160h-80v-160H160v320Zm120-160h80-80Zm160 0h80-80Zm160 0h80-80Zm-120 0Z"/></svg>'}),q(this,"zr"),q(this,"state","idle"),q(this,"startPoint",null),q(this,"endPoint",null),q(this,"group",null),q(this,"rect",null),q(this,"labelRect",null),q(this,"labelText",null),q(this,"lineV",null),q(this,"lineH",null),q(this,"arrowStart",null),q(this,"arrowEnd",null),q(this,"onMouseDown",()=>{this.state==="finished"&&this.removeGraphic()}),q(this,"onChartInteraction",()=>{this.group&&this.removeGraphic()}),q(this,"onClick",e=>{this.state==="idle"?(this.state="drawing",this.startPoint=[e.offsetX,e.offsetY],this.endPoint=[e.offsetX,e.offsetY],this.initGraphic(),this.updateGraphic()):this.state==="drawing"&&(this.state="finished",this.endPoint=[e.offsetX,e.offsetY],this.updateGraphic(),this.context.disableTools(),this.enableClearListeners())}),q(this,"clearHandlers",{}),q(this,"onMouseMove",e=>{this.state==="drawing"&&(this.endPoint=[e.offsetX,e.offsetY],this.updateGraphic())})}onInit(){this.zr=this.chart.getZr()}onActivate(){this.state="idle",this.chart.getZr().setCursorStyle("crosshair"),this.zr.on("click",this.onClick),this.zr.on("mousemove",this.onMouseMove)}onDeactivate(){this.state="idle",this.chart.getZr().setCursorStyle("default"),this.zr.off("click",this.onClick),this.zr.off("mousemove",this.onMouseMove),this.disableClearListeners(),this.state==="drawing"&&this.removeGraphic()}onDestroy(){this.removeGraphic()}enableClearListeners(){const t=()=>{this.removeGraphic()};setTimeout(()=>{this.zr.on("click",t)},10),this.zr.on("mousedown",this.onMouseDown),this.context.events.on("chart:dataZoom",this.onChartInteraction),this.clearHandlers={click:t,mousedown:this.onMouseDown,dataZoom:this.onChartInteraction}}disableClearListeners(){this.clearHandlers.click&&this.zr.off("click",this.clearHandlers.click),this.clearHandlers.mousedown&&this.zr.off("mousedown",this.clearHandlers.mousedown),this.clearHandlers.dataZoom&&this.context.events.off("chart:dataZoom",this.clearHandlers.dataZoom),this.clearHandlers={}}initGraphic(){this.group||(this.group=new H.graphic.Group,this.rect=new H.graphic.Rect({shape:{x:0,y:0,width:0,height:0},style:{fill:"rgba(0,0,0,0)",stroke:"transparent",lineWidth:0},z:100}),this.lineV=new H.graphic.Line({shape:{x1:0,y1:0,x2:0,y2:0},style:{stroke:"#fff",lineWidth:1,lineDash:[4,4]},z:101}),this.lineH=new H.graphic.Line({shape:{x1:0,y1:0,x2:0,y2:0},style:{stroke:"#fff",lineWidth:1,lineDash:[4,4]},z:101}),this.arrowStart=new H.graphic.Polygon({shape:{points:[[0,0],[-5,10],[5,10]]},style:{fill:"#fff"},z:102}),this.arrowEnd=new H.graphic.Polygon({shape:{points:[[0,0],[-5,-10],[5,-10]]},style:{fill:"#fff"},z:102}),this.labelRect=new H.graphic.Rect({shape:{x:0,y:0,width:0,height:0,r:4},style:{fill:"transparent",stroke:"transparent",lineWidth:0,shadowBlur:5,shadowColor:"rgba(0,0,0,0.3)"},z:102}),this.labelText=new H.graphic.Text({style:{x:0,y:0,text:"",fill:"#fff",font:"12px sans-serif",align:"center",verticalAlign:"middle"},z:103}),this.group.add(this.rect),this.group.add(this.lineV),this.group.add(this.lineH),this.group.add(this.arrowStart),this.group.add(this.arrowEnd),this.group.add(this.labelRect),this.group.add(this.labelText),this.zr.add(this.group))}removeGraphic(){this.group&&(this.zr.remove(this.group),this.group=null,this.disableClearListeners())}updateGraphic(){if(!this.startPoint||!this.endPoint||!this.group)return;const[t,e]=this.startPoint,[i,s]=this.endPoint,a=this.context.coordinateConversion.pixelToData({x:t,y:e}),o=this.context.coordinateConversion.pixelToData({x:i,y:s});if(!a||!o)return;const u=Math.round(a.timeIndex),d=Math.round(o.timeIndex),p=a.value,g=o.value,r=d-u,l=g-p,h=l/p*100,n=l>=0,c=n?"rgba(33, 150, 243, 0.2)":"rgba(236, 0, 0, 0.2)",f=n?"#2196F3":"#ec0000";this.rect.setShape({x:Math.min(t,i),y:Math.min(e,s),width:Math.abs(i-t),height:Math.abs(s-e)}),this.rect.setStyle({fill:c});const m=(t+i)/2,w=(e+s)/2;this.lineV.setShape({x1:m,y1:e,x2:m,y2:s}),this.lineV.setStyle({stroke:f}),this.lineH.setShape({x1:t,y1:w,x2:i,y2:w}),this.lineH.setStyle({stroke:f});const C=Math.min(e,s),A=Math.max(e,s);this.arrowStart.setStyle({fill:"none"}),this.arrowEnd.setStyle({fill:"none"}),n?(this.arrowStart.setShape({points:[[m,C],[m-4,C+6],[m+4,C+6]]}),this.arrowStart.setStyle({fill:f})):(this.arrowEnd.setShape({points:[[m,A],[m-4,A-6],[m+4,A-6]]}),this.arrowEnd.setStyle({fill:f}));const v=[`${l.toFixed(2)} (${h.toFixed(2)}%)`,`${r} bars, ${(r*0).toFixed(0)}d`].join(`
|
|
38
|
-
`),y=140,b=40,_=Math.max(e,s),I=Math.min(e,s);let P=(t+i)/2-y/2,k=_+10;const D=this.chart.getHeight();k+b>D&&(k=I-b-10),this.labelRect.setShape({x:P,y:k,width:y,height:b}),this.labelRect.setStyle({fill:"#1e293b",stroke:f,lineWidth:1}),this.labelText.setStyle({x:P+y/2,y:k+b/2,text:v,fill:"#fff"})}}var ge=Object.defineProperty,xe=(x,t,e)=>t in x?ge(x,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):x[t]=e,K=(x,t,e)=>(xe(x,typeof t!="symbol"?t+"":t,e),e);class me extends xt{constructor(t){super({id:"trend-line",name:t?.name||"Trend Line",icon:t?.icon||'<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><line x1="2" y1="22" x2="22" y2="2" /></svg>'}),K(this,"zr"),K(this,"state","idle"),K(this,"startPoint",null),K(this,"endPoint",null),K(this,"group",null),K(this,"line",null),K(this,"startCircle",null),K(this,"endCircle",null),K(this,"onMouseDown",()=>{}),K(this,"onChartInteraction",()=>{}),K(this,"onClick",e=>{if(this.state==="idle")this.state="drawing",this.startPoint=[e.offsetX,e.offsetY],this.endPoint=[e.offsetX,e.offsetY],this.initGraphic(),this.updateGraphic();else if(this.state==="drawing"){if(this.state="finished",this.endPoint=[e.offsetX,e.offsetY],this.updateGraphic(),this.startPoint&&this.endPoint){const i=this.context.coordinateConversion.pixelToData({x:this.startPoint[0],y:this.startPoint[1]}),s=this.context.coordinateConversion.pixelToData({x:this.endPoint[0],y:this.endPoint[1]});if(i&&s){const a=i.paneIndex||0;this.context.addDrawing({id:`line-${Date.now()}`,type:"line",points:[i,s],paneIndex:a,style:{color:"#3b82f6",lineWidth:2}})}}this.removeGraphic(),this.context.disableTools()}}),K(this,"clearHandlers",{}),K(this,"onMouseMove",e=>{this.state==="drawing"&&(this.endPoint=[e.offsetX,e.offsetY],this.updateGraphic())})}onInit(){this.zr=this.chart.getZr()}onActivate(){this.state="idle",this.chart.getZr().setCursorStyle("crosshair"),this.zr.on("click",this.onClick),this.zr.on("mousemove",this.onMouseMove)}onDeactivate(){this.state="idle",this.chart.getZr().setCursorStyle("default"),this.zr.off("click",this.onClick),this.zr.off("mousemove",this.onMouseMove),this.disableClearListeners(),this.state==="drawing"&&this.removeGraphic()}onDestroy(){this.removeGraphic()}saveDataCoordinates(){}updateGraphicFromData(){}enableClearListeners(){}disableClearListeners(){}initGraphic(){this.group||(this.group=new H.graphic.Group,this.line=new H.graphic.Line({shape:{x1:0,y1:0,x2:0,y2:0},style:{stroke:"#3b82f6",lineWidth:2},z:100}),this.startCircle=new H.graphic.Circle({shape:{cx:0,cy:0,r:4},style:{fill:"#fff",stroke:"#3b82f6",lineWidth:1},z:101}),this.endCircle=new H.graphic.Circle({shape:{cx:0,cy:0,r:4},style:{fill:"#fff",stroke:"#3b82f6",lineWidth:1},z:101}),this.group.add(this.line),this.group.add(this.startCircle),this.group.add(this.endCircle),this.zr.add(this.group))}removeGraphic(){this.group&&(this.zr.remove(this.group),this.group=null,this.disableClearListeners())}updateGraphic(){if(!this.startPoint||!this.endPoint||!this.group)return;const[t,e]=this.startPoint,[i,s]=this.endPoint;this.line.setShape({x1:t,y1:e,x2:i,y2:s}),this.startCircle.setShape({cx:t,cy:e}),this.endCircle.setShape({cx:i,cy:s})}}var be=Object.defineProperty,ve=(x,t,e)=>t in x?be(x,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):x[t]=e,lt=(x,t,e)=>(ve(x,typeof t!="symbol"?t+"":t,e),e);class we extends xt{constructor(t={}){super({id:"fibonacci-tool",name:t.name||"Fibonacci Retracement",icon:t.icon||'<svg xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 -960 960 960" width="24px" fill="#e3e3e3"><path d="M120-80v-80h720v80H120Zm0-240v-80h720v80H120Zm0-240v-80h720v80H120Zm0-240v-80h720v80H120Z"/></svg>'}),lt(this,"startPoint",null),lt(this,"endPoint",null),lt(this,"state","idle"),lt(this,"graphicGroup",null),lt(this,"levels",[0,.236,.382,.5,.618,.786,1]),lt(this,"colors",["#787b86","#f44336","#ff9800","#4caf50","#2196f3","#00bcd4","#787b86"]),lt(this,"onClick",e=>{this.state==="idle"?(this.state="drawing",this.startPoint=[e.offsetX,e.offsetY],this.endPoint=[e.offsetX,e.offsetY],this.initGraphic(),this.updateGraphic()):this.state==="drawing"&&(this.state="finished",this.endPoint=[e.offsetX,e.offsetY],this.updateGraphic(),this.saveDrawing(),this.removeGraphic(),this.context.disableTools())}),lt(this,"onMouseMove",e=>{this.state==="drawing"&&(this.endPoint=[e.offsetX,e.offsetY],this.updateGraphic())})}onActivate(){this.state="idle",this.startPoint=null,this.endPoint=null,this.context.getChart().getZr().setCursorStyle("crosshair"),this.bindEvents()}onDeactivate(){this.state="idle",this.startPoint=null,this.endPoint=null,this.removeGraphic(),this.unbindEvents(),this.context.getChart().getZr().setCursorStyle("default")}bindEvents(){const t=this.context.getChart().getZr();t.on("click",this.onClick),t.on("mousemove",this.onMouseMove)}unbindEvents(){const t=this.context.getChart().getZr();t.off("click",this.onClick),t.off("mousemove",this.onMouseMove)}initGraphic(){this.graphicGroup=new H.graphic.Group,this.context.getChart().getZr().add(this.graphicGroup)}removeGraphic(){this.graphicGroup&&(this.context.getChart().getZr().remove(this.graphicGroup),this.graphicGroup=null)}updateGraphic(){if(!this.graphicGroup||!this.startPoint||!this.endPoint)return;this.graphicGroup.removeAll();const t=this.startPoint[0],e=this.startPoint[1],i=this.endPoint[0],s=this.endPoint[1],a=new H.graphic.Line({shape:{x1:t,y1:e,x2:i,y2:s},style:{stroke:"#999",lineWidth:1,lineDash:[4,4]},silent:!0});this.graphicGroup.add(a);const o=Math.min(t,i),u=Math.max(t,i),d=u-o,p=s-e;this.levels.forEach((g,r)=>{const l=s-p*g,h=this.colors[r%this.colors.length],n=new H.graphic.Line({shape:{x1:o,y1:l,x2:u,y2:l},style:{stroke:h,lineWidth:1},silent:!0});if(this.graphicGroup.add(n),r<this.levels.length-1){const c=this.levels[r+1],f=s-p*c,m=Math.abs(f-l),w=Math.min(l,f),C=new H.graphic.Rect({shape:{x:o,y:w,width:d,height:m},style:{fill:this.colors[(r+1)%this.colors.length],opacity:.1},silent:!0});this.graphicGroup.add(C)}})}saveDrawing(){if(!this.startPoint||!this.endPoint)return;const t=this.context.coordinateConversion.pixelToData({x:this.startPoint[0],y:this.startPoint[1]}),e=this.context.coordinateConversion.pixelToData({x:this.endPoint[0],y:this.endPoint[1]});if(t&&e){const i=t.paneIndex||0;this.context.addDrawing({id:`fib-${Date.now()}`,type:"fibonacci",points:[t,e],paneIndex:i,style:{color:"#3b82f6",lineWidth:1}})}}}nt.AbstractPlugin=xt,nt.FibonacciTool=we,nt.LineTool=me,nt.MeasureTool=ye,nt.QFChart=ce});
|
|
35
|
+
<div>${l.marker} <span style="color: #cbd5e1;">${l.displayName}</span></div>
|
|
36
|
+
<div style="font-size: 10px; color: #fff;padding-left:10px;">${f}</div>
|
|
37
|
+
</div>`}),h+="</div>"})}return h}}var ne=Object.defineProperty,ae=(b,t,e)=>t in b?ne(b,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):b[t]=e,bt=(b,t,e)=>(ae(b,typeof t!="symbol"?t+"":t,e),e);class re{constructor(t,e){bt(this,"plugins",new Map),bt(this,"activePluginId",null),bt(this,"context"),bt(this,"toolbarContainer"),bt(this,"tooltipElement",null),bt(this,"hideTimeout",null),this.context=t,this.toolbarContainer=e,this.createTooltip(),this.renderToolbar()}createTooltip(){this.tooltipElement=document.createElement("div"),Object.assign(this.tooltipElement.style,{position:"fixed",display:"none",backgroundColor:"#1e293b",color:"#e2e8f0",padding:"6px 10px",borderRadius:"6px",fontSize:"13px",lineHeight:"1.4",fontWeight:"500",border:"1px solid #334155",zIndex:"9999",pointerEvents:"none",whiteSpace:"nowrap",boxShadow:"0 4px 6px -1px rgba(0, 0, 0, 0.3), 0 2px 4px -1px rgba(0, 0, 0, 0.15)",fontFamily:this.context.getOptions().fontFamily||"sans-serif",transition:"opacity 0.15s ease-in-out, transform 0.15s ease-in-out",opacity:"0",transform:"translateX(-5px)"}),document.body.appendChild(this.tooltipElement)}destroy(){this.tooltipElement&&this.tooltipElement.parentNode&&this.tooltipElement.parentNode.removeChild(this.tooltipElement),this.tooltipElement=null}showTooltip(t,e){if(!this.tooltipElement)return;this.hideTimeout&&(clearTimeout(this.hideTimeout),this.hideTimeout=null);const i=t.getBoundingClientRect();this.tooltipElement.textContent=e,this.tooltipElement.style.display="block";const s=this.tooltipElement.getBoundingClientRect(),n=i.top+(i.height-s.height)/2,a=i.right+10;this.tooltipElement.style.top=`${n}px`,this.tooltipElement.style.left=`${a}px`,requestAnimationFrame(()=>{this.tooltipElement&&(this.tooltipElement.style.opacity="1",this.tooltipElement.style.transform="translateX(0)")})}hideTooltip(){this.tooltipElement&&(this.tooltipElement.style.opacity="0",this.tooltipElement.style.transform="translateX(-5px)",this.hideTimeout&&clearTimeout(this.hideTimeout),this.hideTimeout=setTimeout(()=>{this.tooltipElement&&(this.tooltipElement.style.display="none"),this.hideTimeout=null},150))}register(t){if(this.plugins.has(t.id)){console.warn(`Plugin with id ${t.id} is already registered.`);return}this.plugins.set(t.id,t),t.init(this.context),this.addButton(t)}unregister(t){const e=this.plugins.get(t);e&&(this.activePluginId===t&&this.deactivatePlugin(),e.destroy?.(),this.plugins.delete(t),this.removeButton(t))}activatePlugin(t){if(this.activePluginId===t){this.deactivatePlugin();return}this.activePluginId&&this.deactivatePlugin();const e=this.plugins.get(t);e&&(this.activePluginId=t,this.setButtonActive(t,!0),e.activate?.())}deactivatePlugin(){this.activePluginId&&(this.plugins.get(this.activePluginId)?.deactivate?.(),this.setButtonActive(this.activePluginId,!1),this.activePluginId=null)}renderToolbar(){this.toolbarContainer.innerHTML="",this.toolbarContainer.classList.add("qfchart-toolbar"),this.toolbarContainer.style.display="flex",this.toolbarContainer.style.flexDirection="column",this.toolbarContainer.style.width="40px",this.toolbarContainer.style.backgroundColor=this.context.getOptions().backgroundColor||"#1e293b",this.toolbarContainer.style.borderRight="1px solid #334155",this.toolbarContainer.style.padding="5px",this.toolbarContainer.style.boxSizing="border-box",this.toolbarContainer.style.gap="5px",this.toolbarContainer.style.flexShrink="0"}addButton(t){const e=document.createElement("button");e.id=`qfchart-plugin-btn-${t.id}`,e.style.width="30px",e.style.height="30px",e.style.padding="4px",e.style.border="1px solid transparent",e.style.borderRadius="4px",e.style.backgroundColor="transparent",e.style.cursor="pointer",e.style.color=this.context.getOptions().fontColor||"#cbd5e1",e.style.display="flex",e.style.alignItems="center",e.style.justifyContent="center",t.icon?e.innerHTML=t.icon:e.innerText=(t.name||t.id).substring(0,2).toUpperCase(),e.addEventListener("mouseenter",()=>{this.activePluginId!==t.id&&(e.style.backgroundColor="rgba(255, 255, 255, 0.1)"),this.showTooltip(e,t.name||t.id)}),e.addEventListener("mouseleave",()=>{this.activePluginId!==t.id&&(e.style.backgroundColor="transparent"),this.hideTooltip()}),e.onclick=()=>this.activatePlugin(t.id),this.toolbarContainer.appendChild(e)}removeButton(t){const e=this.toolbarContainer.querySelector(`#qfchart-plugin-btn-${t}`);e&&e.remove()}setButtonActive(t,e){const i=this.toolbarContainer.querySelector(`#qfchart-plugin-btn-${t}`);i&&(e?(i.style.backgroundColor="#2563eb",i.style.color="#ffffff"):(i.style.backgroundColor="transparent",i.style.color=this.context.getOptions().fontColor||"#cbd5e1"))}}var le=Object.defineProperty,he=(b,t,e)=>t in b?le(b,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):b[t]=e,nt=(b,t,e)=>(he(b,typeof t!="symbol"?t+"":t,e),e);class ce{constructor(t){nt(this,"context"),nt(this,"isEditing",!1),nt(this,"currentDrawing",null),nt(this,"editingPointIndex",null),nt(this,"zr"),nt(this,"editGroup",null),nt(this,"editLine",null),nt(this,"editStartPoint",null),nt(this,"editEndPoint",null),nt(this,"isMovingShape",!1),nt(this,"dragStart",null),nt(this,"initialPixelPoints",[]),nt(this,"onDrawingMouseDown",e=>{if(this.isEditing)return;const i=this.context.getDrawing(e.id);i&&(this.isEditing=!0,this.isMovingShape=!0,this.currentDrawing=JSON.parse(JSON.stringify(i)),this.dragStart={x:e.x,y:e.y},this.initialPixelPoints=i.points.map(s=>{const 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))}),nt(this,"onPointMouseDown",e=>{if(this.isEditing)return;const i=this.context.getDrawing(e.id);i&&(this.isEditing=!0,this.currentDrawing=JSON.parse(JSON.stringify(i)),this.editingPointIndex=e.pointIndex,this.context.lockChart(),this.createEditGraphic(),this.zr.on("mousemove",this.onMouseMove),this.zr.on("mouseup",this.onMouseUp))}),nt(this,"onMouseMove",e=>{if(!this.isEditing||!this.currentDrawing)return;const i=e.offsetX,s=e.offsetY;if(this.isMovingShape&&this.dragStart){const n=i-this.dragStart.x,a=s-this.dragStart.y,d={x:this.initialPixelPoints[0].x+n,y:this.initialPixelPoints[0].y+a},h={x:this.initialPixelPoints[1].x+n,y:this.initialPixelPoints[1].y+a};this.editLine.setShape({x1:d.x,y1:d.y,x2:h.x,y2:h.y}),this.editStartPoint.setShape({cx:d.x,cy:d.y}),this.editEndPoint.setShape({cx:h.x,cy:h.y})}else this.editingPointIndex!==null&&(this.editingPointIndex===0?(this.editLine.setShape({x1:i,y1:s}),this.editStartPoint.setShape({cx:i,cy:s})):(this.editLine.setShape({x2:i,y2:s}),this.editEndPoint.setShape({cx:i,cy:s})))}),nt(this,"onMouseUp",e=>{this.isEditing&&this.finishEditing(e.offsetX,e.offsetY)}),this.context=t,this.zr=this.context.getChart().getZr(),this.bindEvents()}bindEvents(){this.context.events.on("drawing:point:mousedown",this.onPointMouseDown),this.context.events.on("drawing:mousedown",this.onDrawingMouseDown)}createEditGraphic(){if(!this.currentDrawing)return;this.editGroup=new q.graphic.Group;const t=this.currentDrawing.points[0],e=this.currentDrawing.points[1],i=this.context.coordinateConversion.dataToPixel(t),s=this.context.coordinateConversion.dataToPixel(e);!i||!s||(this.editLine=new q.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 q.graphic.Circle({shape:{cx:i.x,cy:i.y,r:5},style:{fill:"#fff",stroke:"#3b82f6",lineWidth:2},z:1e3}),this.editEndPoint=new q.graphic.Circle({shape:{cx:s.x,cy:s.y,r:5},style:{fill:"#fff",stroke:"#3b82f6",lineWidth:2},z:1e3}),this.editGroup.add(this.editLine),this.editGroup.add(this.editStartPoint),this.editGroup.add(this.editEndPoint),this.zr.add(this.editGroup))}finishEditing(t,e){if(this.currentDrawing){if(this.isMovingShape&&this.dragStart){const i=t-this.dragStart.x,s=e-this.dragStart.y,n=this.initialPixelPoints.map((a,d)=>{const h=a.x+i,p=a.y+s;return this.context.coordinateConversion.pixelToData({x:h,y:p})});n.every(a=>a!==null)&&n[0]&&n[1]&&(this.currentDrawing.points[0]=n[0],this.currentDrawing.points[1]=n[1],n[0].paneIndex!==void 0&&(this.currentDrawing.paneIndex=n[0].paneIndex),this.context.updateDrawing(this.currentDrawing))}else if(this.editingPointIndex!==null){const i=this.context.coordinateConversion.pixelToData({x:t,y:e});i&&(this.currentDrawing.points[this.editingPointIndex]=i,this.editingPointIndex===0&&i.paneIndex!==void 0&&(this.currentDrawing.paneIndex=i.paneIndex),this.context.updateDrawing(this.currentDrawing))}this.isEditing=!1,this.isMovingShape=!1,this.dragStart=null,this.initialPixelPoints=[],this.currentDrawing=null,this.editingPointIndex=null,this.editGroup&&(this.zr.remove(this.editGroup),this.editGroup=null),this.zr.off("mousemove",this.onMouseMove),this.zr.off("mouseup",this.onMouseUp),this.context.unlockChart()}}}var de=Object.defineProperty,pe=(b,t,e)=>t in b?de(b,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):b[t]=e,ue=(b,t,e)=>(pe(b,typeof t!="symbol"?t+"":t,e),e);class fe{constructor(){ue(this,"handlers",new Map)}on(t,e){this.handlers.has(t)||this.handlers.set(t,new Set),this.handlers.get(t).add(e)}off(t,e){const i=this.handlers.get(t);i&&i.delete(e)}emit(t,e){const i=this.handlers.get(t);i&&i.forEach(s=>{try{s(e)}catch(n){console.error(`Error in EventBus handler for ${t}:`,n)}})}clear(){this.handlers.clear()}}class at{static safeParseColor(t){if(!t||typeof t!="string")return{color:"#888888",opacity:1};const e=t.match(/rgba?\((\d+),\s*(\d+),\s*(\d+)(?:,\s*([\d.]+))?\)/);if(e){const i=e[4]?parseFloat(e[4]):1;return{color:`rgb(${e[1]},${e[2]},${e[3]})`,opacity:i}}return{color:t,opacity:1}}static render(t,e,i){at.clearAll(t);const s=new Map;for(const n of e)n&&!n._deleted&&s.set(n.position,n);s.forEach(n=>{const a=n._paneIndex??0,d=i?i(a):void 0,h=at.buildTable(n,d);at.positionTable(h,n.position,d),t.appendChild(h)})}static clearAll(t){for(;t.firstChild;)t.removeChild(t.firstChild)}static buildTable(t,e){const i=document.createElement("table"),s=t.border_width??0,n=t.frame_width??0;if(s>0&&t.border_color||n>0&&t.frame_color?(i.style.borderCollapse="separate",i.style.borderSpacing="0"):i.style.borderCollapse="collapse",i.style.pointerEvents="none",i.style.fontSize="14px",i.style.lineHeight="1.4",i.style.fontFamily="sans-serif",i.style.margin="4px",e&&(i.style.maxHeight=e.height+"px",i.style.maxWidth=e.width+"px",i.style.overflow="hidden"),t.bgcolor){const{color:r,opacity:l}=at.safeParseColor(t.bgcolor);i.style.backgroundColor=r,l<1&&(i.style.opacity=String(l))}if(n>0&&t.frame_color){const{color:r}=at.safeParseColor(t.frame_color);i.style.border=`${n}px solid ${r}`}else i.style.border="none";const a=new Map,d=new Set;if(t.merges)for(const r of t.merges){const l=`${r.startCol},${r.startRow}`;a.set(l,{colspan:r.endCol-r.startCol+1,rowspan:r.endRow-r.startRow+1});for(let o=r.startRow;o<=r.endRow;o++)for(let f=r.startCol;f<=r.endCol;f++)o===r.startRow&&f===r.startCol||d.add(`${f},${o}`)}const h=s>0&&!!t.border_color,p=h?at.safeParseColor(t.border_color).color:"",g=t.rows||0,c=t.columns||0;for(let r=0;r<g;r++){const l=document.createElement("tr");for(let o=0;o<c;o++){const f=`${o},${r}`;if(d.has(f))continue;const u=document.createElement("td"),y=a.get(f);y&&(y.colspan>1&&(u.colSpan=y.colspan),y.rowspan>1&&(u.rowSpan=y.rowspan)),h?u.style.border=`${s}px solid ${p}`:u.style.border="none";const I=t.cells?.[r]?.[o];if(I&&!I._merged){if(u.textContent=I.text||"",I.bgcolor&&typeof I.bgcolor=="string"&&I.bgcolor.length>0){const{color:A,opacity:k}=at.safeParseColor(I.bgcolor);u.style.backgroundColor=A,k<1&&(u.style.backgroundColor=I.bgcolor)}if(I.text_color){const{color:A}=at.safeParseColor(I.text_color);u.style.color=A}if(u.style.fontSize=at.getSizePixels(I.text_size)+"px",u.style.textAlign=at.mapHAlign(I.text_halign),u.style.verticalAlign=at.mapVAlign(I.text_valign),I.text_font_family==="monospace"&&(u.style.fontFamily="monospace"),I.width>0)if(e){const A=Math.max(1,I.width*e.width/100);u.style.width=A+"px"}else u.style.width=I.width+"%";if(I.height>0)if(e){const A=Math.max(1,I.height*e.height/100);u.style.height=A+"px"}else u.style.height=I.height+"%";I.tooltip&&(u.title=I.tooltip)}const P=I?.height??0;P>0&&e&&P*e.height/100<4?u.style.padding="0":u.style.padding="4px 6px",u.style.whiteSpace="nowrap",l.appendChild(u)}i.appendChild(l)}return i}static positionTable(t,e,i){t.style.position="absolute";const s=8,n=i?i.y+"px":"0",a=i?i.x+"px":"0",d=i?i.y+i.height-s+"px":"0",h=i?i.x+i.width-s+"px":"0",p=i?i.x+i.width/2+"px":"50%",g=i?i.y+i.height/2+"px":"50%";switch(e){case"top_left":t.style.top=n,t.style.left=a;break;case"top_center":t.style.top=n,t.style.left=p,t.style.transform="translateX(-50%)";break;case"top_right":t.style.top=n,t.style.left=h,t.style.transform="translateX(-100%)";break;case"middle_left":t.style.top=g,t.style.left=a,t.style.transform="translateY(-50%)";break;case"middle_center":t.style.top=g,t.style.left=p,t.style.transform="translate(-50%, -50%)";break;case"middle_right":t.style.top=g,t.style.left=h,t.style.transform="translate(-100%, -50%)";break;case"bottom_left":t.style.top=d,t.style.left=a,t.style.transform="translateY(-100%)";break;case"bottom_center":t.style.top=d,t.style.left=p,t.style.transform="translate(-50%, -100%)";break;case"bottom_right":t.style.top=d,t.style.left=h,t.style.transform="translate(-100%, -100%)";break;default:t.style.top=n,t.style.left=h,t.style.transform="translateX(-100%)";break}}static getSizePixels(t){if(typeof t=="number"&&t>0)return t;switch(t){case"auto":case"size.auto":return 12;case"tiny":case"size.tiny":return 8;case"small":case"size.small":return 10;case"normal":case"size.normal":return 14;case"large":case"size.large":return 20;case"huge":case"size.huge":return 36;default:return 14}}static mapHAlign(t){switch(t){case"left":case"text.align_left":return"left";case"right":case"text.align_right":return"right";case"center":case"text.align_center":default:return"center"}}static mapVAlign(t){switch(t){case"top":case"text.align_top":return"top";case"bottom":case"text.align_bottom":return"bottom";case"center":case"text.align_center":default:return"middle"}}}class tt{static parseColor(t){if(!t||typeof t!="string"||t.length===0)return{color:"",opacity:0};const e=t.match(/rgba?\((\d+),\s*(\d+),\s*(\d+)(?:,\s*([\d.]+))?\)/);if(e){const i=e[4]?parseFloat(e[4]):1;return{color:`rgb(${e[1]},${e[2]},${e[3]})`,opacity:i}}if(/^#[0-9a-fA-F]{8}$/.test(t)){const i=parseInt(t.slice(1,3),16),s=parseInt(t.slice(3,5),16),n=parseInt(t.slice(5,7),16),a=parseInt(t.slice(7,9),16)/255;return{color:`rgb(${i},${s},${n})`,opacity:a}}return{color:t,opacity:1}}static getSizePixels(t){if(typeof t=="number"&&t>0)return t;switch(t){case"auto":case"size.auto":return 11;case"tiny":case"size.tiny":return 8;case"small":case"size.small":return 10;case"normal":case"size.normal":return 12;case"large":case"size.large":return 16;case"huge":case"size.huge":return 24;default:return 12}}static mapHAlign(t){switch(t){case"left":case"text.align_left":return"left";case"right":case"text.align_right":return"right";default:return"center"}}static mapVAlign(t){switch(t){case"top":case"text.align_top":return"top";case"bottom":case"text.align_bottom":return"bottom";default:return"middle"}}static buildGraphicElements(t,e){if(!t||t.length===0)return[];const i=new Map;for(const n of t)n&&!n._deleted&&i.set(n.position,n);const s=[];return i.forEach(n=>{const a=n._paneIndex??0,d=e(a);if(!d)return;const h=tt.buildTableElements(n,d);s.push(...h)}),s}static buildTableElements(t,e){const i=t.rows||0,s=t.columns||0;if(i===0||s===0)return[];const n=t.border_width??0,a=t.frame_width??0,d=n>0&&!!t.border_color,h=a>0&&!!t.frame_color,p=new Map,g=new Set;if(t.merges)for(const m of t.merges){p.set(`${m.startCol},${m.startRow}`,{colspan:m.endCol-m.startCol+1,rowspan:m.endRow-m.startRow+1});for(let z=m.startRow;z<=m.endRow;z++)for(let w=m.startCol;w<=m.endCol;w++)z===m.startRow&&w===m.startCol||g.add(`${w},${z}`)}const c=4,r=2,l=1.25,o=[];for(let m=0;m<i;m++){o[m]=[];for(let z=0;z<s;z++){if(g.has(`${z},${m}`)){o[m][z]={text:"",lines:[],fontSize:12,fontFamily:"sans-serif",textColor:{color:"",opacity:0},bgColor:{color:"",opacity:0},halign:"center",valign:"middle",explicitWidth:0,explicitHeight:0,colspan:1,rowspan:1,skip:!0,padX:0,padY:0};continue}const w=t.cells?.[m]?.[z],H=p.get(`${z},${m}`),F=H?.colspan??1,W=H?.rowspan??1,O=w&&!w._merged&&w.text||"",Z=O?O.split(`
|
|
38
|
+
`):[],X=w?tt.getSizePixels(w.text_size):12,B=w?.text_font_family==="monospace"?"monospace":"sans-serif";let R=0,J=0;w?.width>0&&(R=Math.max(1,w.width*e.width/100)),w?.height>0&&(J=Math.max(1,w.height*e.height/100));const it=J>0&&J<4,wt=it?0:c,dt=it?0:r,E=w&&!w._merged&&w.bgcolor&&typeof w.bgcolor=="string"&&w.bgcolor.length>0?w.bgcolor:"",T=w?.text_color||"";o[m][z]={text:O,lines:Z,fontSize:X,fontFamily:B,textColor:T?tt.parseColor(T):{color:"#e0e0e0",opacity:1},bgColor:E?tt.parseColor(E):{color:"",opacity:0},halign:w?tt.mapHAlign(w.text_halign):"center",valign:w?tt.mapVAlign(w.text_valign):"middle",explicitWidth:R,explicitHeight:J,colspan:F,rowspan:W,skip:!1,padX:wt,padY:dt}}}const f=new Array(s).fill(0),u=new Array(i).fill(0);for(let m=0;m<i;m++)for(let z=0;z<s;z++){const w=o[m][z];if(w.skip||w.colspan>1||w.rowspan>1)continue;const H=tt.measureMultiLineWidth(w.lines,w.fontSize,w.fontFamily),F=Math.max(w.lines.length,1),W=w.explicitWidth>0?w.explicitWidth:H+w.padX*2,O=w.explicitHeight>0?w.explicitHeight:F*w.fontSize*l+w.padY*2;f[z]=Math.max(f[z],W),u[m]=Math.max(u[m],O)}for(let m=0;m<s;m++)f[m]===0&&(f[m]=20);for(let m=0;m<i;m++)u[m]===0&&(u[m]=4);for(let m=0;m<i;m++)for(let z=0;z<s;z++){const w=o[m][z];if(w.skip)continue;const H=Math.max(w.lines.length,1),F=w.explicitHeight>0?w.explicitHeight:H*w.fontSize*l+w.padY*2;if(w.colspan>1){const W=tt.sumRange(f,z,w.colspan),O=tt.measureMultiLineWidth(w.lines,w.fontSize,w.fontFamily),Z=w.explicitWidth>0?w.explicitWidth:O+w.padX*2;if(Z>W){const X=(Z-W)/w.colspan;for(let B=0;B<w.colspan;B++)f[z+B]+=X}w.rowspan===1&&(u[m]=Math.max(u[m],F))}if(w.rowspan>1){const W=tt.sumRange(u,m,w.rowspan);if(F>W){const O=(F-W)/w.rowspan;for(let Z=0;Z<w.rowspan;Z++)u[m+Z]+=O}}}for(let m=0;m<s;m++)f[m]=Math.round(f[m]);for(let m=0;m<i;m++)u[m]=Math.round(u[m]);const y=new Array(s+1).fill(0);for(let m=0;m<s;m++)y[m+1]=y[m]+f[m];const I=new Array(i+1).fill(0);for(let m=0;m<i;m++)I[m+1]=I[m]+u[m];const P=h?a:0,A=y[s]+P*2,k=I[i]+P*2,x=Math.min(A,e.width),v=Math.min(k,e.height),C=tt.computePosition(t.position,e,x,v),S=Math.round(C.x),_=Math.round(C.y),M=[],D=S+P,N=_+P;if(t.bgcolor){const{color:m,opacity:z}=tt.parseColor(t.bgcolor);z>0&&M.push({type:"rect",shape:{x:S,y:_,width:x,height:v},style:{fill:m,opacity:z},silent:!0,z:0,z2:0})}if(h){const{color:m}=tt.parseColor(t.frame_color),z=a/2;M.push({type:"rect",shape:{x:S+z,y:_+z,width:x-a,height:v-a},style:{fill:"none",stroke:m,lineWidth:a},silent:!0,z:0,z2:1})}const L=d?tt.parseColor(t.border_color).color:"";for(let m=0;m<i;m++)for(let z=0;z<s;z++){const w=o[m][z];if(w.skip)continue;const H=D+y[z],F=N+I[m],W=tt.sumRange(f,z,w.colspan),O=tt.sumRange(u,m,w.rowspan);if(H-S>=x||F-_>=v)continue;const Z=Math.min(W,x-(H-S)),X=Math.min(O,v-(F-_));if(w.bgColor.opacity>0&&M.push({type:"rect",shape:{x:H,y:F,width:Z,height:X},style:{fill:w.bgColor.color,opacity:w.bgColor.opacity},silent:!0,z:0,z2:2}),d&&M.push({type:"rect",shape:{x:H,y:F,width:Z,height:X},style:{fill:"none",stroke:L,lineWidth:n},silent:!0,z:0,z2:3}),w.text){let B,R;switch(w.halign){case"left":B=H+w.padX,R="left";break;case"right":B=H+Z-w.padX,R="right";break;default:B=H+Z/2,R="center";break}let J,it;switch(w.valign){case"top":J=F+w.padY,it="top";break;case"bottom":J=F+X-w.padY,it="bottom";break;default:J=F+X/2,it="middle";break}M.push({type:"text",x:B,y:J,style:{text:w.text,fill:w.textColor.color,opacity:w.textColor.opacity,font:`${w.fontSize}px ${w.fontFamily}`,textAlign:R,textVerticalAlign:it,lineHeight:Math.round(w.fontSize*l)},silent:!0,z:0,z2:4})}}return M}static computePosition(t,e,i,s){const n=e.x,a=e.y,d=e.width,h=e.height;switch(t){case"top_left":return{x:n+4,y:a+4};case"top_center":return{x:n+(d-i)/2,y:a+4};case"top_right":return{x:n+d-i-4,y:a+4};case"middle_left":return{x:n+4,y:a+(h-s)/2};case"middle_center":return{x:n+(d-i)/2,y:a+(h-s)/2};case"middle_right":return{x:n+d-i-4,y:a+(h-s)/2};case"bottom_left":return{x:n+4,y:a+h-s-4};case"bottom_center":return{x:n+(d-i)/2,y:a+h-s-4};case"bottom_right":return{x:n+d-i-4,y:a+h-s-4};default:return{x:n+d-i-4,y:a+4}}}static measureMultiLineWidth(t,e,i){if(!t||t.length===0)return 0;const s=i==="monospace"?.6:.55;let n=0;for(const a of t)n=Math.max(n,a.length*e*s);return n}static sumRange(t,e,i){let s=0;for(let n=e;n<e+i&&n<t.length;n++)s+=t[n];return s}}var ge=Object.defineProperty,ye=(b,t,e)=>t in b?ge(b,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):b[t]=e,$=(b,t,e)=>(ye(b,typeof t!="symbol"?t+"":t,e),e);class xe{constructor(t,e={}){$(this,"chart"),$(this,"options"),$(this,"marketData",[]),$(this,"indicators",new Map),$(this,"timeToIndex",new Map),$(this,"pluginManager"),$(this,"drawingEditor"),$(this,"events",new fe),$(this,"isMainCollapsed",!1),$(this,"maximizedPaneId",null),$(this,"countdownInterval",null),$(this,"selectedDrawingId",null),$(this,"drawings",[]),$(this,"coordinateConversion",{pixelToData:a=>{const d=this.chart.getOption();if(!d||!d.grid)return null;const h=d.grid.length;for(let p=0;p<h;p++)if(this.chart.containPixel({gridIndex:p},[a.x,a.y])){this.chart.convertFromPixel({seriesIndex:p},[a.x,a.y]);const g=this.chart.convertFromPixel({gridIndex:p},[a.x,a.y]);if(g)return{timeIndex:Math.round(g[0])-this.dataIndexOffset,value:g[1],paneIndex:p}}return null},dataToPixel:a=>{const d=a.paneIndex||0,h=this.chart.convertToPixel({gridIndex:d},[a.timeIndex+this.dataIndexOffset,a.value]);return h?{x:h[0],y:h[1]}:null}}),$(this,"upColor","#00da3c"),$(this,"downColor","#ec0000"),$(this,"defaultPadding",0),$(this,"padding"),$(this,"dataIndexOffset",0),$(this,"_paddingPoints",0),$(this,"LAZY_MIN_PADDING",5),$(this,"LAZY_MAX_PADDING",500),$(this,"LAZY_CHUNK_SIZE",50),$(this,"LAZY_EDGE_THRESHOLD",10),$(this,"_expandScheduled",!1),$(this,"rootContainer"),$(this,"layoutContainer"),$(this,"toolbarContainer"),$(this,"leftSidebar"),$(this,"rightSidebar"),$(this,"chartContainer"),$(this,"overlayContainer"),$(this,"_lastTables",[]),$(this,"_tableGraphicIds",[]),$(this,"_baseGraphics",[]),$(this,"_labelTooltipEl",null),$(this,"_lastLayout",null),$(this,"_mainHeightOverride",null),$(this,"_paneDragState",null),$(this,"_paneResizeRafId",null),$(this,"onKeyDown",a=>{(a.key==="Delete"||a.key==="Backspace")&&this.selectedDrawingId&&(this.removeDrawing(this.selectedDrawingId),this.selectedDrawingId=null,this.render())}),$(this,"onFullscreenChange",()=>{this.render()}),$(this,"isLocked",!1),$(this,"lockedState",null),this.rootContainer=t,this.options={title:"Market",height:"600px",backgroundColor:"#1e293b",upColor:"#00da3c",downColor:"#ec0000",fontColor:"#cbd5e1",fontFamily:"sans-serif",padding:.01,dataZoom:{visible:!0,position:"top",height:6},layout:{mainPaneHeight:"50%",gap:13},watermark:!0,...e},this.options.upColor&&(this.upColor=this.options.upColor),this.options.downColor&&(this.downColor=this.options.downColor),this.padding=this.options.padding!==void 0?this.options.padding:this.defaultPadding,this.options.height&&(typeof this.options.height=="number"?this.rootContainer.style.height=`${this.options.height}px`:this.rootContainer.style.height=this.options.height),this.rootContainer.innerHTML="",this.layoutContainer=document.createElement("div"),this.layoutContainer.style.display="flex",this.layoutContainer.style.width="100%",this.layoutContainer.style.height="100%",this.layoutContainer.style.overflow="hidden",this.rootContainer.appendChild(this.layoutContainer),this.leftSidebar=document.createElement("div"),this.leftSidebar.style.display="none",this.leftSidebar.style.width="250px",this.leftSidebar.style.flexShrink="0",this.leftSidebar.style.overflowY="auto",this.leftSidebar.style.backgroundColor=this.options.backgroundColor||"#1e293b",this.leftSidebar.style.borderRight="1px solid #334155",this.leftSidebar.style.padding="10px",this.leftSidebar.style.boxSizing="border-box",this.leftSidebar.style.color="#cbd5e1",this.leftSidebar.style.fontSize="12px",this.leftSidebar.style.fontFamily=this.options.fontFamily||"sans-serif",this.layoutContainer.appendChild(this.leftSidebar),this.toolbarContainer=document.createElement("div"),this.layoutContainer.appendChild(this.toolbarContainer),this.chartContainer=document.createElement("div"),this.chartContainer.style.flexGrow="1",this.chartContainer.style.height="100%",this.chartContainer.style.overflow="hidden",this.layoutContainer.appendChild(this.chartContainer),this.rightSidebar=document.createElement("div"),this.rightSidebar.style.display="none",this.rightSidebar.style.width="250px",this.rightSidebar.style.flexShrink="0",this.rightSidebar.style.overflowY="auto",this.rightSidebar.style.backgroundColor=this.options.backgroundColor||"#1e293b",this.rightSidebar.style.borderLeft="1px solid #334155",this.rightSidebar.style.padding="10px",this.rightSidebar.style.boxSizing="border-box",this.rightSidebar.style.color="#cbd5e1",this.rightSidebar.style.fontSize="12px",this.rightSidebar.style.fontFamily=this.options.fontFamily||"sans-serif",this.layoutContainer.appendChild(this.rightSidebar),this.chart=q.init(this.chartContainer),this.chartContainer.style.position="relative",this.overlayContainer=document.createElement("div"),this.overlayContainer.style.cssText="position:absolute;top:0;left:0;width:100%;height:100%;pointer-events:none;z-index:100;overflow:hidden;",this.chartContainer.appendChild(this.overlayContainer),this.pluginManager=new re(this,this.toolbarContainer),this.drawingEditor=new ce(this),this.chart.on("dataZoom",a=>{this.events.emit("chart:dataZoom",a);const d=this.options.databox?.triggerOn,h=this.options.databox?.position;d==="click"&&h==="floating"&&this.chart.dispatchAction({type:"hideTip"}),this._checkEdgeAndExpand()}),this.chart.on("finished",a=>this.events.emit("chart:updated",a)),this.chart.getZr().on("mousedown",a=>{this._paneDragState||this.events.emit("mouse:down",a)}),this.chart.getZr().on("mousemove",a=>{this._paneDragState||this.events.emit("mouse:move",a)}),this.chart.getZr().on("mouseup",a=>this.events.emit("mouse:up",a)),this.chart.getZr().on("click",a=>{this._paneDragState||this.events.emit("mouse:click",a)});const i=this.chart.getZr(),s=i.setCursorStyle,n=this;i.setCursorStyle=function(a){if(n._paneDragState){s.call(this,"row-resize");return}a==="grab"&&(a="crosshair"),s.call(this,a)},this.bindDrawingEvents(),this.bindPaneResizeEvents(),window.addEventListener("resize",this.resize.bind(this)),document.addEventListener("fullscreenchange",this.onFullscreenChange),document.addEventListener("keydown",this.onKeyDown)}bindPaneResizeEvents(){const t=this.chart.getZr(),e=s=>{if(!this._lastLayout||this._lastLayout.paneBoundaries.length===0||this.maximizedPaneId)return null;const n=this.chart.getHeight();if(n<=0)return null;for(const a of this._lastLayout.paneBoundaries){const d=a.yPercent/100*n;if(Math.abs(s-d)<=6){if(a.aboveId==="main"&&this.isMainCollapsed||this.indicators.get(a.belowId)?.collapsed||a.aboveId!=="main"&&this.indicators.get(a.aboveId)?.collapsed)continue;return a}}return null},i=s=>s==="main"?this._lastLayout?.mainPaneHeight??50:this.indicators.get(s)?.height??15;t.on("mousemove",s=>{if(this._paneDragState){const n=s.offsetY-this._paneDragState.startY,a=this.chart.getHeight();if(a<=0)return;const d=n/a*100,h=this._paneDragState.aboveId==="main"?10:5,p=5;let g=this._paneDragState.startAboveHeight+d,c=this._paneDragState.startBelowHeight-d;if(g<h&&(g=h,c=this._paneDragState.startAboveHeight+this._paneDragState.startBelowHeight-h),c<p&&(c=p,g=this._paneDragState.startAboveHeight+this._paneDragState.startBelowHeight-p),this._paneDragState.aboveId==="main")this._mainHeightOverride=g;else{const l=this.indicators.get(this._paneDragState.aboveId);l&&(l.height=g)}const r=this.indicators.get(this._paneDragState.belowId);r&&(r.height=c),this._paneResizeRafId||(this._paneResizeRafId=requestAnimationFrame(()=>{this._paneResizeRafId=null,this.render()})),t.setCursorStyle("row-resize"),s.stop?.();return}e(s.offsetY)&&t.setCursorStyle("row-resize")}),t.on("mousedown",s=>{const n=e(s.offsetY);n&&(this._paneDragState={startY:s.offsetY,aboveId:n.aboveId,belowId:n.belowId,startAboveHeight:i(n.aboveId),startBelowHeight:i(n.belowId)},t.setCursorStyle("row-resize"),s.stop?.())}),t.on("mouseup",()=>{this._paneDragState&&(this._paneDragState=null,this._paneResizeRafId&&(cancelAnimationFrame(this._paneResizeRafId),this._paneResizeRafId=null),this.render())})}bindDrawingEvents(){let t=null;const e=i=>{if(!i||i.componentType!=="series"||!i.seriesName?.startsWith("drawings"))return null;i.seriesIndex;const s=i.seriesName.match(/drawings-pane-(\d+)/);if(!s)return null;const n=parseInt(s[1]),a=this.drawings.filter(h=>(h.paneIndex||0)===n)[i.dataIndex];if(!a)return null;const d=i.event?.target?.name;return{drawing:a,targetName:d,paneIdx:n}};this.chart.on("mouseover",i=>{const s=e(i);if(!s)return;const n=i.event?.target?.parent;if(n){const a=s.drawing.id===this.selectedDrawingId;t&&(clearTimeout(t),t=null),a||n.children().forEach(d=>{d.name&&d.name.startsWith("point")&&d.attr("style",{opacity:1})})}if(s.targetName==="line")this.events.emit("drawing:hover",{id:s.drawing.id,type:s.drawing.type}),this.chart.getZr().setCursorStyle("move");else if(s.targetName?.startsWith("point")){const a=s.targetName==="point-start"?0:1;this.events.emit("drawing:point:hover",{id:s.drawing.id,pointIndex:a}),this.chart.getZr().setCursorStyle("pointer")}}),this.chart.on("mouseout",i=>{const s=e(i);if(!s)return;const n=i.event?.target?.parent;if(s.drawing.id!==this.selectedDrawingId){if(t=setTimeout(()=>{if(n){if(this.selectedDrawingId===s.drawing.id)return;n.children().forEach(a=>{a.name&&a.name.startsWith("point")&&a.attr("style",{opacity:0})})}},50),s.targetName==="line")this.events.emit("drawing:mouseout",{id:s.drawing.id});else if(s.targetName?.startsWith("point")){const a=s.targetName==="point-start"?0:1;this.events.emit("drawing:point:mouseout",{id:s.drawing.id,pointIndex:a})}this.chart.getZr().setCursorStyle("default")}}),this.chart.on("mousedown",i=>{const s=e(i);if(!s)return;const n=i.event?.event||i.event,a=n?.offsetX,d=n?.offsetY;if(s.targetName==="line")this.events.emit("drawing:mousedown",{id:s.drawing.id,x:a,y:d});else if(s.targetName?.startsWith("point")){const h=s.targetName==="point-start"?0:1;this.events.emit("drawing:point:mousedown",{id:s.drawing.id,pointIndex:h,x:a,y:d})}}),this.chart.on("click",i=>{const s=e(i);if(s){if(this.selectedDrawingId!==s.drawing.id&&(this.selectedDrawingId=s.drawing.id,this.events.emit("drawing:selected",{id:s.drawing.id}),this.render()),s.targetName==="line")this.events.emit("drawing:click",{id:s.drawing.id});else if(s.targetName?.startsWith("point")){const 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())}),this._labelTooltipEl=document.createElement("div"),this._labelTooltipEl.style.cssText="position:absolute;display:none;pointer-events:none;z-index:200;background:rgba(30,41,59,0.95);color:#fff;border:1px solid #475569;border-radius:4px;padding:6px 10px;font-size:12px;line-height:1.5;white-space:pre-wrap;max-width:350px;box-shadow:0 2px 8px rgba(0,0,0,0.3);font-family:"+(this.options.fontFamily||"sans-serif")+";",this.chartContainer.appendChild(this._labelTooltipEl),this.chart.on("mouseover",{seriesType:"scatter"},i=>{const s=i.data?._tooltipText;if(!s||!this._labelTooltipEl)return;this._labelTooltipEl.textContent=s,this._labelTooltipEl.style.display="block";const n=this.chartContainer.getBoundingClientRect(),a=i.event?.event;if(a){const d=a.clientX-n.left,h=a.clientY-n.top,p=this._labelTooltipEl.offsetWidth,g=Math.min(d-p/2,n.width-p-8);this._labelTooltipEl.style.left=Math.max(4,g)+"px",this._labelTooltipEl.style.top=h+18+"px"}}),this.chart.on("mouseout",{seriesType:"scatter"},()=>{this._labelTooltipEl&&(this._labelTooltipEl.style.display="none")})}getChart(){return this.chart}getMarketData(){return this.marketData}getTimeToIndex(){return this.timeToIndex}getOptions(){return this.options}disableTools(){this.pluginManager.deactivatePlugin()}registerPlugin(t){this.pluginManager.register(t)}addDrawing(t){this.drawings.push(t),this.render()}removeDrawing(t){const e=this.drawings.findIndex(i=>i.id===t);if(e!==-1){const i=this.drawings[e];this.drawings.splice(e,1),this.events.emit("drawing:deleted",{id:i.id}),this.render()}}getDrawing(t){return this.drawings.find(e=>e.id===t)}updateDrawing(t){const e=this.drawings.findIndex(i=>i.id===t.id);e!==-1&&(this.drawings[e]=t,this.render())}lockChart(){if(this.isLocked)return;this.isLocked=!0;const t=this.chart.getOption();this.chart.setOption({dataZoom:t.dataZoom.map(e=>({...e,disabled:!0})),tooltip:{show:!1}})}unlockChart(){if(!this.isLocked)return;this.isLocked=!1;const t=this.chart.getOption();(this.options.dataZoom||{}).visible,t.dataZoom&&this.chart.setOption({dataZoom:t.dataZoom.map(e=>({...e,disabled:!1})),tooltip:{show:!0}})}setZoom(t,e){this.chart.dispatchAction({type:"dataZoom",start:t,end:e})}setMarketData(t){this.marketData=t,this.rebuildTimeIndex(),this.render()}updateData(t){if(t.length===0)return;const e=new Map;this.marketData.forEach(u=>{e.set(u.time,u)}),t.forEach(u=>{e.has(u.time),e.set(u.time,u)}),this.marketData=Array.from(e.values()).sort((u,y)=>u.time-y.time),this.rebuildTimeIndex();const i=this.dataIndexOffset,s=mt.buildCandlestickSeries(this.marketData,this.options),n={value:[NaN,NaN,NaN,NaN],itemStyle:{opacity:0}},a=[...Array(i).fill(n),...s.data,...Array(i).fill(n)],d=[...Array(i).fill(""),...this.marketData.map(u=>new Date(u.time).toLocaleString()),...Array(i).fill("")],h=this.chart.getOption(),p=_t.calculate(this.chart.getHeight(),this.indicators,this.options,this.isMainCollapsed,this.maximizedPaneId,this.marketData,this._mainHeightOverride??void 0);this._lastLayout=p;const g=[...Array(i).fill(null),...this.marketData,...Array(i).fill(null)],{series:c,barColors:r}=mt.buildIndicatorSeries(this.indicators,this.timeToIndex,p.paneLayout,d.length,i,g,p.overlayYAxisMap,p.separatePaneYAxisOffset),l=a.map((u,y)=>r[y]?{value:u.value||u,itemStyle:{color:r[y],color0:r[y]}}:u),o={xAxis:h.xAxis.map((u,y)=>({data:d})),series:[{data:l,markLine:s.markLine},...c]};this.chart.setOption(o,{notMerge:!1});const f=[];this.indicators.forEach(u=>{Object.values(u.plots).forEach(y=>{y.options?.style==="table"&&y.data?.forEach(I=>{(Array.isArray(I.value)?I.value:[I.value]).forEach(P=>{P&&!P._deleted&&(P._paneIndex=P.force_overlay?0:u.paneIndex,f.push(P))})})})}),this._lastTables=f,this._renderTableOverlays(),this.startCountdown()}startCountdown(){if(this.stopCountdown(),!this.options.lastPriceLine?.showCountdown||this.marketData.length===0)return;let t=this.options.interval;if(!t&&this.marketData.length>=2){const i=this.marketData[this.marketData.length-1],s=this.marketData[this.marketData.length-2];t=i.time-s.time}if(!t)return;const e=()=>{if(this.marketData.length===0)return;const i=this.marketData[this.marketData.length-1].time+t,s=Date.now(),n=i-s;if(n<=0)return;const a=Math.abs(n),d=Math.floor(a/36e5),h=Math.floor(a%36e5/6e4),p=Math.floor(a%6e4/1e3),g=`${d>0?d.toString().padStart(2,"0")+":":""}${h.toString().padStart(2,"0")}:${p.toString().padStart(2,"0")}`,c=this.chart.getOption();if(!c||!c.series)return;const r=c.series.findIndex(I=>I.type==="candlestick");if(r===-1)return;const l=c.series[r];if(!l.markLine||!l.markLine.data||!l.markLine.data[0])return;const o=l.markLine.data[0];o.label.formatter;const f=o.yAxis;let u="";if(this.options.yAxisLabelFormatter)u=this.options.yAxisLabelFormatter(f);else{const I=this.options.yAxisDecimalPlaces!==void 0?this.options.yAxisDecimalPlaces:V.autoDetectDecimals(this.marketData);u=V.formatValue(f,I)}const y=`${u}
|
|
39
|
+
${g}`;this.chart.setOption({series:[{name:this.options.title||"Market",markLine:{data:[{...o,label:{...o.label,formatter:y}}]}}]})};e(),this.countdownInterval=setInterval(e,1e3)}stopCountdown(){this.countdownInterval&&(clearInterval(this.countdownInterval),this.countdownInterval=null)}addIndicator(t,e,i={}){const s=i.overlay!==void 0?i.overlay:i.isOverlay??!1;let n=0;if(!s){let d=0;this.indicators.forEach(h=>{h.paneIndex>d&&(d=h.paneIndex)}),n=d+1}const a=new Tt(t,e,n,{height:i.height,collapsed:!1,titleColor:i.titleColor,controls:i.controls});return this.indicators.set(t,a),this.render(),a}setIndicator(t,e,i=!1){this.addIndicator(t,{[t]:e},{overlay:i})}removeIndicator(t){this.indicators.delete(t),this.render()}toggleIndicator(t,e="collapse"){if(e==="fullscreen"){document.fullscreenElement?document.exitFullscreen():this.rootContainer.requestFullscreen();return}if(e==="maximize"){this.maximizedPaneId===t?this.maximizedPaneId=null:this.maximizedPaneId=t,this.render();return}if(t==="main"){this.isMainCollapsed=!this.isMainCollapsed,this.render();return}const i=this.indicators.get(t);i&&(i.toggleCollapse(),this.render())}resize(){this.chart.resize(),this._renderTableOverlays()}_buildTableGraphics(){const t=this.chart.getModel(),e=s=>t.getComponent("grid",s)?.coordinateSystem?.getRect(),i=tt.buildGraphicElements(this._lastTables,e);this._tableGraphicIds=[];for(let s=0;s<i.length;s++){const n=`__qf_table_${s}`;i[s].id=n,this._tableGraphicIds.push(n)}return i}_renderTableOverlays(){const t=this._buildTableGraphics(),e=[...this._baseGraphics,...t];this.chart.setOption({graphic:e},{replaceMerge:["graphic"]}),at.clearAll(this.overlayContainer)}destroy(){this.stopCountdown(),window.removeEventListener("resize",this.resize.bind(this)),document.removeEventListener("fullscreenchange",this.onFullscreenChange),document.removeEventListener("keydown",this.onKeyDown),this.pluginManager.deactivatePlugin(),this.pluginManager.destroy(),this.chart.dispose()}rebuildTimeIndex(){this.timeToIndex.clear(),this.marketData.forEach((i,s)=>{this.timeToIndex.set(i.time,s)});const t=this.marketData.length,e=Math.ceil(t*this.padding);this._paddingPoints=Math.max(this._paddingPoints,e,this.LAZY_MIN_PADDING),this.dataIndexOffset=this._paddingPoints}expandPadding(t){this._resizePadding(t)}_resizePadding(t){const e=Math.ceil(this.marketData.length*this.padding);if(t=Math.max(t,e,this.LAZY_MIN_PADDING),t=Math.min(t,this.LAZY_MAX_PADDING),t===this._paddingPoints)return;const i=this._paddingPoints,s=this.marketData.length+2*i,n=this.chart.getOption(),a=n?.dataZoom?.find(_=>_.type==="slider"||_.type==="inside"),d=a?a.start/100*s:0,h=a?a.end/100*s:s,p=t-i;this._paddingPoints=t,this.dataIndexOffset=this._paddingPoints;const g=this._paddingPoints,c={value:[NaN,NaN,NaN,NaN],itemStyle:{opacity:0}},r=mt.buildCandlestickSeries(this.marketData,this.options),l=[...Array(g).fill(c),...r.data,...Array(g).fill(c)],o=[...Array(g).fill(""),...this.marketData.map(_=>new Date(_.time).toLocaleString()),...Array(g).fill("")],f=[...Array(g).fill(null),...this.marketData,...Array(g).fill(null)],u=_t.calculate(this.chart.getHeight(),this.indicators,this.options,this.isMainCollapsed,this.maximizedPaneId,this.marketData,this._mainHeightOverride??void 0),{series:y,barColors:I}=mt.buildIndicatorSeries(this.indicators,this.timeToIndex,u.paneLayout,o.length,g,f,u.overlayYAxisMap,u.separatePaneYAxisOffset),P=l.map((_,M)=>I[M]?{value:_.value||_,itemStyle:{color:I[M],color0:I[M]}}:_),A=this.marketData.length+2*t,k=Math.max(0,(d+p)/A*100),x=Math.min(100,(h+p)/A*100),v=[],C=new Map;this.drawings.forEach(_=>{const M=_.paneIndex||0;C.has(M)||C.set(M,[]),C.get(M).push(_)}),C.forEach(_=>{v.push({data:_.map(M=>[M.points[0].timeIndex+this.dataIndexOffset,M.points[0].value,M.points[1].timeIndex+this.dataIndexOffset,M.points[1].value])})});const S={xAxis:n.xAxis.map(()=>({data:o})),dataZoom:[{start:k,end:x},{start:k,end:x}],series:[{data:P,markLine:r.markLine},...y.map(_=>{const M={data:_.data};return _.renderItem&&(M.renderItem=_.renderItem),M}),...v]};this.chart.setOption(S,{notMerge:!1})}_checkEdgeAndExpand(){if(this._expandScheduled)return;const t=this.chart.getOption()?.dataZoom?.find(f=>f.type==="slider"||f.type==="inside");if(!t)return;const e=this._paddingPoints,i=this.marketData.length,s=i+2*e,n=Math.round(t.start/100*s),a=Math.round(t.end/100*s),d=e,h=e+i-1,p=Math.max(0,Math.min(a,h)-Math.max(n,d)+1),g=n<this.LAZY_EDGE_THRESHOLD,c=a>s-this.LAZY_EDGE_THRESHOLD;if((g||c)&&e<this.LAZY_MAX_PADDING&&p>=3){this._expandScheduled=!0,requestAnimationFrame(()=>{this._expandScheduled=!1,this._resizePadding(e+this.LAZY_CHUNK_SIZE)});return}const r=Math.max(0,e-n),l=Math.max(0,a-(e+i-1)),o=Math.max(r+this.LAZY_CHUNK_SIZE,l+this.LAZY_CHUNK_SIZE);e>o+this.LAZY_CHUNK_SIZE&&(this._expandScheduled=!0,requestAnimationFrame(()=>{this._expandScheduled=!1,this._resizePadding(o)}))}render(){if(this.marketData.length===0)return;let t=null;try{const x=this.chart.getOption();if(x&&x.dataZoom&&x.dataZoom.length>0){const v=x.dataZoom.find(C=>C.type==="slider"||C.type==="inside");v&&(t={start:v.start,end:v.end})}}catch{}const e=this.options.databox?.position,i=this.leftSidebar.style.display,s=this.rightSidebar.style.display,n=e==="left"?"block":"none",a=e==="right"?"block":"none";(i!==n||s!==a)&&(this.leftSidebar.style.display=n,this.rightSidebar.style.display=a,this.chart.resize());const d=this.dataIndexOffset,h=[...Array(d).fill(""),...this.marketData.map(x=>new Date(x.time).toLocaleString()),...Array(d).fill("")],p=_t.calculate(this.chart.getHeight(),this.indicators,this.options,this.isMainCollapsed,this.maximizedPaneId,this.marketData,this._mainHeightOverride??void 0);if(this._lastLayout=p,!t&&p.dataZoom&&this.marketData.length>0){const x=this.marketData.length,v=h.length,C=d/v,S=x/v;p.dataZoom.forEach(_=>{if(_.start!==void 0){const M=_.start/100,D=C+M*S;_.start=D*100}if(_.end!==void 0){const M=_.end/100,D=C+M*S;_.end=D*100}})}t&&p.dataZoom&&p.dataZoom.forEach(x=>{x.start=t.start,x.end=t.end}),p.xAxis.forEach(x=>{x.data=h,x.boundaryGap=!1});const g=mt.buildCandlestickSeries(this.marketData,this.options),c={value:[NaN,NaN,NaN,NaN],itemStyle:{opacity:0}};g.data=[...Array(d).fill(c),...g.data,...Array(d).fill(c)];const r=[...Array(d).fill(null),...this.marketData,...Array(d).fill(null)],{series:l,barColors:o}=mt.buildIndicatorSeries(this.indicators,this.timeToIndex,p.paneLayout,h.length,d,r,p.overlayYAxisMap,p.separatePaneYAxisOffset);g.data=g.data.map((x,v)=>o[v]?{value:x.value||x,itemStyle:{color:o[v],color0:o[v]}}:x);const f=[];this.indicators.forEach((x,v)=>{x.paneIndex===0&&f.push({id:v,titleColor:x.titleColor})});const u=se.build(p,this.options,this.toggleIndicator.bind(this),this.isMainCollapsed,this.maximizedPaneId,f),y=new Map;this.drawings.forEach(x=>{const v=x.paneIndex||0;y.has(v)||y.set(v,[]),y.get(v).push(x)});const I=[];y.forEach((x,v)=>{I.push({type:"custom",name:`drawings-pane-${v}`,xAxisIndex:v,yAxisIndex:v,clip:!0,renderItem:(C,S)=>{const _=x[C.dataIndex];if(!_)return;const M=_.points[0],D=_.points[1];if(!M||!D)return;const N=this.dataIndexOffset,L=S.coord([M.timeIndex+N,M.value]),m=S.coord([D.timeIndex+N,D.value]),z=_.id===this.selectedDrawingId;if(_.type==="line")return{type:"group",children:[{type:"line",name:"line",shape:{x1:L[0],y1:L[1],x2:m[0],y2:m[1]},style:{stroke:_.style?.color||"#3b82f6",lineWidth:_.style?.lineWidth||2}},{type:"circle",name:"point-start",shape:{cx:L[0],cy:L[1],r:4},style:{fill:"#fff",stroke:_.style?.color||"#3b82f6",lineWidth:1,opacity:z?1:0}},{type:"circle",name:"point-end",shape:{cx:m[0],cy:m[1],r:4},style:{fill:"#fff",stroke:_.style?.color||"#3b82f6",lineWidth:1,opacity:z?1:0}}]};if(_.type==="fibonacci"){const w=L[0],H=L[1],F=m[0],W=m[1],O=Math.min(w,F),Z=Math.max(w,F),X=Z-O,B=W-H,R=[0,.236,.382,.5,.618,.786,1],J=["#787b86","#f44336","#ff9800","#4caf50","#2196f3","#00bcd4","#787b86"],it=[];it.push({type:"line",name:"line",shape:{x1:w,y1:H,x2:F,y2:W},style:{stroke:"#999",lineWidth:1,lineDash:[4,4]}}),it.push({type:"circle",name:"point-start",shape:{cx:w,cy:H,r:4},style:{fill:"#fff",stroke:_.style?.color||"#3b82f6",lineWidth:1,opacity:z?1:0},z:100}),it.push({type:"circle",name:"point-end",shape:{cx:F,cy:W,r:4},style:{fill:"#fff",stroke:_.style?.color||"#3b82f6",lineWidth:1,opacity:z?1:0},z:100}),R.forEach((E,T)=>{const G=W-B*E,j=J[T%J.length];it.push({type:"line",name:"fib-line",shape:{x1:O,y1:G,x2:Z,y2:G},style:{stroke:j,lineWidth:1},silent:!0});const st=_.points[0].value,Y=_.points[1].value,ot=Y-st,ht=Y-ot*E;if(it.push({type:"text",style:{text:`${E} (${ht.toFixed(2)})`,x:O+5,y:G-10,fill:j,fontSize:10},silent:!0}),T<R.length-1){const U=R[T+1],K=W-B*U,pt=Math.abs(K-G),ut=Math.min(G,K);it.push({type:"rect",shape:{x:O,y:ut,width:X,height:pt},style:{fill:J[(T+1)%J.length],opacity:.1},silent:!0})}});const wt=[],dt=[];return R.forEach((E,T)=>{const G=W-B*E,j=J[T%J.length];dt.push({type:"line",shape:{x1:O,y1:G,x2:Z,y2:G},style:{stroke:j,lineWidth:1},silent:!0});const st=_.points[0].value,Y=_.points[1].value,ot=Y-st,ht=Y-ot*E;if(dt.push({type:"text",style:{text:`${E} (${ht.toFixed(2)})`,x:O+5,y:G-10,fill:j,fontSize:10},silent:!0}),T<R.length-1){const U=R[T+1],K=W-B*U,pt=Math.abs(K-G),ut=Math.min(G,K);wt.push({type:"rect",name:"line",shape:{x:O,y:ut,width:X,height:pt},style:{fill:J[(T+1)%J.length],opacity:.1}})}}),{type:"group",children:[...wt,...dt,{type:"line",name:"line",shape:{x1:w,y1:H,x2:F,y2:W},style:{stroke:"#999",lineWidth:1,lineDash:[4,4]}},{type:"circle",name:"point-start",shape:{cx:w,cy:H,r:4},style:{fill:"#fff",stroke:_.style?.color||"#3b82f6",lineWidth:1,opacity:z?1:0},z:100},{type:"circle",name:"point-end",shape:{cx:F,cy:W,r:4},style:{fill:"#fff",stroke:_.style?.color||"#3b82f6",lineWidth:1,opacity:z?1:0},z:100}]}}},data:x.map(C=>[C.points[0].timeIndex+this.dataIndexOffset,C.points[0].value,C.points[1].timeIndex+this.dataIndexOffset,C.points[1].value]),encode:{x:[0,2],y:[1,3]},z:100,silent:!1})});const P=x=>{const v=oe.format(x,this.options),C=this.options.databox?.position;return C==="left"?(this.leftSidebar.innerHTML=v,""):C==="right"?(this.rightSidebar.innerHTML=v,""):this.options.databox?`<div style="min-width: 200px;">${v}</div>`:""},A=[];this.indicators.forEach(x=>{Object.values(x.plots).forEach(v=>{v.options?.style==="table"&&v.data?.forEach(C=>{(Array.isArray(C.value)?C.value:[C.value]).forEach(S=>{S&&!S._deleted&&(S._paneIndex=S.force_overlay?0:x.paneIndex,A.push(S))})})})});const k={backgroundColor:this.options.backgroundColor,animation:!1,legend:{show:!1},tooltip:{show:!0,showContent:!!this.options.databox,trigger:"axis",triggerOn:this.options.databox?.triggerOn??"mousemove",axisPointer:{type:"cross",label:{backgroundColor:"#475569"}},backgroundColor:"rgba(30, 41, 59, 0.9)",borderWidth:1,borderColor:"#334155",padding:10,textStyle:{color:"#fff",fontFamily:this.options.fontFamily||"sans-serif"},formatter:P,extraCssText:e!=="floating"&&e!==void 0?"display: none !important;":void 0,position:(x,v,C,S,_)=>{if(this.options.databox?.position==="floating"){const M={top:10};return M[["left","right"][+(x[0]<_.viewSize[0]/2)]]=30,M}return null}},axisPointer:{link:{xAxisIndex:"all"},label:{backgroundColor:"#475569"}},graphic:u,grid:p.grid,xAxis:p.xAxis,yAxis:p.yAxis,dataZoom:p.dataZoom,series:[g,...l,...I]};if(this.chart.setOption(k,!0),this._baseGraphics=u,this._lastTables=A,A.length>0){const x=this._buildTableGraphics();if(x.length>0){const v=[...u,...x];this.chart.setOption({graphic:v},{replaceMerge:["graphic"]})}}else this._tableGraphicIds=[];at.clearAll(this.overlayContainer)}}var me=Object.defineProperty,be=(b,t,e)=>t in b?me(b,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):b[t]=e,It=(b,t,e)=>(be(b,typeof t!="symbol"?t+"":t,e),e);class Ct{constructor(t){It(this,"id"),It(this,"name"),It(this,"icon"),It(this,"context"),It(this,"eventListeners",[]),this.id=t.id,this.name=t.name,this.icon=t.icon}init(t){this.context=t,this.onInit()}onInit(){}activate(){this.onActivate(),this.context.events.emit("plugin:activated",this.id)}onActivate(){}deactivate(){this.onDeactivate(),this.context.events.emit("plugin:deactivated",this.id)}onDeactivate(){}destroy(){this.removeAllListeners(),this.onDestroy()}onDestroy(){}on(t,e){this.context.events.on(t,e),this.eventListeners.push({event:t,handler:e})}off(t,e){this.context.events.off(t,e),this.eventListeners=this.eventListeners.filter(i=>i.event!==t||i.handler!==e)}removeAllListeners(){this.eventListeners.forEach(({event:t,handler:e})=>{this.context.events.off(t,e)}),this.eventListeners=[]}get chart(){return this.context.getChart()}get marketData(){return this.context.getMarketData()}}var we=Object.defineProperty,ve=(b,t,e)=>t in b?we(b,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):b[t]=e,et=(b,t,e)=>(ve(b,typeof t!="symbol"?t+"":t,e),e);class Ie extends Ct{constructor(t){super({id:"measure",name:t?.name||"Measure",icon:t?.icon||'<svg xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 -960 960 960" width="24px" fill="#e3e3e3"><path d="M160-240q-33 0-56.5-23.5T80-320v-320q0-33 23.5-56.5T160-720h640q33 0 56.5 23.5T880-640v320q0 33-23.5 56.5T800-240H160Zm0-80h640v-320H680v160h-80v-160h-80v160h-80v-160h-80v160h-80v-160H160v320Zm120-160h80-80Zm160 0h80-80Zm160 0h80-80Zm-120 0Z"/></svg>'}),et(this,"zr"),et(this,"state","idle"),et(this,"startPoint",null),et(this,"endPoint",null),et(this,"group",null),et(this,"rect",null),et(this,"labelRect",null),et(this,"labelText",null),et(this,"lineV",null),et(this,"lineH",null),et(this,"arrowStart",null),et(this,"arrowEnd",null),et(this,"onMouseDown",()=>{this.state==="finished"&&this.removeGraphic()}),et(this,"onChartInteraction",()=>{this.group&&this.removeGraphic()}),et(this,"onClick",e=>{this.state==="idle"?(this.state="drawing",this.startPoint=[e.offsetX,e.offsetY],this.endPoint=[e.offsetX,e.offsetY],this.initGraphic(),this.updateGraphic()):this.state==="drawing"&&(this.state="finished",this.endPoint=[e.offsetX,e.offsetY],this.updateGraphic(),this.context.disableTools(),this.enableClearListeners())}),et(this,"clearHandlers",{}),et(this,"onMouseMove",e=>{this.state==="drawing"&&(this.endPoint=[e.offsetX,e.offsetY],this.updateGraphic())})}onInit(){this.zr=this.chart.getZr()}onActivate(){this.state="idle",this.chart.getZr().setCursorStyle("crosshair"),this.zr.on("click",this.onClick),this.zr.on("mousemove",this.onMouseMove)}onDeactivate(){this.state="idle",this.chart.getZr().setCursorStyle("default"),this.zr.off("click",this.onClick),this.zr.off("mousemove",this.onMouseMove),this.disableClearListeners(),this.state==="drawing"&&this.removeGraphic()}onDestroy(){this.removeGraphic()}enableClearListeners(){const t=()=>{this.removeGraphic()};setTimeout(()=>{this.zr.on("click",t)},10),this.zr.on("mousedown",this.onMouseDown),this.context.events.on("chart:dataZoom",this.onChartInteraction),this.clearHandlers={click:t,mousedown:this.onMouseDown,dataZoom:this.onChartInteraction}}disableClearListeners(){this.clearHandlers.click&&this.zr.off("click",this.clearHandlers.click),this.clearHandlers.mousedown&&this.zr.off("mousedown",this.clearHandlers.mousedown),this.clearHandlers.dataZoom&&this.context.events.off("chart:dataZoom",this.clearHandlers.dataZoom),this.clearHandlers={}}initGraphic(){this.group||(this.group=new q.graphic.Group,this.rect=new q.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 q.graphic.Line({shape:{x1:0,y1:0,x2:0,y2:0},style:{stroke:"#fff",lineWidth:1,lineDash:[4,4]},z:101}),this.lineH=new q.graphic.Line({shape:{x1:0,y1:0,x2:0,y2:0},style:{stroke:"#fff",lineWidth:1,lineDash:[4,4]},z:101}),this.arrowStart=new q.graphic.Polygon({shape:{points:[[0,0],[-5,10],[5,10]]},style:{fill:"#fff"},z:102}),this.arrowEnd=new q.graphic.Polygon({shape:{points:[[0,0],[-5,-10],[5,-10]]},style:{fill:"#fff"},z:102}),this.labelRect=new q.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 q.graphic.Text({style:{x:0,y:0,text:"",fill:"#fff",font:"12px sans-serif",align:"center",verticalAlign:"middle"},z:103}),this.group.add(this.rect),this.group.add(this.lineV),this.group.add(this.lineH),this.group.add(this.arrowStart),this.group.add(this.arrowEnd),this.group.add(this.labelRect),this.group.add(this.labelText),this.zr.add(this.group))}removeGraphic(){this.group&&(this.zr.remove(this.group),this.group=null,this.disableClearListeners())}updateGraphic(){if(!this.startPoint||!this.endPoint||!this.group)return;const[t,e]=this.startPoint,[i,s]=this.endPoint,n=this.context.coordinateConversion.pixelToData({x:t,y:e}),a=this.context.coordinateConversion.pixelToData({x:i,y:s});if(!n||!a)return;const d=Math.round(n.timeIndex),h=Math.round(a.timeIndex),p=n.value,g=a.value,c=h-d,r=g-p,l=r/p*100,o=r>=0,f=o?"rgba(33, 150, 243, 0.2)":"rgba(236, 0, 0, 0.2)",u=o?"#2196F3":"#ec0000";this.rect.setShape({x:Math.min(t,i),y:Math.min(e,s),width:Math.abs(i-t),height:Math.abs(s-e)}),this.rect.setStyle({fill:f});const y=(t+i)/2,I=(e+s)/2;this.lineV.setShape({x1:y,y1:e,x2:y,y2:s}),this.lineV.setStyle({stroke:u}),this.lineH.setShape({x1:t,y1:I,x2:i,y2:I}),this.lineH.setStyle({stroke:u});const P=Math.min(e,s),A=Math.max(e,s);this.arrowStart.setStyle({fill:"none"}),this.arrowEnd.setStyle({fill:"none"}),o?(this.arrowStart.setShape({points:[[y,P],[y-4,P+6],[y+4,P+6]]}),this.arrowStart.setStyle({fill:u})):(this.arrowEnd.setShape({points:[[y,A],[y-4,A-6],[y+4,A-6]]}),this.arrowEnd.setStyle({fill:u}));const k=[`${r.toFixed(2)} (${l.toFixed(2)}%)`,`${c} bars, ${(c*0).toFixed(0)}d`].join(`
|
|
40
|
+
`),x=140,v=40,C=Math.max(e,s),S=Math.min(e,s);let _=(t+i)/2-x/2,M=C+10;const D=this.chart.getHeight();M+v>D&&(M=S-v-10),this.labelRect.setShape({x:_,y:M,width:x,height:v}),this.labelRect.setStyle({fill:"#1e293b",stroke:u,lineWidth:1}),this.labelText.setStyle({x:_+x/2,y:M+v/2,text:k,fill:"#fff"})}}var Ae=Object.defineProperty,Ce=(b,t,e)=>t in b?Ae(b,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):b[t]=e,lt=(b,t,e)=>(Ce(b,typeof t!="symbol"?t+"":t,e),e);class _e extends Ct{constructor(t){super({id:"trend-line",name:t?.name||"Trend Line",icon:t?.icon||'<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><line x1="2" y1="22" x2="22" y2="2" /></svg>'}),lt(this,"zr"),lt(this,"state","idle"),lt(this,"startPoint",null),lt(this,"endPoint",null),lt(this,"group",null),lt(this,"line",null),lt(this,"startCircle",null),lt(this,"endCircle",null),lt(this,"onMouseDown",()=>{}),lt(this,"onChartInteraction",()=>{}),lt(this,"onClick",e=>{if(this.state==="idle")this.state="drawing",this.startPoint=[e.offsetX,e.offsetY],this.endPoint=[e.offsetX,e.offsetY],this.initGraphic(),this.updateGraphic();else if(this.state==="drawing"){if(this.state="finished",this.endPoint=[e.offsetX,e.offsetY],this.updateGraphic(),this.startPoint&&this.endPoint){const i=this.context.coordinateConversion.pixelToData({x:this.startPoint[0],y:this.startPoint[1]}),s=this.context.coordinateConversion.pixelToData({x:this.endPoint[0],y:this.endPoint[1]});if(i&&s){const 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()}}),lt(this,"clearHandlers",{}),lt(this,"onMouseMove",e=>{this.state==="drawing"&&(this.endPoint=[e.offsetX,e.offsetY],this.updateGraphic())})}onInit(){this.zr=this.chart.getZr()}onActivate(){this.state="idle",this.chart.getZr().setCursorStyle("crosshair"),this.zr.on("click",this.onClick),this.zr.on("mousemove",this.onMouseMove)}onDeactivate(){this.state="idle",this.chart.getZr().setCursorStyle("default"),this.zr.off("click",this.onClick),this.zr.off("mousemove",this.onMouseMove),this.disableClearListeners(),this.state==="drawing"&&this.removeGraphic()}onDestroy(){this.removeGraphic()}saveDataCoordinates(){}updateGraphicFromData(){}enableClearListeners(){}disableClearListeners(){}initGraphic(){this.group||(this.group=new q.graphic.Group,this.line=new q.graphic.Line({shape:{x1:0,y1:0,x2:0,y2:0},style:{stroke:"#3b82f6",lineWidth:2},z:100}),this.startCircle=new q.graphic.Circle({shape:{cx:0,cy:0,r:4},style:{fill:"#fff",stroke:"#3b82f6",lineWidth:1},z:101}),this.endCircle=new q.graphic.Circle({shape:{cx:0,cy:0,r:4},style:{fill:"#fff",stroke:"#3b82f6",lineWidth:1},z:101}),this.group.add(this.line),this.group.add(this.startCircle),this.group.add(this.endCircle),this.zr.add(this.group))}removeGraphic(){this.group&&(this.zr.remove(this.group),this.group=null,this.disableClearListeners())}updateGraphic(){if(!this.startPoint||!this.endPoint||!this.group)return;const[t,e]=this.startPoint,[i,s]=this.endPoint;this.line.setShape({x1:t,y1:e,x2:i,y2:s}),this.startCircle.setShape({cx:t,cy:e}),this.endCircle.setShape({cx:i,cy:s})}}var Se=Object.defineProperty,ke=(b,t,e)=>t in b?Se(b,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):b[t]=e,gt=(b,t,e)=>(ke(b,typeof t!="symbol"?t+"":t,e),e);class Me extends Ct{constructor(t={}){super({id:"fibonacci-tool",name:t.name||"Fibonacci Retracement",icon:t.icon||'<svg xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 -960 960 960" width="24px" fill="#e3e3e3"><path d="M120-80v-80h720v80H120Zm0-240v-80h720v80H120Zm0-240v-80h720v80H120Zm0-240v-80h720v80H120Z"/></svg>'}),gt(this,"startPoint",null),gt(this,"endPoint",null),gt(this,"state","idle"),gt(this,"graphicGroup",null),gt(this,"levels",[0,.236,.382,.5,.618,.786,1]),gt(this,"colors",["#787b86","#f44336","#ff9800","#4caf50","#2196f3","#00bcd4","#787b86"]),gt(this,"onClick",e=>{this.state==="idle"?(this.state="drawing",this.startPoint=[e.offsetX,e.offsetY],this.endPoint=[e.offsetX,e.offsetY],this.initGraphic(),this.updateGraphic()):this.state==="drawing"&&(this.state="finished",this.endPoint=[e.offsetX,e.offsetY],this.updateGraphic(),this.saveDrawing(),this.removeGraphic(),this.context.disableTools())}),gt(this,"onMouseMove",e=>{this.state==="drawing"&&(this.endPoint=[e.offsetX,e.offsetY],this.updateGraphic())})}onActivate(){this.state="idle",this.startPoint=null,this.endPoint=null,this.context.getChart().getZr().setCursorStyle("crosshair"),this.bindEvents()}onDeactivate(){this.state="idle",this.startPoint=null,this.endPoint=null,this.removeGraphic(),this.unbindEvents(),this.context.getChart().getZr().setCursorStyle("default")}bindEvents(){const t=this.context.getChart().getZr();t.on("click",this.onClick),t.on("mousemove",this.onMouseMove)}unbindEvents(){const t=this.context.getChart().getZr();t.off("click",this.onClick),t.off("mousemove",this.onMouseMove)}initGraphic(){this.graphicGroup=new q.graphic.Group,this.context.getChart().getZr().add(this.graphicGroup)}removeGraphic(){this.graphicGroup&&(this.context.getChart().getZr().remove(this.graphicGroup),this.graphicGroup=null)}updateGraphic(){if(!this.graphicGroup||!this.startPoint||!this.endPoint)return;this.graphicGroup.removeAll();const t=this.startPoint[0],e=this.startPoint[1],i=this.endPoint[0],s=this.endPoint[1],n=new q.graphic.Line({shape:{x1:t,y1:e,x2:i,y2:s},style:{stroke:"#999",lineWidth:1,lineDash:[4,4]},silent:!0});this.graphicGroup.add(n);const a=Math.min(t,i),d=Math.max(t,i),h=d-a,p=s-e;this.levels.forEach((g,c)=>{const r=s-p*g,l=this.colors[c%this.colors.length],o=new q.graphic.Line({shape:{x1:a,y1:r,x2:d,y2:r},style:{stroke:l,lineWidth:1},silent:!0});if(this.graphicGroup.add(o),c<this.levels.length-1){const f=this.levels[c+1],u=s-p*f,y=Math.abs(u-r),I=Math.min(r,u),P=new q.graphic.Rect({shape:{x:a,y:I,width:h,height:y},style:{fill:this.colors[(c+1)%this.colors.length],opacity:.1},silent:!0});this.graphicGroup.add(P)}})}saveDrawing(){if(!this.startPoint||!this.endPoint)return;const t=this.context.coordinateConversion.pixelToData({x:this.startPoint[0],y:this.startPoint[1]}),e=this.context.coordinateConversion.pixelToData({x:this.endPoint[0],y:this.endPoint[1]});if(t&&e){const i=t.paneIndex||0;this.context.addDrawing({id:`fib-${Date.now()}`,type:"fibonacci",points:[t,e],paneIndex:i,style:{color:"#3b82f6",lineWidth:1}})}}}ct.AbstractPlugin=Ct,ct.FibonacciTool=Me,ct.LineTool=_e,ct.MeasureTool=Ie,ct.QFChart=xe});
|