UNPKG

klinecharts

Version:

Lightweight k-line chart built with html5 canvas

7 lines 190 kB
/** * @license * KLineChart v10.0.0-beta2 * Copyright (c) 2019 lihu. * Licensed under Apache License 2.0 https://www.apache.org/licenses/LICENSE-2.0 */ !function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).klinecharts={})}(this,(function(t){function e(t,s){if(r(t)||r(s))for(const a in s)if(Object.prototype.hasOwnProperty.call(s,a)){const o=t[a],n=s[a];r(n)&&r(o)?e(o,n):t[a]=i(n)}}function i(t){if(!r(t))return t;let e=null;e=s(t)?[]:{};for(const s in t)if(Object.prototype.hasOwnProperty.call(t,s)){const a=t[s];r(a)?e[s]=i(a):e[s]=a}return e}function s(t){return"[object Array]"===Object.prototype.toString.call(t)}function a(t){return"function"==typeof t}function r(t){return"object"==typeof t&&n(t)}function o(t){return"number"==typeof t&&Number.isFinite(t)}function n(t){return null!=t}function l(t){return"boolean"==typeof t}function h(t){return"string"==typeof t}Object.defineProperty(t,Symbol.toStringTag,{value:"Module"});var c=/\\(\\)?/g,d=RegExp("[^.[\\]]+|\\[(?:([^\"'][^[]*)|([\"'])((?:(?!\\2)[^\\\\]|\\\\.)*?)\\2)\\]|(?=(?:\\.|\\[\\])(?:\\.|\\[\\]|$))","g");function u(t,e,i){if(n(t)){const s=[];e.replace(d,((t,...e)=>{let i=t;return n(e[1])?i=e[2].replace(c,"$1"):n(e[0])&&(i=e[0].trim()),s.push(i),""}));let a=t,r=0;const o=s.length;for(;n(a)&&r<o;)a=a?.[s[r++]];return n(a)?a:i??"--"}return i??"--"}function g(t,e,i){const s=function(t,e){const i={};return t.formatToParts(new Date(e)).forEach((({type:t,value:e})=>{switch(t){case"year":i.YYYY=e;break;case"month":i.MM=e;break;case"day":i.DD=e;break;case"hour":i.HH="24"===e?"00":e;break;case"minute":i.mm=e;break;case"second":i.ss=e}})),i}(t,e);return i.replace(/YYYY|MM|DD|HH|mm|ss/g,(t=>s[t]))}function p(t,e){const i=+t;return o(i)?i.toFixed(e??2):`${t}`}function m(t){const e=+t;if(o(e)){if(e>1e9)return+(e/1e9).toFixed(3)+"B";if(e>1e6)return+(e/1e6).toFixed(3)+"M";if(e>1e3)return+(e/1e3).toFixed(3)+"K"}return`${t}`}function _(t,e){const i=`${t}`;if(0===e.length)return i;if(i.includes(".")){const t=i.split(".");return`${t[0].replace(/(\d)(?=(\d{3})+$)/g,(t=>`${t}${e}`))}.${t[1]}`}return i.replace(/(\d)(?=(\d{3})+$)/g,(t=>`${t}${e}`))}function f(t,e){const i=`${t}`;if(new RegExp("\\.0{"+e+",}[1-9][0-9]*$").test(i)){const t=i.split("."),e=t.length-1,s=t[e],a=/0*/.exec(s);if(n(a)){const i=a[0].length;return t[e]=s.replace(/0*/,`0{${i}}`),t.join(".")}}return i}function y(t,e){return t.replace(/\{(\w+)\}/g,((t,i)=>{const s=e[i];return n(s)?s:`{${i}}`}))}var x=null;function v(t){return t.ownerDocument.defaultView?.devicePixelRatio??1}function b(t,e,i){return`${e??"normal"} ${t??12}px ${i??"Helvetica Neue"}`}function C(t,e,i,s){if(!n(x)){const t=document.createElement("canvas"),e=v(t);(x=t.getContext("2d")).scale(e,e)}return x.font=b(e,i,s),Math.round(x.measureText(t).width)}function E(t){const i={width:0,height:0,left:0,right:0,top:0,bottom:0};return n(t)&&e(i,t),i}var w=function(t){return t[t.Main=0]="Main",t[t.Overlay=1]="Overlay",t[t.Separator=2]="Separator",t[t.Drawer=3]="Drawer",t[t.All=4]="All",t}({});function S(t){return a(window.requestAnimationFrame)?window.requestAnimationFrame(t):window.setTimeout(t,20)}function I(t){a(window.cancelAnimationFrame)?window.cancelAnimationFrame(t):window.clearTimeout(t)}var T=class{constructor(t){this._options={duration:500,iterationCount:1},this._currentIterationCount=0,this._running=!1,this._time=0,e(this._options,t)}_loop(){this._running=!0;const t=()=>{if(this._running){const e=(new Date).getTime()-this._time;e<this._options.duration?(this._doFrameCallback?.(e),S(t)):(this.stop(),this._currentIterationCount++,this._currentIterationCount<this._options.iterationCount&&this.start())}};S(t)}doFrame(t){return this._doFrameCallback=t,this}setDuration(t){return this._options.duration=t,this}setIterationCount(t){return this._options.iterationCount=t,this}start(){this._running||(this._time=(new Date).getTime(),this._loop())}stop(){this._running&&this._doFrameCallback?.(this._options.duration),this._running=!1}},P=1,A=(new Date).getTime();function M(t){const e=(new Date).getTime();return e===A?++P:P=1,A=e,`${t??""}${e}_${P}`}function D(t,e){const i=document.createElement(t),s=e??{};for(const a in s)i.style[a]=s[a]??"";return i}function k(t,e,i){let s=0,a=0;for(a=t.length-1;s!==a;){const r=Math.floor((a+s)/2),o=a-s,n=t[r][e];if(i===t[s][e])return s;if(i===t[a][e])return a;if(i===n)return r;if(i>n?s=r:a=r,o<=2)break}return s}function B(t,e){e=Math.max(0,e??0);const i=Math.pow(10,e);return Math.round(t*i)/i}function F(t,e,i){const s=[Number.MIN_SAFE_INTEGER,Number.MAX_SAFE_INTEGER],a=t.length;let r=0;for(;r<a;){const a=t[r];s[0]=Math.max(a[e]??Number.MIN_SAFE_INTEGER,s[0]),s[1]=Math.min(a[i]??Number.MAX_SAFE_INTEGER,s[1]),++r}return s}function R(t){return 0===t?0:Math.log10(t)}function L(t){return Math.pow(10,t)}var O=class{constructor(t){this._holdingTasks=null,this._running=!1,this._callback=t}add(t){this._running?n(this._holdingTasks)?this._holdingTasks={...this._holdingTasks,...t}:this._holdingTasks=t:this._runTask(t)}async _runTask(t){this._running=!0;try{await Promise.all(Object.values(t))}finally{if(this._running=!1,this._callback?.(),n(this._holdingTasks)){const t=this._holdingTasks;this._runTask(t),this._holdingTasks=null}}}clear(){this._holdingTasks=null}},W={PRICE:2,VOLUME:0},Y=class{constructor(){this._callbacks=[]}subscribe(t){this._callbacks.indexOf(t)<0&&this._callbacks.push(t)}unsubscribe(t){if(a(t)){const e=this._callbacks.indexOf(t);e>-1&&this._callbacks.splice(e,1)}else this._callbacks=[]}execute(t){this._callbacks.forEach((e=>{e(t)}))}isEmpty(){return 0===this._callbacks.length}};function z(t){return"transparent"===t||"none"===t||/^[rR][gG][Bb][Aa]\(([\s]*(2[0-4][0-9]|25[0-5]|[01]?[0-9][0-9]?)[\s]*,){3}[\s]*0[\s]*\)$/.test(t)||/^[hH][Ss][Ll][Aa]\(([\s]*(360|3[0-5][0-9]|[012]?[0-9][0-9]?)[\s]*,)([\s]*((100|[0-9][0-9]?)%|0)[\s]*,){2}([\s]*0[\s]*)\)$/.test(t)}function V(t,e){const i=t.replace(/^#/,""),s=parseInt(i,16);return`rgba(${s>>16&255}, ${s>>8&255}, ${255&s}, ${e??1})`}var N={RED:"#F92855",GREEN:"#2DC08E",WHITE:"#FFFFFF",GREY:"#76808F",BLUE:"#1677FF"};function H(){const t={show:!0,color:N.GREY,textOffset:5,textSize:10,textFamily:"Helvetica Neue",textWeight:"normal"};return{type:"candle_solid",bar:{compareRule:"current_open",upColor:N.GREEN,downColor:N.RED,noChangeColor:N.GREY,upBorderColor:N.GREEN,downBorderColor:N.RED,noChangeBorderColor:N.GREY,upWickColor:N.GREEN,downWickColor:N.RED,noChangeWickColor:N.GREY},area:{lineSize:2,lineColor:N.BLUE,smooth:!1,value:"close",backgroundColor:[{offset:0,color:V(N.BLUE,.01)},{offset:1,color:V(N.BLUE,.2)}],point:{show:!0,color:N.BLUE,radius:4,rippleColor:V(N.BLUE,.3),rippleRadius:8,animation:!0,animationDuration:1e3}},priceMark:{show:!0,high:{...t},low:{...t},last:{show:!0,compareRule:"current_open",upColor:N.GREEN,downColor:N.RED,noChangeColor:N.GREY,line:{show:!0,style:"dashed",dashedValue:[4,4],size:1},text:{show:!0,style:"fill",size:12,paddingLeft:4,paddingTop:4,paddingRight:4,paddingBottom:4,borderColor:"transparent",borderStyle:"solid",borderSize:0,borderDashedValue:[2,2],color:N.WHITE,family:"Helvetica Neue",weight:"normal",borderRadius:2},extendTexts:[]}},tooltip:{offsetLeft:4,offsetTop:6,offsetRight:4,offsetBottom:6,showRule:"always",showType:"standard",rect:{position:"fixed",paddingLeft:4,paddingRight:4,paddingTop:4,paddingBottom:4,offsetLeft:4,offsetTop:4,offsetRight:4,offsetBottom:4,borderRadius:4,borderSize:1,borderColor:"#F2F3F5",color:"#FEFEFE"},title:{show:!0,size:14,family:"Helvetica Neue",weight:"normal",color:N.GREY,marginLeft:8,marginTop:4,marginRight:8,marginBottom:4,template:"{ticker} · {period}"},legend:{size:12,family:"Helvetica Neue",weight:"normal",color:N.GREY,marginLeft:8,marginTop:4,marginRight:8,marginBottom:4,defaultValue:"n/a",template:[{title:"time",value:"{time}"},{title:"open",value:"{open}"},{title:"high",value:"{high}"},{title:"low",value:"{low}"},{title:"close",value:"{close}"},{title:"volume",value:"{volume}"}]},features:[]}}}function X(){const t=V(N.GREEN,.7),e=V(N.RED,.7);return{ohlc:{compareRule:"current_open",upColor:t,downColor:e,noChangeColor:N.GREY},bars:[{style:"fill",borderStyle:"solid",borderSize:1,borderDashedValue:[2,2],upColor:t,downColor:e,noChangeColor:N.GREY}],lines:["#FF9600","#935EBD",N.BLUE,"#E11D74","#01C5C4"].map((t=>({style:"solid",smooth:!1,size:1,dashedValue:[2,2],color:t}))),circles:[{style:"fill",borderStyle:"solid",borderSize:1,borderDashedValue:[2,2],upColor:t,downColor:e,noChangeColor:N.GREY}],texts:[{paddingLeft:0,paddingTop:0,paddingRight:0,paddingBottom:0,style:"fill",size:12,color:N.BLUE,family:"Helvetica Neue",weight:"normal",borderStyle:"solid",borderDashedValue:[2,2],borderSize:0,borderColor:"transparent",borderRadius:0,backgroundColor:"transparent"}],lastValueMark:{show:!1,text:{show:!1,style:"fill",color:N.WHITE,size:12,family:"Helvetica Neue",weight:"normal",borderStyle:"solid",borderColor:"transparent",borderSize:0,borderDashedValue:[2,2],paddingLeft:4,paddingTop:4,paddingRight:4,paddingBottom:4,borderRadius:2}},tooltip:{offsetLeft:4,offsetTop:6,offsetRight:4,offsetBottom:6,showRule:"always",showType:"standard",title:{show:!0,showName:!0,showParams:!0,size:12,family:"Helvetica Neue",weight:"normal",color:N.GREY,marginLeft:8,marginTop:4,marginRight:8,marginBottom:4},legend:{size:12,family:"Helvetica Neue",weight:"normal",color:N.GREY,marginLeft:8,marginTop:4,marginRight:8,marginBottom:4,defaultValue:"n/a"},features:[]}}}function $(){return{show:!0,size:"auto",axisLine:{show:!0,color:"#DDDDDD",size:1},tickText:{show:!0,color:N.GREY,size:12,family:"Helvetica Neue",weight:"normal",marginStart:4,marginEnd:6},tickLine:{show:!0,size:1,length:3,color:"#DDDDDD"}}}function G(){const t=V(N.BLUE,.35),e=V(N.BLUE,.25);return{point:{color:N.BLUE,borderColor:t,borderSize:1,radius:5,activeColor:N.BLUE,activeBorderColor:t,activeBorderSize:3,activeRadius:5},line:{style:"solid",smooth:!1,color:N.BLUE,size:1,dashedValue:[2,2]},rect:{style:"fill",color:e,borderColor:N.BLUE,borderSize:1,borderRadius:0,borderStyle:"solid",borderDashedValue:[2,2]},polygon:{style:"fill",color:N.BLUE,borderColor:N.BLUE,borderSize:1,borderStyle:"solid",borderDashedValue:[2,2]},circle:{style:"fill",color:e,borderColor:N.BLUE,borderSize:1,borderStyle:"solid",borderDashedValue:[2,2]},arc:{style:"solid",color:N.BLUE,size:1,dashedValue:[2,2]},text:{style:"fill",color:N.WHITE,size:12,family:"Helvetica Neue",weight:"normal",borderStyle:"solid",borderDashedValue:[2,2],borderSize:1,borderRadius:2,borderColor:N.BLUE,paddingLeft:4,paddingRight:4,paddingTop:4,paddingBottom:4,backgroundColor:N.BLUE}}}var U="default";var Z=class{constructor(t){this.scrollZoomEnabled=!0,this._range={from:0,to:0,range:0,realFrom:0,realTo:0,realRange:0,displayFrom:0,displayTo:0,displayRange:0},this._prevRange={from:0,to:0,range:0,realFrom:0,realTo:0,realRange:0,displayFrom:0,displayTo:0,displayRange:0},this._ticks=[],this._autoCalcTickFlag=!0,this._parent=t}getParent(){return this._parent}buildTicks(t){return this._autoCalcTickFlag&&(this._range=this.createRangeImp()),!(this._prevRange.from===this._range.from&&this._prevRange.to===this._range.to&&!t)&&(this._prevRange=this._range,this._ticks=this.createTicksImp(),!0)}getTicks(){return this._ticks}setRange(t){this._autoCalcTickFlag=!1,this._range=t}getRange(){return this._range}setAutoCalcTickFlag(t){this._autoCalcTickFlag=t}getAutoCalcTickFlag(){return this._autoCalcTickFlag}};function q(t,e,i,s,a){const r=t.result,o=t.figures,l=t.styles,h=u(l,"texts",s.texts),c=h.length,d=u(l,"circles",s.circles),g=d.length,p=u(l,"bars",s.bars),m=p.length,_=u(l,"lines",s.lines),f=_.length;let y,x=0,v=0,b=0,C=0,E=0;o.forEach((o=>{switch(o.type){case"text":E=x,y=h[x%c],x++;break;case"circle":{E=v;const t=d[v%g];y={...t,color:t.noChangeColor},v++;break}case"bar":{E=b;const t=p[b%m];y={...t,color:t.noChangeColor},b++;break}case"line":E=C,y=_[C%f],C++}if(n(o.type)){const n=o.styles?.({data:{prev:r[e-1],current:r[e],next:r[e+1]},indicator:t,barSpace:i,defaultStyles:s});a(o,{...y,...n},E)}}))}var j=class{constructor(t){this.yAxisId=U,this.precision=4,this.calcParams=[],this.shouldOhlc=!1,this.shouldFormatBigNumber=!1,this.visible=!0,this.zLevel=0,this.series="normal",this.figures=[],this.minValue=null,this.maxValue=null,this.styles=null,this.shouldUpdate=(t,e)=>{const i=JSON.stringify(t.calcParams)!==JSON.stringify(e.calcParams)||t.figures!==e.figures||t.calc!==e.calc;return{calc:i,draw:i||t.shortName!==e.shortName||t.paneId!==e.paneId||t.yAxisId!==e.yAxisId||t.series!==e.series||t.minValue!==e.minValue||t.maxValue!==e.maxValue||t.precision!==e.precision||t.shouldOhlc!==e.shouldOhlc||t.shouldFormatBigNumber!==e.shouldFormatBigNumber||t.visible!==e.visible||t.zLevel!==e.zLevel||t.extendData!==e.extendData||t.regenerateFigures!==e.regenerateFigures||t.createTooltipDataSource!==e.createTooltipDataSource||t.draw!==e.draw}},this.calc=()=>[],this.regenerateFigures=null,this.createTooltipDataSource=null,this.draw=null,this.result=[],this._lockSeriesPrecision=!1,this.override(t),this._lockSeriesPrecision=!1}override(t){const{result:s,...r}=this;this._prevIndicator={...i(r),result:s};const{id:l,name:c,shortName:d,precision:u,styles:g,figures:p,calcParams:m,..._}=t;!h(this.id)&&h(l)&&(this.id=l),h(this.name)||(this.name=c??""),this.shortName=d??this.shortName??this.name,o(u)&&(this.precision=u,this._lockSeriesPrecision=!0),n(g)&&(this.styles??={},e(this.styles,g)),e(this,_),n(m)&&(this.calcParams=m,a(this.regenerateFigures)&&(this.figures=this.regenerateFigures(this.calcParams))),this.figures=p??this.figures}setSeriesPrecision(t){this._lockSeriesPrecision||(this.precision=t)}shouldUpdateImp(){const t=this._prevIndicator.zLevel!==this.zLevel,e=this.shouldUpdate(this._prevIndicator,this);return l(e)?{calc:e,draw:e,sort:t}:{...e,sort:t}}async calcImp(t){try{const e=await this.calc(t,this);return this.result=e,!0}catch(e){return!1}}static extend(t){return class extends j{constructor(){super(t)}}}},Q={name:"AO",shortName:"AO",calcParams:[5,34],figures:[{key:"ao",title:"AO: ",type:"bar",baseValue:0,styles:({data:t,indicator:e,defaultStyles:i})=>{const{prev:s,current:a}=t,r=s?.ao??Number.MIN_SAFE_INTEGER,o=a?.ao??Number.MIN_SAFE_INTEGER;let n="";return n=o>r?u(e.styles,"bars[0].upColor",i.bars[0].upColor):u(e.styles,"bars[0].downColor",i.bars[0].downColor),{color:n,style:o>r?"stroke":"fill",borderColor:n}}}],calc:(t,e)=>{const i=e.calcParams,s=Math.max(i[0],i[1]);let a=0,r=0,o=0,n=0;return t.map(((e,l)=>{const h={},c=(e.low+e.high)/2;if(a+=c,r+=c,l>=i[0]-1){o=a/i[0];const e=t[l-(i[0]-1)];a-=(e.low+e.high)/2}if(l>=i[1]-1){n=r/i[1];const e=t[l-(i[1]-1)];r-=(e.low+e.high)/2}return l>=s-1&&(h.ao=o-n),h}))}};var K={name:"BOLL",shortName:"BOLL",series:"price",calcParams:[20,2],precision:2,shouldOhlc:!0,figures:[{key:"up",title:"UP: ",type:"line"},{key:"mid",title:"MID: ",type:"line"},{key:"dn",title:"DN: ",type:"line"}],calc:(t,e)=>{const i=e.calcParams,s=i[0]-1;let a=0;return t.map(((e,r)=>{const o=e.close,n={};if(a+=o,r>=s){n.mid=a/i[0];const e=function(t,e){const i=t.length;let s=0;return t.forEach((t=>{const i=t.close-e;s+=i*i})),s=Math.abs(s),Math.sqrt(s/i)}(t.slice(r-s,r+1),n.mid);n.up=n.mid+i[1]*e,n.dn=n.mid-i[1]*e,a-=t[r-s].close}return n}))}},J={name:"BBI",shortName:"BBI",series:"price",precision:2,calcParams:[3,6,12,24],shouldOhlc:!0,figures:[{key:"bbi",title:"BBI: ",type:"line"}],calc:(t,e)=>{const i=e.calcParams,s=Math.max(...i),a=[],r=[];return t.map(((e,o)=>{const n={},l=e.close;if(i.forEach(((e,i)=>{a[i]=(a[i]??0)+l,o>=e-1&&(r[i]=a[i]/e,a[i]-=t[o-(e-1)].close)})),o>=s-1){let t=0;r.forEach((e=>{t+=e})),n.bbi=t/4}return n}))}},tt={name:"CCI",shortName:"CCI",calcParams:[20],figures:[{key:"cci",title:"CCI: ",type:"line"}],calc:(t,e)=>{const i=e.calcParams,s=i[0]-1;let a=0;const r=[];return t.map(((e,o)=>{const n={},l=(e.high+e.low+e.close)/3;if(a+=l,r.push(l),o>=s){const e=a/i[0],h=r.slice(o-s,o+1);let c=0;h.forEach((t=>{c+=Math.abs(t-e)}));const d=c/i[0];n.cci=0!==d?(l-e)/d/.015:0;const u=(t[o-s].high+t[o-s].low+t[o-s].close)/3;a-=u}return n}))}},et={name:"CR",shortName:"CR",calcParams:[26,10,20,40,60],figures:[{key:"cr",title:"CR: ",type:"line"},{key:"ma1",title:"MA1: ",type:"line"},{key:"ma2",title:"MA2: ",type:"line"},{key:"ma3",title:"MA3: ",type:"line"},{key:"ma4",title:"MA4: ",type:"line"}],calc:(t,e)=>{const i=e.calcParams,s=Math.ceil(i[1]/2.5+1),a=Math.ceil(i[2]/2.5+1),r=Math.ceil(i[3]/2.5+1),o=Math.ceil(i[4]/2.5+1);let n=0;const l=[];let h=0;const c=[];let d=0;const u=[];let g=0;const p=[],m=[];return t.forEach(((e,_)=>{const f={},y=t[_-1]??e,x=(y.high+y.close+y.low+y.open)/4,v=Math.max(0,e.high-x),b=Math.max(0,x-e.low);_>=i[0]-1&&(f.cr=0!==b?v/b*100:0,n+=f.cr,h+=f.cr,d+=f.cr,g+=f.cr,_>=i[0]+i[1]-2&&(l.push(n/i[1]),_>=i[0]+i[1]+s-3&&(f.ma1=l[l.length-1-s]),n-=m[_-(i[1]-1)].cr??0),_>=i[0]+i[2]-2&&(c.push(h/i[2]),_>=i[0]+i[2]+a-3&&(f.ma2=c[c.length-1-a]),h-=m[_-(i[2]-1)].cr??0),_>=i[0]+i[3]-2&&(u.push(d/i[3]),_>=i[0]+i[3]+r-3&&(f.ma3=u[u.length-1-r]),d-=m[_-(i[3]-1)].cr??0),_>=i[0]+i[4]-2&&(p.push(g/i[4]),_>=i[0]+i[4]+o-3&&(f.ma4=p[p.length-1-o]),g-=m[_-(i[4]-1)].cr??0)),m.push(f)})),m}},it={name:"DMA",shortName:"DMA",calcParams:[10,50,10],figures:[{key:"dma",title:"DMA: ",type:"line"},{key:"ama",title:"AMA: ",type:"line"}],calc:(t,e)=>{const i=e.calcParams,s=Math.max(i[0],i[1]);let a=0,r=0,o=0;const n=[];return t.forEach(((e,l)=>{const h={},c=e.close;a+=c,r+=c;let d=0,u=0;if(l>=i[0]-1&&(d=a/i[0],a-=t[l-(i[0]-1)].close),l>=i[1]-1&&(u=r/i[1],r-=t[l-(i[1]-1)].close),l>=s-1){const t=d-u;h.dma=t,o+=t,l>=s+i[2]-2&&(h.ama=o/i[2],o-=n[l-(i[2]-1)].dma??0)}n.push(h)})),n}},st={name:"DMI",shortName:"DMI",calcParams:[14,6],figures:[{key:"pdi",title:"PDI: ",type:"line"},{key:"mdi",title:"MDI: ",type:"line"},{key:"adx",title:"ADX: ",type:"line"},{key:"adxr",title:"ADXR: ",type:"line"}],calc:(t,e)=>{const i=e.calcParams;let s=0,a=0,r=0,o=0,n=0,l=0,h=0,c=0;const d=[];return t.forEach(((e,u)=>{const g={},p=t[u-1]??e,m=p.close,_=e.high,f=e.low,y=_-f,x=Math.abs(_-m),v=Math.abs(m-f),b=_-p.high,C=p.low-f,E=Math.max(Math.max(y,x),v),w=b>0&&b>C?b:0,S=C>0&&C>b?C:0;if(s+=E,a+=w,r+=S,u>=i[0]-1){u>i[0]-1?(o=o-o/i[0]+E,n=n-n/i[0]+w,l=l-l/i[0]+S):(o=s,n=a,l=r);let t=0,e=0;0!==o&&(t=100*n/o,e=100*l/o),g.pdi=t,g.mdi=e;let p=0;e+t!==0&&(p=Math.abs(e-t)/(e+t)*100),h+=p,u>=2*i[0]-2&&(c=u>2*i[0]-2?(c*(i[0]-1)+p)/i[0]:h/i[0],g.adx=c,u>=2*i[0]+i[1]-3&&(g.adxr=((d[u-(i[1]-1)].adx??0)+c)/2))}d.push(g)})),d}},at={name:"MACD",shortName:"MACD",calcParams:[12,26,9],figures:[{key:"dif",title:"DIF: ",type:"line"},{key:"dea",title:"DEA: ",type:"line"},{key:"macd",title:"MACD: ",type:"bar",baseValue:0,styles:({data:t,indicator:e,defaultStyles:i})=>{const{prev:s,current:a}=t,r=s?.macd??Number.MIN_SAFE_INTEGER,o=a?.macd??Number.MIN_SAFE_INTEGER;let n="";return n=o>0?u(e.styles,"bars[0].upColor",i.bars[0].upColor):o<0?u(e.styles,"bars[0].downColor",i.bars[0].downColor):u(e.styles,"bars[0].noChangeColor",i.bars[0].noChangeColor),{style:r<o?"stroke":"fill",color:n,borderColor:n}}}],calc:(t,e)=>{const i=e.calcParams;let s=0,a=0,r=0,o=0,n=0,l=0;const h=Math.max(i[0],i[1]);return t.map(((t,e)=>{const c={},d=t.close;return s+=d,e>=i[0]-1&&(a=e>i[0]-1?(2*d+(i[0]-1)*a)/(i[0]+1):s/i[0]),e>=i[1]-1&&(r=e>i[1]-1?(2*d+(i[1]-1)*r)/(i[1]+1):s/i[1]),e>=h-1&&(o=a-r,c.dif=o,n+=o,e>=h+i[2]-2&&(l=e>h+i[2]-2?(2*o+l*(i[2]-1))/(i[2]+1):n/i[2],c.macd=2*(o-l),c.dea=l)),c}))}},rt={name:"RSI",shortName:"RSI",calcParams:[6,12,24],figures:[{key:"rsi1",title:"RSI1: ",type:"line"},{key:"rsi2",title:"RSI2: ",type:"line"},{key:"rsi3",title:"RSI3: ",type:"line"}],regenerateFigures:t=>t.map(((t,e)=>{const i=e+1;return{key:`rsi${i}`,title:`RSI${i}: `,type:"line"}})),calc:(t,e)=>{const{calcParams:i,figures:s}=e,a=[],r=[];return t.map(((e,o)=>{const n={},l=(t[o-1]??e).close,h=e.close-l;return i.forEach(((e,i)=>{if(h>0?a[i]=(a[i]??0)+h:r[i]=(r[i]??0)+Math.abs(h),o>=e-1){0!==r[i]?n[s[i].key]=100-100/(1+a[i]/r[i]):n[s[i].key]=0;const l=t[o-(e-1)],h=t[o-e]??l,c=l.close-h.close;c>0?a[i]-=c:r[i]-=Math.abs(c)}})),n}))}},ot={name:"KDJ",shortName:"KDJ",calcParams:[9,3,3],figures:[{key:"k",title:"K: ",type:"line"},{key:"d",title:"D: ",type:"line"},{key:"j",title:"J: ",type:"line"}],calc:(t,e)=>{const i=e.calcParams,s=[];return t.forEach(((e,a)=>{const r={},o=e.close;if(a>=i[0]-1){const e=F(t.slice(a-(i[0]-1),a+1),"high","low"),n=e[0],l=e[1],h=n-l,c=(o-l)/(0===h?1:h)*100;r.k=((i[1]-1)*(s[a-1]?.k??50)+c)/i[1],r.d=((i[2]-1)*(s[a-1]?.d??50)+r.k)/i[2],r.j=3*r.k-2*r.d}s.push(r)})),s}},nt={name:"SAR",shortName:"SAR",series:"price",calcParams:[2,2,20],precision:2,shouldOhlc:!0,figures:[{key:"sar",title:"SAR: ",type:"circle",styles:({data:t,indicator:e,defaultStyles:i})=>{const{current:s}=t;return{color:(s?.sar??Number.MIN_SAFE_INTEGER)<((s?.high??0)+(s?.low??0))/2?u(e.styles,"circles[0].upColor",i.circles[0].upColor):u(e.styles,"circles[0].downColor",i.circles[0].downColor)}}}],calc:(t,e)=>{const i=e.calcParams,s=i[0]/100,a=i[1]/100,r=i[2]/100;let o=s,n=-100,l=!1,h=0;return t.map(((e,i)=>{const c=h,d=e.high,u=e.low;if(l){(-100===n||n<d)&&(n=d,o=Math.min(o+a,r)),h=c+o*(n-c);const g=Math.min(t[Math.max(1,i)-1].low,u);h>e.low?(h=n,o=s,n=-100,l=!l):h>g&&(h=g)}else{(-100===n||n>u)&&(n=u,o=Math.min(o+a,r)),h=c+o*(n-c);const s=Math.max(t[Math.max(1,i)-1].high,d);h<e.high?(h=n,o=0,n=-100,l=!l):h<s&&(h=s)}return{high:d,low:u,sar:h}}))}};function lt(){return{key:"volume",title:"VOLUME: ",type:"bar",baseValue:0,styles:({data:t,indicator:e,defaultStyles:i})=>{const s=t.current;let a=u(e.styles,"bars[0].noChangeColor",i.bars[0].noChangeColor);return n(s)&&(s.close>s.open?a=u(e.styles,"bars[0].upColor",i.bars[0].upColor):s.close<s.open&&(a=u(e.styles,"bars[0].downColor",i.bars[0].downColor))),{color:a}}}}var ht={name:"VOL",shortName:"VOL",series:"volume",calcParams:[5,10,20],shouldFormatBigNumber:!0,precision:0,minValue:0,figures:[{key:"ma1",title:"MA5: ",type:"line"},{key:"ma2",title:"MA10: ",type:"line"},{key:"ma3",title:"MA20: ",type:"line"},lt()],regenerateFigures:t=>{const e=t.map(((t,e)=>({key:`ma${e+1}`,title:`MA${t}: `,type:"line"})));return e.push(lt()),e},calc:(t,e)=>{const{calcParams:i,figures:s}=e,a=[];return t.map(((e,r)=>{const o=e.volume??0,n={volume:o,open:e.open,close:e.close};return i.forEach(((e,i)=>{a[i]=(a[i]??0)+o,r>=e-1&&(n[s[i].key]=a[i]/e,a[i]-=t[r-(e-1)].volume??0)})),n}))}},ct={name:"WR",shortName:"WR",calcParams:[6,10,14],figures:[{key:"wr1",title:"WR1: ",type:"line"},{key:"wr2",title:"WR2: ",type:"line"},{key:"wr3",title:"WR3: ",type:"line"}],regenerateFigures:t=>t.map(((t,e)=>({key:`wr${e+1}`,title:`WR${e+1}: `,type:"line"}))),calc:(t,e)=>{const{calcParams:i,figures:s}=e;return t.map(((e,a)=>{const r={},o=e.close;return i.forEach(((e,i)=>{const n=e-1;if(a>=n){const e=F(t.slice(a-n,a+1),"high","low"),l=e[0],h=l-e[1];r[s[i].key]=0===h?0:(o-l)/h*100}})),r}))}},dt={};function ut(t){return dt[t]??null}function gt(t,e){const i=e?.ignoreEvent??!1;return l(i)?!i:!i.includes(t)}[{name:"AVP",shortName:"AVP",series:"price",precision:2,figures:[{key:"avp",title:"AVP: ",type:"line"}],calc:t=>{let e=0,i=0;return t.map((t=>{const s={},a=t.turnover??0,r=t.volume??0;return e+=a,i+=r,0!==i&&(s.avp=e/i),s}))}},Q,{name:"BIAS",shortName:"BIAS",calcParams:[6,12,24],figures:[{key:"bias1",title:"BIAS6: ",type:"line"},{key:"bias2",title:"BIAS12: ",type:"line"},{key:"bias3",title:"BIAS24: ",type:"line"}],regenerateFigures:t=>t.map(((t,e)=>({key:`bias${e+1}`,title:`BIAS${t}: `,type:"line"}))),calc:(t,e)=>{const{calcParams:i,figures:s}=e,a=[];return t.map(((e,r)=>{const o={},n=e.close;return i.forEach(((e,l)=>{if(a[l]=(a[l]??0)+n,r>=e-1){const h=a[l]/i[l];o[s[l].key]=(n-h)/h*100,a[l]-=t[r-(e-1)].close}})),o}))}},K,{name:"BRAR",shortName:"BRAR",calcParams:[26],figures:[{key:"br",title:"BR: ",type:"line"},{key:"ar",title:"AR: ",type:"line"}],calc:(t,e)=>{const i=e.calcParams;let s=0,a=0,r=0,o=0;return t.map(((e,n)=>{const l={},h=e.high,c=e.low,d=e.open,u=(t[n-1]??e).close;if(r+=h-d,o+=d-c,s+=h-u,a+=u-c,n>=i[0]-1){l.ar=0!==o?r/o*100:0,l.br=0!==a?s/a*100:0;const e=t[n-(i[0]-1)],h=e.high,c=e.low,d=e.open,u=(t[n-i[0]]??t[n-(i[0]-1)]).close;s-=h-u,a-=u-c,r-=h-d,o-=d-c}return l}))}},J,tt,et,it,st,{name:"EMV",shortName:"EMV",calcParams:[14,9],figures:[{key:"emv",title:"EMV: ",type:"line"},{key:"maEmv",title:"MAEMV: ",type:"line"}],calc:(t,e)=>{const i=e.calcParams;let s=0;const a=[];return t.map(((e,r)=>{const o={};if(r>0){const n=t[r-1],l=e.high,h=e.low,c=e.volume??0,d=(l+h)/2-(n.high+n.low)/2;o.emv=0===c||l-h==0?0:d/(c/1e8/(l-h)),s+=o.emv,a.push(o.emv),r>=i[0]&&(o.maEmv=s/i[0],s-=a[r-i[0]])}return o}))}},{name:"EMA",shortName:"EMA",series:"price",calcParams:[6,12,20],precision:2,shouldOhlc:!0,figures:[{key:"ema1",title:"EMA6: ",type:"line"},{key:"ema2",title:"EMA12: ",type:"line"},{key:"ema3",title:"EMA20: ",type:"line"}],regenerateFigures:t=>t.map(((t,e)=>({key:`ema${e+1}`,title:`EMA${t}: `,type:"line"}))),calc:(t,e)=>{const{calcParams:i,figures:s}=e;let a=0;const r=[];return t.map(((t,e)=>{const o={},n=t.close;return a+=n,i.forEach(((t,i)=>{e>=t-1&&(r[i]=e>t-1?(2*n+(t-1)*r[i])/(t+1):a/t,o[s[i].key]=r[i])})),o}))}},{name:"MTM",shortName:"MTM",calcParams:[12,6],figures:[{key:"mtm",title:"MTM: ",type:"line"},{key:"maMtm",title:"MAMTM: ",type:"line"}],calc:(t,e)=>{const i=e.calcParams;let s=0;const a=[];return t.forEach(((e,r)=>{const o={};r>=i[0]&&(o.mtm=e.close-t[r-i[0]].close,s+=o.mtm,r>=i[0]+i[1]-1&&(o.maMtm=s/i[1],s-=a[r-(i[1]-1)].mtm??0)),a.push(o)})),a}},{name:"MA",shortName:"MA",series:"price",calcParams:[5,10,30,60],precision:2,shouldOhlc:!0,figures:[{key:"ma1",title:"MA5: ",type:"line"},{key:"ma2",title:"MA10: ",type:"line"},{key:"ma3",title:"MA30: ",type:"line"},{key:"ma4",title:"MA60: ",type:"line"}],regenerateFigures:t=>t.map(((t,e)=>({key:`ma${e+1}`,title:`MA${t}: `,type:"line"}))),calc:(t,e)=>{const{calcParams:i,figures:s}=e,a=[];return t.map(((e,r)=>{const o={},n=e.close;return i.forEach(((e,i)=>{a[i]=(a[i]??0)+n,r>=e-1&&(o[s[i].key]=a[i]/e,a[i]-=t[r-(e-1)].close)})),o}))}},at,{name:"OBV",shortName:"OBV",calcParams:[30],figures:[{key:"obv",title:"OBV: ",type:"line"},{key:"maObv",title:"MAOBV: ",type:"line"}],calc:(t,e)=>{const i=e.calcParams;let s=0,a=0;const r=[];return t.forEach(((e,o)=>{const n=t[o-1]??e;e.close<n.close?a-=e.volume??0:e.close>n.close&&(a+=e.volume??0);const l={obv:a};s+=a,o>=i[0]-1&&(l.maObv=s/i[0],s-=r[o-(i[0]-1)].obv??0),r.push(l)})),r}},{name:"PVT",shortName:"PVT",figures:[{key:"pvt",title:"PVT: ",type:"line"}],calc:t=>{let e=0;return t.map(((i,s)=>{const a={},r=i.close,o=i.volume??1,n=(t[s-1]??i).close;let l=0;const h=n*o;return 0!==h&&(l=(r-n)/h),e+=l,a.pvt=e,a}))}},{name:"PSY",shortName:"PSY",calcParams:[12,6],figures:[{key:"psy",title:"PSY: ",type:"line"},{key:"maPsy",title:"MAPSY: ",type:"line"}],calc:(t,e)=>{const i=e.calcParams;let s=0,a=0;const r=[],o=[];return t.forEach(((e,n)=>{const l={},h=(t[n-1]??e).close,c=e.close-h>0?1:0;r.push(c),s+=c,n>=i[0]-1&&(l.psy=s/i[0]*100,a+=l.psy,n>=i[0]+i[1]-2&&(l.maPsy=a/i[1],a-=o[n-(i[1]-1)].psy??0),s-=r[n-(i[0]-1)]),o.push(l)})),o}},{name:"ROC",shortName:"ROC",calcParams:[12,6],figures:[{key:"roc",title:"ROC: ",type:"line"},{key:"maRoc",title:"MAROC: ",type:"line"}],calc:(t,e)=>{const i=e.calcParams,s=[];let a=0;return t.forEach(((e,r)=>{const o={};if(r>=i[0]-1){const n=e.close,l=(t[r-i[0]]??t[r-(i[0]-1)]).close;o.roc=0!==l?(n-l)/l*100:0,a+=o.roc,r>=i[0]-1+i[1]-1&&(o.maRoc=a/i[1],a-=s[r-(i[1]-1)].roc??0)}s.push(o)})),s}},rt,{name:"SMA",shortName:"SMA",series:"price",calcParams:[12,2],precision:2,figures:[{key:"sma",title:"SMA: ",type:"line"}],shouldOhlc:!0,calc:(t,e)=>{const i=e.calcParams;let s=0,a=0;return t.map(((t,e)=>{const r={},o=t.close;return s+=o,e>=i[0]-1&&(a=e>i[0]-1?(o*i[1]+a*(i[0]-i[1]+1))/(i[0]+1):s/i[0],r.sma=a),r}))}},ot,nt,{name:"TRIX",shortName:"TRIX",calcParams:[12,9],figures:[{key:"trix",title:"TRIX: ",type:"line"},{key:"maTrix",title:"MATRIX: ",type:"line"}],calc:(t,e)=>{const i=e.calcParams;let s=0,a=0,r=0,o=0,n=0,l=0,h=0;const c=[];return t.forEach(((t,e)=>{const d={},u=t.close;if(s+=u,e>=i[0]-1&&(a=e>i[0]-1?(2*u+(i[0]-1)*a)/(i[0]+1):s/i[0],n+=a,e>=2*i[0]-2&&(r=e>2*i[0]-2?(2*a+(i[0]-1)*r)/(i[0]+1):n/i[0],l+=r,e>=3*i[0]-3))){let t=0,s=0;e>3*i[0]-3?(t=(2*r+(i[0]-1)*o)/(i[0]+1),s=(t-o)/o*100):t=l/i[0],o=t,d.trix=s,h+=s,e>=3*i[0]+i[1]-4&&(d.maTrix=h/i[1],h-=c[e-(i[1]-1)].trix??0)}c.push(d)})),c}},ht,{name:"VR",shortName:"VR",calcParams:[26,6],figures:[{key:"vr",title:"VR: ",type:"line"},{key:"maVr",title:"MAVR: ",type:"line"}],calc:(t,e)=>{const i=e.calcParams;let s=0,a=0,r=0,o=0;const n=[];return t.forEach(((e,l)=>{const h={},c=e.close,d=(t[l-1]??e).close,u=e.volume??0;if(c>d?s+=u:c<d?a+=u:r+=u,l>=i[0]-1){const e=r/2;h.vr=a+e===0?0:(s+e)/(a+e)*100,o+=h.vr,l>=i[0]+i[1]-2&&(h.maVr=o/i[1],o-=n[l-(i[1]-1)].vr??0);const c=t[l-(i[0]-1)],d=t[l-i[0]]??c,u=c.close,g=c.volume??0;u>d.close?s-=g:u<d.close?a-=g:r-=g}n.push(h)})),n}},ct].forEach((t=>{dt[t.name]=j.extend(t)}));var pt="overlay_figure_",mt=class{constructor(t){this.groupId="",this.totalStep=1,this.currentStep=1,this.lock=!1,this.visible=!0,this.zLevel=0,this.needDefaultPointFigure=!1,this.needDefaultXAxisFigure=!1,this.needDefaultYAxisFigure=!1,this.mode="normal",this.modeSensitivity=8,this.points=[],this.styles=null,this.createPointFigures=null,this.createXAxisFigures=null,this.createYAxisFigures=null,this.performEventPressedMove=null,this.performEventMoveForDrawing=null,this.onDrawStart=null,this.onDrawing=null,this.onDrawEnd=null,this.onClick=null,this.onDoubleClick=null,this.onRightClick=null,this.onPressedMoveStart=null,this.onPressedMoving=null,this.onPressedMoveEnd=null,this.onMouseMove=null,this.onMouseEnter=null,this.onMouseLeave=null,this.onRemoved=null,this.onSelected=null,this.onDeselected=null,this._prevZLevel=0,this._prevPressedPoint=null,this._prevPressedPoints=[],this.override(t)}override(t){this._prevOverlay=i({...this,_prevOverlay:null});const{id:r,name:o,currentStep:l,points:c,styles:d,...u}=t;if(e(this,u),h(this.name)||(this.name=o??""),!h(this.id)&&h(r)&&(this.id=r),n(d)&&(this.styles??={},e(this.styles,d)),s(c)&&c.length>0){let t=0;if(this.points=[...c],c.length>=this.totalStep-1?(this.currentStep=-1,t=this.totalStep-1):(this.currentStep=c.length+1,t=c.length),a(this.performEventMoveForDrawing))for(let e=0;e<t;e++)this.performEventMoveForDrawing({currentStep:e+2,mode:this.mode,points:this.points,performPointIndex:e,performPoint:this.points[e]});-1===this.currentStep&&this.performEventPressedMove?.({currentStep:this.currentStep,mode:this.mode,points:this.points,performPointIndex:this.points.length-1,performPoint:this.points[this.points.length-1]})}}getPrevZLevel(){return this._prevZLevel}setPrevZLevel(t){this._prevZLevel=t}shouldUpdate(){const t=this._prevOverlay.zLevel!==this.zLevel;return{sort:t,draw:t||JSON.stringify(this._prevOverlay.points)!==JSON.stringify(this.points)||this._prevOverlay.visible!==this.visible||this._prevOverlay.extendData!==this.extendData||this._prevOverlay.styles!==this.styles}}nextStep(){this.currentStep===this.totalStep-1?this.currentStep=-1:this.currentStep++}forceComplete(){this.currentStep=-1}isDrawing(){return-1!==this.currentStep}isStart(){return 1===this.currentStep}eventMoveForDrawing(t){const e=this.currentStep-1,i={};o(t.timestamp)&&(i.timestamp=t.timestamp),o(t.dataIndex)&&(i.dataIndex=t.dataIndex),o(t.value)&&(i.value=t.value),this.points[e]=i,this.performEventMoveForDrawing?.({currentStep:this.currentStep,mode:this.mode,points:this.points,performPointIndex:e,performPoint:i})}eventPressedPointMove(t,e){this.points[e].timestamp=t.timestamp,o(t.value)&&(this.points[e].value=t.value),this.performEventPressedMove?.({currentStep:this.currentStep,points:this.points,mode:this.mode,performPointIndex:e,performPoint:this.points[e]})}startPressedMove(t){this._prevPressedPoint={...t},this._prevPressedPoints=i(this.points)}eventPressedOtherMove(t,e){if(null!==this._prevPressedPoint){let i=null;o(t.dataIndex)&&o(this._prevPressedPoint.dataIndex)&&(i=t.dataIndex-this._prevPressedPoint.dataIndex);let s=null;o(t.value)&&o(this._prevPressedPoint.value)&&(s=t.value-this._prevPressedPoint.value),this.points=this._prevPressedPoints.map((t=>{o(t.timestamp)&&(t.dataIndex=e.timestampToDataIndex(t.timestamp));const a={...t};return o(i)&&o(t.dataIndex)&&(a.dataIndex=t.dataIndex+i,a.timestamp=e.dataIndexToTimestamp(a.dataIndex)??void 0),o(s)&&o(t.value)&&(a.value=t.value+s),a}))}}static extend(t){return class extends mt{constructor(){super(t)}}}},_t={name:"fibonacciLine",totalStep:3,needDefaultPointFigure:!0,needDefaultXAxisFigure:!0,needDefaultYAxisFigure:!0,createPointFigures:({chart:t,coordinates:e,bounding:i,overlay:s,yAxis:a})=>{const r=s.points;if(e.length>0){let n=0;a?.isInCandle()??1?n=t.getSymbol()?.pricePrecision??W.PRICE:t.getIndicators({paneId:s.paneId}).forEach((t=>{n=Math.max(n,t.precision)}));const l=[],h=[],c=0,d=i.width;if(e.length>1&&o(r[0].value)&&o(r[1].value)){const i=[1,.786,.618,.5,.382,.236,0],s=e[0].y-e[1].y,a=r[0].value-r[1].value;i.forEach((i=>{const o=e[1].y+s*i,u=t.getDecimalFold().format(t.getThousandsSeparator().format(((r[1].value??0)+a*i).toFixed(n)));l.push({coordinates:[{x:c,y:o},{x:d,y:o}]}),h.push({x:c,y:o,text:`${u} (${(100*i).toFixed(1)}%)`,baseline:"bottom"})}))}return[{type:"line",attrs:l},{type:"text",isCheckEvent:!1,attrs:h}]}return[]}},ft={name:"horizontalRayLine",totalStep:3,needDefaultPointFigure:!0,needDefaultXAxisFigure:!0,needDefaultYAxisFigure:!0,createPointFigures:({coordinates:t,bounding:e})=>{const i={x:0,y:t[0].y};return n(t[1])&&t[0].x<t[1].x&&(i.x=e.width),[{type:"line",attrs:{coordinates:[t[0],i]}}]},performEventPressedMove:({points:t,performPoint:e})=>{t[0].value=e.value,t[1].value=e.value},performEventMoveForDrawing:({currentStep:t,points:e,performPoint:i})=>{2===t&&(e[0].value=i.value)}},yt=class{constructor(){this._children=[],this._callbacks=new Map}registerEvent(t,e){return this._callbacks.set(t,e),this}onEvent(t,e){const i=this._callbacks.get(t);return!(!n(i)||!this.checkEventOn(e))&&i(e)}dispatchEventToChildren(t,e){const i=this._children.length-1;if(i>-1)for(let s=i;s>-1;s--)if(this._children[s].dispatchEvent(t,e))return!0;return!1}dispatchEvent(t,e){return!!this.dispatchEventToChildren(t,e)||this.onEvent(t,e)}addChild(t){return this._children.push(t),this}clear(){this._children=[]}},xt=class extends yt{constructor(t){super(),this.attrs=t.attrs,this.styles=t.styles}checkEventOn(t){return this.checkEventOnImp(t,this.attrs,this.styles)}setAttrs(t){return this.attrs=t,this}setStyles(t){return this.styles=t,this}draw(t){this.drawImp(t,this.attrs,this.styles)}static extend(t){return class extends xt{checkEventOnImp(e,i,s){return t.checkEventOn(e,i,s)}drawImp(e,i,s){t.draw(e,i,s)}}}};function vt(t,e){let i=[];i=i.concat(e);for(const s of i){const{coordinates:e}=s;if(e.length>1)for(let i=1;i<e.length;i++){const s=e[i-1],a=e[i];if(s.x===a.x){if(Math.abs(s.y-t.y)+Math.abs(a.y-t.y)-Math.abs(s.y-a.y)<4&&Math.abs(t.x-s.x)<2)return!0}else{const e=Et(s,a),i=bt(e,t),r=Math.abs(i-t.y);if(Math.abs(s.x-t.x)+Math.abs(a.x-t.x)-Math.abs(s.x-a.x)<4&&r*r/(e[0]*e[0]+1)<4)return!0}}}return!1}function bt(t,e){return null!==t?e.x*t[0]+t[1]:e.y}function Ct(t,e,i){return bt(Et(t,e),i)}function Et(t,e){const i=t.x-e.x;if(0!==i){const s=(t.y-e.y)/i;return[s,t.y-s*t.x]}return null}function wt(t,e,i){const s=e.length,a=o(i)?i>0&&i<1?i:0:i?.5:0;if(a>0&&s>2){let i=e[0].x,r=e[0].y;for(let n=1;n<s-1;n++){const s=e[n-1],o=e[n],l=e[n+1],h=o.x-s.x,c=o.y-s.y,d=l.x-o.x,u=l.y-o.y;let g=l.x-s.x,p=l.y-s.y;const m=Math.sqrt(h*h+c*c),_=Math.sqrt(d*d+u*u),f=_/(_+m);let y=o.x+g*a*f,x=o.y+p*a*f;y=Math.min(y,Math.max(l.x,o.x)),x=Math.min(x,Math.max(l.y,o.y)),y=Math.max(y,Math.min(l.x,o.x)),x=Math.max(x,Math.min(l.y,o.y)),g=y-o.x,p=x-o.y;let v=o.x-g*m/_,b=o.y-p*m/_;v=Math.min(v,Math.max(s.x,o.x)),b=Math.min(b,Math.max(s.y,o.y)),v=Math.max(v,Math.min(s.x,o.x)),b=Math.max(b,Math.min(s.y,o.y)),g=o.x-v,p=o.y-b,y=o.x+g*_/m,x=o.y+p*_/m,t.bezierCurveTo(i,r,v,b,o.x,o.y),i=y,r=x}const o=e[s-1];t.bezierCurveTo(i,r,o.x,o.y,o.x,o.y)}else for(let r=1;r<s;r++)t.lineTo(e[r].x,e[r].y)}var St={name:"line",checkEventOn:vt,draw:(t,e,i)=>{!function(t,e,i){let s=[];s=s.concat(e);const{style:a="solid",smooth:r=!1,size:o=1,color:n="currentColor",dashedValue:l=[2,2]}=i;t.lineWidth=o,t.strokeStyle=n,"dashed"===a?t.setLineDash(l):t.setLineDash([]);const h=o%2==1?.5:0;s.forEach((({coordinates:e})=>{e.length>1&&(2!==e.length||e[0].x!==e[1].x&&e[0].y!==e[1].y?(t.save(),o%2==1&&t.translate(.5,.5),t.beginPath(),t.moveTo(e[0].x,e[0].y),wt(t,e,r),t.stroke(),t.closePath(),t.restore()):(t.beginPath(),e[0].x===e[1].x?(t.moveTo(e[0].x+h,e[0].y),t.lineTo(e[1].x+h,e[1].y)):(t.moveTo(e[0].x,e[0].y+h),t.lineTo(e[1].x,e[1].y+h)),t.stroke(),t.closePath()))}))}(t,e,i)}};function It(t,e,i){const s=i??0,a=[];if(t.length>1)if(t[0].x===t[1].x){const i=0,r=e.height;if(a.push({coordinates:[{x:t[0].x,y:i},{x:t[0].x,y:r}]}),t.length>2){a.push({coordinates:[{x:t[2].x,y:i},{x:t[2].x,y:r}]});const e=t[0].x-t[2].x;for(let o=0;o<s;o++){const s=e*(o+1);a.push({coordinates:[{x:t[0].x+s,y:i},{x:t[0].x+s,y:r}]})}}}else{const i=0,r=e.width,o=Et(t[0],t[1]),n=o[0],l=o[1];if(a.push({coordinates:[{x:i,y:i*n+l},{x:r,y:r*n+l}]}),t.length>2){const e=t[2].y-n*t[2].x;a.push({coordinates:[{x:i,y:i*n+e},{x:r,y:r*n+e}]});const o=l-e;for(let t=0;t<s;t++){const e=l+o*(t+1);a.push({coordinates:[{x:i,y:i*n+e},{x:r,y:r*n+e}]})}}}return a}function Tt(t,e){if(t.length>1){let i={x:0,y:0};return i=t[0].x===t[1].x&&t[0].y!==t[1].y?t[0].y<t[1].y?{x:t[0].x,y:e.height}:{x:t[0].x,y:0}:t[0].x>t[1].x?{x:0,y:Ct(t[0],t[1],{x:0,y:t[0].y})}:{x:e.width,y:Ct(t[0],t[1],{x:e.width,y:t[0].y})},{coordinates:[t[0],i]}}return[]}var Pt={name:"simpleAnnotation",totalStep:2,styles:{line:{style:"dashed"}},createPointFigures:({overlay:t,coordinates:e})=>{let i="";n(t.extendData)&&(i=a(t.extendData)?t.extendData(t):t.extendData??"");const s=e[0].x,r=e[0].y-6,o=r-50,l=o-5;return[{type:"line",attrs:{coordinates:[{x:s,y:r},{x:s,y:o}]},ignoreEvent:!0},{type:"polygon",attrs:{coordinates:[{x:s,y:o},{x:s-4,y:l},{x:s+4,y:l}]},ignoreEvent:!0},{type:"text",attrs:{x:s,y:l,text:i,align:"center",baseline:"bottom"},ignoreEvent:!0}]}},At={name:"simpleTag",totalStep:2,styles:{line:{style:"dashed"}},createPointFigures:({bounding:t,coordinates:e})=>({type:"line",attrs:{coordinates:[{x:0,y:e[0].y},{x:t.width,y:e[0].y}]},ignoreEvent:!0}),createYAxisFigures:({chart:t,overlay:e,coordinates:i,bounding:s,yAxis:r})=>{let l="left",h=0;r?.isFromZero()??!1?(l="left",h=0):(l="right",h=s.width);let c="";return n(e.extendData)&&(c=a(e.extendData)?e.extendData(e):e.extendData??""),!n(c)&&o(e.points[0].value)&&(c=p(e.points[0].value,t.getSymbol()?.pricePrecision??W.PRICE)),{type:"text",attrs:{x:h,y:i[0].y,text:c,align:l,baseline:"middle"}}}},Mt={};[_t,ft,{name:"horizontalSegment",totalStep:3,needDefaultPointFigure:!0,needDefaultXAxisFigure:!0,needDefaultYAxisFigure:!0,createPointFigures:({coordinates:t})=>{const e=[];return 2===t.length&&e.push({coordinates:t}),[{type:"line",attrs:e}]},performEventPressedMove:({points:t,performPoint:e})=>{t[0].value=e.value,t[1].value=e.value},performEventMoveForDrawing:({currentStep:t,points:e,performPoint:i})=>{2===t&&(e[0].value=i.value)}},{name:"horizontalStraightLine",totalStep:2,needDefaultPointFigure:!0,needDefaultXAxisFigure:!0,needDefaultYAxisFigure:!0,createPointFigures:({coordinates:t,bounding:e})=>[{type:"line",attrs:{coordinates:[{x:0,y:t[0].y},{x:e.width,y:t[0].y}]}}]},{name:"parallelStraightLine",totalStep:4,needDefaultPointFigure:!0,needDefaultXAxisFigure:!0,needDefaultYAxisFigure:!0,createPointFigures:({coordinates:t,bounding:e})=>[{type:"line",attrs:It(t,e)}]},{name:"priceChannelLine",totalStep:4,needDefaultPointFigure:!0,needDefaultXAxisFigure:!0,needDefaultYAxisFigure:!0,createPointFigures:({coordinates:t,bounding:e})=>[{type:"line",attrs:It(t,e,1)}]},{name:"priceLine",totalStep:2,needDefaultPointFigure:!0,needDefaultXAxisFigure:!0,needDefaultYAxisFigure:!0,createPointFigures:({chart:t,coordinates:e,bounding:i,overlay:s,yAxis:a})=>{let r=0;a?.isInCandle()??1?r=t.getSymbol()?.pricePrecision??W.PRICE:t.getIndicators({paneId:s.paneId}).forEach((t=>{r=Math.max(r,t.precision)}));const{value:o=0}=s.points[0];return[{type:"line",attrs:{coordinates:[e[0],{x:i.width,y:e[0].y}]}},{type:"text",ignoreEvent:!0,attrs:{x:e[0].x,y:e[0].y,text:t.getDecimalFold().format(t.getThousandsSeparator().format(o.toFixed(r))),baseline:"bottom"}}]}},{name:"rayLine",totalStep:3,needDefaultPointFigure:!0,needDefaultXAxisFigure:!0,needDefaultYAxisFigure:!0,createPointFigures:({coordinates:t,bounding:e})=>[{type:"line",attrs:Tt(t,e)}]},{name:"segment",totalStep:3,needDefaultPointFigure:!0,needDefaultXAxisFigure:!0,needDefaultYAxisFigure:!0,createPointFigures:({coordinates:t})=>2===t.length?[{type:"line",attrs:{coordinates:t}}]:[]},{name:"straightLine",totalStep:3,needDefaultPointFigure:!0,needDefaultXAxisFigure:!0,needDefaultYAxisFigure:!0,createPointFigures:({coordinates:t,bounding:e})=>2===t.length?t[0].x===t[1].x?[{type:"line",attrs:{coordinates:[{x:t[0].x,y:0},{x:t[0].x,y:e.height}]}}]:[{type:"line",attrs:{coordinates:[{x:0,y:Ct(t[0],t[1],{x:0,y:t[0].y})},{x:e.width,y:Ct(t[0],t[1],{x:e.width,y:t[0].y})}]}}]:[]},{name:"verticalRayLine",totalStep:3,needDefaultPointFigure:!0,needDefaultXAxisFigure:!0,needDefaultYAxisFigure:!0,createPointFigures:({coordinates:t,bounding:e})=>{if(2===t.length){const i={x:t[0].x,y:0};return t[0].y<t[1].y&&(i.y=e.height),[{type:"line",attrs:{coordinates:[t[0],i]}}]}return[]},performEventPressedMove:({points:t,performPoint:e})=>{t[0].timestamp=e.timestamp,t[0].dataIndex=e.dataIndex,t[1].timestamp=e.timestamp,t[1].dataIndex=e.dataIndex},performEventMoveForDrawing:({currentStep:t,points:e,performPoint:i})=>{2===t&&(e[0].timestamp=i.timestamp,e[0].dataIndex=i.dataIndex)}},{name:"verticalSegment",totalStep:3,needDefaultPointFigure:!0,needDefaultXAxisFigure:!0,needDefaultYAxisFigure:!0,createPointFigures:({coordinates:t})=>2===t.length?[{type:"line",attrs:{coordinates:t}}]:[],performEventPressedMove:({points:t,performPoint:e})=>{t[0].timestamp=e.timestamp,t[0].dataIndex=e.dataIndex,t[1].timestamp=e.timestamp,t[1].dataIndex=e.dataIndex},performEventMoveForDrawing:({currentStep:t,points:e,performPoint:i})=>{2===t&&(e[0].timestamp=i.timestamp,e[0].dataIndex=i.dataIndex)}},{name:"verticalStraightLine",totalStep:2,needDefaultPointFigure:!0,needDefaultXAxisFigure:!0,needDefaultYAxisFigure:!0,createPointFigures:({coordinates:t,bounding:e})=>[{type:"line",attrs:{coordinates:[{x:t[0].x,y:0},{x:t[0].x,y:e.height}]}}]},Pt,At].forEach((t=>{Mt[t.name]=mt.extend(t)}));var Dt={light:{grid:{horizontal:{color:"#EDEDED"},vertical:{color:"#EDEDED"}},candle:{priceMark:{high:{color:"#76808F"},low:{color:"#76808F"}},tooltip:{rect:{color:"#FEFEFE",borderColor:"#F2F3F5"},title:{color:"#76808F"},legend:{color:"#76808F"}}},indicator:{tooltip:{title:{color:"#76808F"},legend:{color:"#76808F"}}},xAxis:{axisLine:{color:"#DDDDDD"},tickText:{color:"#76808F"},tickLine:{color:"#DDDDDD"}},yAxis:{axisLine:{color:"#DDDDDD"},tickText:{color:"#76808F"},tickLine:{color:"#DDDDDD"}},separator:{color:"#DDDDDD"},crosshair:{horizontal:{line:{color:"#76808F"},text:{borderColor:"#686D76",backgroundColor:"#686D76"}},vertical:{line:{color:"#76808F"},text:{borderColor:"#686D76",backgroundColor:"#686D76"}}}},dark:{grid:{horizontal:{color:"#292929"},vertical:{color:"#292929"}},candle:{priceMark:{high:{color:"#929AA5"},low:{color:"#929AA5"}},tooltip:{rect:{color:"rgba(10, 10, 10, .6)",borderColor:"rgba(10, 10, 10, .6)"},title:{color:"#929AA5"},legend:{color:"#929AA5"}}},indicator:{tooltip:{title:{color:"#929AA5"},legend:{color:"#929AA5"}}},xAxis:{axisLine:{color:"#333333"},tickText:{color:"#929AA5"},tickLine:{color:"#333333"}},yAxis:{axisLine:{color:"#333333"},tickText:{color:"#929AA5"},tickLine:{color:"#333333"}},separator:{color:"#333333"},crosshair:{horizontal:{line:{color:"#929AA5"},text:{borderColor:"#373a40",backgroundColor:"#373a40"}},vertical:{line:{color:"#929AA5"},text:{borderColor:"#373a40",backgroundColor:"#373a40"}}}}};function kt(t){return Dt[t]??null}var Bt={CANDLE:"candle_pane",INDICATOR:"indicator_pane_",X_AXIS:"x_axis_pane"},Ft={barSpaceLimitMin:1,barSpaceLimitMax:50,yAxisPosition:"right",yAxisInside:!1,paneMinHeight:30,paneHeight:100},Rt=class{constructor(t,i){this._styles={grid:{show:!0,horizontal:{show:!0,size:1,color:"#EDEDED",style:"dashed",dashedValue:[2,2]},vertical:{show:!0,size:1,color:"#EDEDED",style:"dashed",dashedValue:[2,2]}},candle:H(),indicator:X(),xAxis:$(),yAxis:$(),separator:{size:1,color:"#DDDDDD",fill:!0,activeBackgroundColor:V(N.BLUE,.08)},crosshair:{show:!0,horizontal:{show:!0,line:{show:!0,style:"dashed",dashedValue:[4,2],size:1,color:N.GREY},text:{show:!0,style:"fill",color:N.WHITE,size:12,family:"Helvetica Neue",weight:"normal",borderStyle:"solid",borderDashedValue:[2,2],borderSize:1,borderColor:N.GREY,borderRadius:2,paddingLeft:4,paddingRight:4,paddingTop:4,paddingBottom:4,backgroundColor:N.GREY},features:[]},vertical:{show:!0,line:{show:!0,style:"dashed",dashedValue:[4,2],size:1,color:N.GREY},text:{show:!0,style:"fill",color:N.WHITE,size:12,family:"Helvetica Neue",weight:"normal",borderStyle:"solid",borderDashedValue:[2,2],borderSize:1,borderColor:N.GREY,borderRadius:2,paddingLeft:4,paddingRight:4,paddingTop:4,paddingBottom:4,backgroundColor:N.GREY}}},overlay:G()},this._formatter={formatDate:({dateTimeFormat:t,timestamp:e,template:i})=>g(t,e,i),formatBigNumber:m,formatExtendText:t=>""},this._innerFormatter={formatDate:(t,e,i)=>this._formatter.formatDate({dateTimeFormat:this._dateTimeFormat,timestamp:t,template:e,type:i}),formatBigNumber:t=>this._formatter.formatBigNumber(t),formatExtendText:t=>this._formatter.formatExtendText(t)},this._locale="en-US",this._thousandsSeparator={sign:",",format:t=>_(t,this._thousandsSeparator.sign)},this._decimalFold={threshold:3,format:t=>f(t,this._decimalFold.threshold)},this._symbol=null,this._period=null,this._dataList=[],this._dataLoader=null,this._loading=!1,this._dataLoadMore={forward:!1,backward:!1},this._zoomEnabled=!0,this._zoomAnchor={main:"cursor",xAxis:"cursor"},this._scrollEnabled=!0,this._totalBarSpace=0,this._barSpace=10,this._layoutBasicParams={...Ft},this._offsetRightDistance=80,this._startLastBarRightSideDiffBarCount=0,this._scrollLimitRole="bar_count",this._minVisibleBarCount={left:2,right:2},this._maxOffsetDistance={left:50,right:50},this._visibleRange={from:0,to:0,realFrom:0,realTo:0},this._visibleRangeDataList=[],this._visibleRangeHighLowPrice=[{x:0,price:Number.MIN_SAFE_INTEGER},{x:0,price:Number.MAX_SAFE_INTEGER}],this._crosshair={},this._actions=new Map,this._indicators=new Map,this._overlays=new Map,this._progressOverlayInfo=null,this._lastPriceMarkExtendTextUpdateTimers=[],this._pressedOverlayInfo={paneId:"",overlay:null,figureType:"none",figureIndex:-1,figure:null},this._hoverOverlayInfo={paneId:"",overlay:null,figureType:"none",figureIndex:-1,figure:null},this._clickOverlayInfo={paneId:"",overlay:null,figureType:"none",figureIndex:-1,figure:null},this._chart=t;const{layout:a}=i??{};n(a)&&!s(a)&&e(this._layoutBasicParams,a.basicParams),this._calcOptimalBarSpace(),this._lastBarRightSideDiffBarCount=this._offsetRightDistance/this._barSpace;const{styles:r,locale:o,timezone:l,formatter:c,thousandsSeparator:d,decimalFold:u,zoomAnchor:p}=i??{};n(r)&&this.setStyles(r),h(o)&&this.setLocale(o),this.setTimezone(l??""),n(c)&&this.setFormatter(c),n(d)&&this.setThousandsSeparator(d),n(u)&&this.setDecimalFold(u),n(p)&&this.setZoomAnchor(p),this._taskScheduler=new O((()=>{this._chart.layout({measureWidth:!0,update:!0,buildYAxisTick:!0})}))}setStyles(t){let i=null;if(i=h(t)?kt(t):t,e(this._styles,i),s(i?.candle?.tooltip?.legend?.template)&&(this._styles.candle.tooltip.legend.template=i.candle.tooltip.legend.template),n(i?.candle?.priceMark?.last?.extendTexts)){this._clearLastPriceMarkExtendTextUpdateTimer();const t=[];this._styles.candle.priceMark.last.extendTexts.forEach((e=>{const i=e.updateInterval;if(e.show&&i>0&&!t.includes(i)){t.push(i);const e=setInterval((()=>{this._chart.updatePane(w.Main,Bt.CANDLE)}),i);this._lastPriceMarkExtendTextUpdateTimers.push(e)}}))}}getStyles(){return this._styles}setFormatter(t){e(this._formatter,t)}getFormatter(){return this._formatter}getInnerFormatter(){return this._innerFormatter}setLocale(t){this._locale=t}getLocale(){return this._locale}setTimezone(t){if(!n(this._dateTimeFormat)||this.getTimezone()!==t){const i={hour12:!1,year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit",second:"2-digit"};t.length>0&&(i.timeZone=t);let s=null;try{s=new Intl.DateTimeFormat("en",i)}catch(e){}null!==s&&(this._dateTimeFormat=s)}}getTimezone(){return this._dateTimeFormat.resolvedOptions().timeZone}getDateTimeFormat(){return this._dateTimeFormat}setThousandsSeparator(t){e(this._thousandsSeparator,t)}getThousandsSeparator(){return this._thousandsSeparator}setDecimalFold(t){e(this._decimalFold,t)}getDecimalFold(){return this._decimalFold}setSymbol(t){this.resetData((()=>{this._symbol={pricePrecision:W.PRICE,volumePrecision:W.VOLUME,...this._symbol,...t},this._synchronizeIndicatorSeriesPrecision()}))}getSymbol(){return this._symbol}setPeriod(t){this.resetData((()=>{this._period=t}))}getPeriod(){return this._period}getDataList(){return this._dataList}getVisibleRangeDataList(){return this._visibleRangeDataList}getVisibleRangeHighLowPrice(){return this._visibleRangeHighLowPrice}_addData(t,e,i){let a=!1,r=!1,o=0;if(s(t)){const s={backward:!1,forward:!1};switch(l(i)?(s.backward=i,s.forward=i):(s.backward=i?.backward??!1,s.forward=i?.forward??!1),o=t.length,e){case"init":this._clearData(),this._dataList=t,this._dataLoadMore.backward=s.backward,this._dataLoadMore.forward=s.forward,this.setOffsetRightDistance(this._offsetRightDistance),r=!0;break;case"backward":this._dataList=this._dataList.concat(t),this._dataLoadMore.backward=s.backward,this._lastBarR