klinecharts
Version:
Lightweight k-line chart built with html5 canvas
7 lines • 215 kB
JavaScript
/**
* @license
* KLineChart v10.0.0-beta1
* 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){"use strict";function e(t,r){if(o(t)||o(r))for(var n in r)if(Object.prototype.hasOwnProperty.call(r,n)){var a=t[n],s=r[n];o(s)&&o(a)?e(a,s):t[n]=i(s)}}function i(t){if(!o(t))return t;var e=null;for(var n in e=r(t)?[]:{},t)if(Object.prototype.hasOwnProperty.call(t,n)){var a=t[n];o(a)?e[n]=i(a):e[n]=a}return e}function r(t){return"[object Array]"===Object.prototype.toString.call(t)}function n(t){return"function"==typeof t}function o(t){return"object"==typeof t&&s(t)}function a(t){return"number"==typeof t&&Number.isFinite(t)}function s(t){return null!=t}function l(t){return"boolean"==typeof t}function u(t){return"string"==typeof t}var c=/\\(\\)?/g,h=RegExp("[^.[\\]]+|\\[(?:([^\"'][^[]*)|([\"'])((?:(?!\\2)[^\\\\]|\\\\.)*?)\\2)\\]|(?=(?:\\.|\\[\\])(?:\\.|\\[\\]|$))","g");function d(t,e,i){if(s(t)){var r=[];e.replace(h,(function(t){for(var e=[],i=1;i<arguments.length;i++)e[i-1]=arguments[i];var n=t;return s(e[1])?n=e[2].replace(c,"$1"):s(e[0])&&(n=e[0].trim()),r.push(n),""}));for(var n=t,o=0,a=r.length;s(n)&&o<a;)n=null==n?void 0:n[r[o++]];return s(n)?n:null!=i?i:"--"}return null!=i?i:"--"}function p(t,e,i){var r=function(t,e){var i={};return t.formatToParts(new Date(e)).forEach((function(t){var e=t.type,r=t.value;switch(e){case"year":i.YYYY=r;break;case"month":i.MM=r;break;case"day":i.DD=r;break;case"hour":i.HH="24"===r?"00":r;break;case"minute":i.mm=r;break;case"second":i.ss=r}})),i}(t,e);return i.replace(/YYYY|MM|DD|HH|mm|ss/g,(function(t){return r[t]}))}function g(t,e){var i=+t;return a(i)?i.toFixed(null!=e?e:2):"".concat(t)}function v(t){var e=+t;if(a(e)){if(e>1e9)return"".concat(+(e/1e9).toFixed(3),"B");if(e>1e6)return"".concat(+(e/1e6).toFixed(3),"M");if(e>1e3)return"".concat(+(e/1e3).toFixed(3),"K")}return"".concat(t)}function f(t,e){var i="".concat(t);if(0===e.length)return i;if(i.includes(".")){var r=i.split(".");return"".concat(r[0].replace(/(\d)(?=(\d{3})+$)/g,(function(t){return"".concat(t).concat(e)})),".").concat(r[1])}return i.replace(/(\d)(?=(\d{3})+$)/g,(function(t){return"".concat(t).concat(e)}))}function m(t,e){var i="".concat(t);if(new RegExp("\\.0{"+e+",}[1-9][0-9]*$").test(i)){var r=i.split("."),n=r.length-1,o=r[n],a=/0*/.exec(o);if(s(a)){var l=a[0].length;return r[n]=o.replace(/0*/,"0{".concat(l,"}")),r.join(".")}}return i}function y(t,e){return t.replace(/\{(\w+)\}/g,(function(t,i){var r=e[i];return s(r)?r:"{".concat(i,"}")}))}var _=null;function x(t){var e,i;return null!==(i=null===(e=t.ownerDocument.defaultView)||void 0===e?void 0:e.devicePixelRatio)&&void 0!==i?i:1}function b(t,e,i){return"".concat(null!=e?e:"normal"," ").concat(null!=t?t:12,"px ").concat(null!=i?i:"Helvetica Neue")}function w(t,e,i,r){if(!s(_)){var n=document.createElement("canvas"),o=x(n);(_=n.getContext("2d")).scale(o,o)}return _.font=b(e,i,r),Math.round(_.measureText(t).width)}var C=function(t,e){return C=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var i in e)Object.prototype.hasOwnProperty.call(e,i)&&(t[i]=e[i])},C(t,e)};function E(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Class extends value "+String(e)+" is not a constructor or null");function i(){this.constructor=t}C(t,e),t.prototype=null===e?Object.create(e):(i.prototype=e.prototype,new i)}var T=function(){return T=Object.assign||function(t){for(var e,i=1,r=arguments.length;i<r;i++)for(var n in e=arguments[i])Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n]);return t},T.apply(this,arguments)};function S(t,e){var i={};for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&e.indexOf(r)<0&&(i[r]=t[r]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var n=0;for(r=Object.getOwnPropertySymbols(t);n<r.length;n++)e.indexOf(r[n])<0&&Object.prototype.propertyIsEnumerable.call(t,r[n])&&(i[r[n]]=t[r[n]])}return i}function P(t,e,i,r){return new(i||(i=Promise))((function(n,o){function a(t){try{l(r.next(t))}catch(t){o(t)}}function s(t){try{l(r.throw(t))}catch(t){o(t)}}function l(t){var e;t.done?n(t.value):(e=t.value,e instanceof i?e:new i((function(t){t(e)}))).then(a,s)}l((r=r.apply(t,e||[])).next())}))}function M(t,e){var i,r,n,o={label:0,sent:function(){if(1&n[0])throw n[1];return n[1]},trys:[],ops:[]},a=Object.create(("function"==typeof Iterator?Iterator:Object).prototype);return a.next=s(0),a.throw=s(1),a.return=s(2),"function"==typeof Symbol&&(a[Symbol.iterator]=function(){return this}),a;function s(s){return function(l){return function(s){if(i)throw new TypeError("Generator is already executing.");for(;a&&(a=0,s[0]&&(o=0)),o;)try{if(i=1,r&&(n=2&s[0]?r.return:s[0]?r.throw||((n=r.return)&&n.call(r),0):r.next)&&!(n=n.call(r,s[1])).done)return n;switch(r=0,n&&(s=[2&s[0],n.value]),s[0]){case 0:case 1:n=s;break;case 4:return o.label++,{value:s[1],done:!1};case 5:o.label++,r=s[1],s=[0];continue;case 7:s=o.ops.pop(),o.trys.pop();continue;default:if(!(n=o.trys,(n=n.length>0&&n[n.length-1])||6!==s[0]&&2!==s[0])){o=0;continue}if(3===s[0]&&(!n||s[1]>n[0]&&s[1]<n[3])){o.label=s[1];break}if(6===s[0]&&o.label<n[1]){o.label=n[1],n=s;break}if(n&&o.label<n[2]){o.label=n[2],o.ops.push(s);break}n[2]&&o.ops.pop(),o.trys.pop();continue}s=e.call(t,o)}catch(t){s=[6,t],r=0}finally{i=n=0}if(5&s[0])throw s[1];return{value:s[0]?s[1]:void 0,done:!0}}([s,l])}}}function I(t){var e="function"==typeof Symbol&&Symbol.iterator,i=e&&t[e],r=0;if(i)return i.call(t);if(t&&"number"==typeof t.length)return{next:function(){return t&&r>=t.length&&(t=void 0),{value:t&&t[r++],done:!t}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")}function D(t,e){var i="function"==typeof Symbol&&t[Symbol.iterator];if(!i)return t;var r,n,o=i.call(t),a=[];try{for(;(void 0===e||e-- >0)&&!(r=o.next()).done;)a.push(r.value)}catch(t){n={error:t}}finally{try{r&&!r.done&&(i=o.return)&&i.call(o)}finally{if(n)throw n.error}}return a}function k(t,e,i){if(i||2===arguments.length)for(var r,n=0,o=e.length;n<o;n++)!r&&n in e||(r||(r=Array.prototype.slice.call(e,0,n)),r[n]=e[n]);return t.concat(r||Array.prototype.slice.call(e))}function A(t){var i={width:0,height:0,left:0,right:0,top:0,bottom:0};return s(t)&&e(i,t),i}"function"==typeof SuppressedError&&SuppressedError;function F(t){return n(window.requestAnimationFrame)?window.requestAnimationFrame(t):window.setTimeout(t,20)}function B(t){n(window.cancelAnimationFrame)?window.cancelAnimationFrame(t):window.clearTimeout(t)}var R=function(){function t(t){this._options={duration:500,iterationCount:1},this._currentIterationCount=0,this._running=!1,this._time=0,e(this._options,t)}return t.prototype._loop=function(){var t=this;this._running=!0;var e=function(){var i;if(t._running){var r=(new Date).getTime()-t._time;r<t._options.duration?(null===(i=t._doFrameCallback)||void 0===i||i.call(t,r),F(e)):(t.stop(),t._currentIterationCount++,t._currentIterationCount<t._options.iterationCount&&t.start())}};F(e)},t.prototype.doFrame=function(t){return this._doFrameCallback=t,this},t.prototype.setDuration=function(t){return this._options.duration=t,this},t.prototype.setIterationCount=function(t){return this._options.iterationCount=t,this},t.prototype.start=function(){this._running||(this._time=(new Date).getTime(),this._loop())},t.prototype.stop=function(){var t;this._running&&(null===(t=this._doFrameCallback)||void 0===t||t.call(this,this._options.duration)),this._running=!1},t}(),L=1,O=(new Date).getTime();function W(t){var e=(new Date).getTime();return e===O?++L:L=1,O=e,"".concat(null!=t?t:"").concat(e,"_").concat(L)}function V(t,e){var i,r=document.createElement(t),n=null!=e?e:{};for(var o in n)r.style[o]=null!==(i=n[o])&&void 0!==i?i:"";return r}function z(t,e,i){var r=0,n=0;for(n=t.length-1;r!==n;){var o=Math.floor((n+r)/2),a=n-r,s=t[o][e];if(i===t[r][e])return r;if(i===t[n][e])return n;if(i===s)return o;if(i>s?r=o:n=o,a<=2)break}return r}function N(t,e){e=Math.max(0,null!=e?e:0);var i=Math.pow(10,e);return Math.round(t*i)/i}function Y(t,e,i){for(var r,n,o=[Number.MIN_SAFE_INTEGER,Number.MAX_SAFE_INTEGER],a=t.length,s=0;s<a;){var l=t[s];o[0]=Math.max(null!==(r=l[e])&&void 0!==r?r:Number.MIN_SAFE_INTEGER,o[0]),o[1]=Math.min(null!==(n=l[i])&&void 0!==n?n:Number.MAX_SAFE_INTEGER,o[1]),++s}return o}function H(t){return 0===t?0:Math.log10(t)}function X(t){return Math.pow(10,t)}var G=function(){function t(t){this._holdingTasks=null,this._running=!1,this._callback=t}return t.prototype.add=function(t){this._running?s(this._holdingTasks)?this._holdingTasks=T(T({},this._holdingTasks),t):this._holdingTasks=t:this._runTask(t)},t.prototype._runTask=function(t){return P(this,void 0,void 0,(function(){var e,i;return M(this,(function(r){switch(r.label){case 0:this._running=!0,r.label=1;case 1:return r.trys.push([1,,3,4]),[4,Promise.all(Object.values(t))];case 2:return r.sent(),[3,4];case 3:return this._running=!1,null===(i=this._callback)||void 0===i||i.call(this),s(this._holdingTasks)&&(e=this._holdingTasks,this._runTask(e),this._holdingTasks=null),[7];case 4:return[2]}}))}))},t.prototype.clear=function(){this._holdingTasks=null},t}(),U=2,Z=0,j=function(){function t(){this._callbacks=[]}return t.prototype.subscribe=function(t){this._callbacks.indexOf(t)<0&&this._callbacks.push(t)},t.prototype.unsubscribe=function(t){if(n(t)){var e=this._callbacks.indexOf(t);e>-1&&this._callbacks.splice(e,1)}else this._callbacks=[]},t.prototype.execute=function(t){this._callbacks.forEach((function(e){e(t)}))},t.prototype.isEmpty=function(){return 0===this._callbacks.length},t}();function q(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 Q(t,e){var i=t.replace(/^#/,""),r=parseInt(i,16),n=r>>8&255,o=255&r;return"rgba(".concat(r>>16&255,", ").concat(n,", ").concat(o,", ").concat(null!=e?e:1,")")}var K={RED:"#F92855",GREEN:"#2DC08E",WHITE:"#FFFFFF",GREY:"#76808F",BLUE:"#1677FF"};function J(){return{show:!0,size:"auto",axisLine:{show:!0,color:"#DDDDDD",size:1},tickText:{show:!0,color:K.GREY,size:12,family:"Helvetica Neue",weight:"normal",marginStart:4,marginEnd:6},tickLine:{show:!0,size:1,length:3,color:"#DDDDDD"}}}function $(t,e,i,r){var n,o=t.result,a=t.figures,l=t.styles,u=d(l,"circles",i.circles),c=u.length,h=d(l,"bars",i.bars),p=h.length,g=d(l,"lines",i.lines),v=g.length,f=0,m=0,y=0,_=0;a.forEach((function(a){var l;switch(a.type){case"circle":_=f;var d=u[f%c];n=T(T({},d),{color:d.noChangeColor}),f++;break;case"bar":_=m;var x=h[m%p];n=T(T({},x),{color:x.noChangeColor}),m++;break;case"line":_=y,n=g[y%v],y++}if(s(a.type)){var b=null===(l=a.styles)||void 0===l?void 0:l.call(a,{data:{prev:o[e-1],current:o[e],next:o[e+1]},indicator:t,defaultStyles:i});r(a,T(T({},n),b),_)}}))}var tt=function(){function t(t){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=function(t,e){var 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.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=function(){return[]},this.regenerateFigures=null,this.createTooltipDataSource=null,this.draw=null,this.result=[],this._lockSeriesPrecision=!1,this.override(t),this._lockSeriesPrecision=!1}return t.prototype.override=function(t){var r,o,l=this.result,c=S(this,["result"]);this._prevIndicator=T(T({},i(c)),{result:l});var h=t.id,d=t.name,p=t.shortName,g=t.precision,v=t.styles,f=t.figures,m=t.calcParams,y=S(t,["id","name","shortName","precision","styles","figures","calcParams"]);!u(this.id)&&u(h)&&(this.id=h),u(this.name)||(this.name=null!=d?d:""),this.shortName=null!==(r=null!=p?p:this.shortName)&&void 0!==r?r:this.name,a(g)&&(this.precision=g,this._lockSeriesPrecision=!0),s(v)&&(null!==(o=this.styles)&&void 0!==o||(this.styles={}),e(this.styles,v)),e(this,y),s(m)&&(this.calcParams=m,n(this.regenerateFigures)&&(this.figures=this.regenerateFigures(this.calcParams))),this.figures=null!=f?f:this.figures},t.prototype.setSeriesPrecision=function(t){this._lockSeriesPrecision||(this.precision=t)},t.prototype.shouldUpdateImp=function(){var t=this._prevIndicator.zLevel!==this.zLevel,e=this.shouldUpdate(this._prevIndicator,this);return l(e)?{calc:e,draw:e,sort:t}:T(T({},e),{sort:t})},t.prototype.calcImp=function(t){return P(this,void 0,void 0,(function(){var e;return M(this,(function(i){switch(i.label){case 0:return i.trys.push([0,2,,3]),[4,this.calc(t,this)];case 1:return e=i.sent(),this.result=e,[2,!0];case 2:return i.sent(),[2,!1];case 3:return[2]}}))}))},t.extend=function(e){return function(t){function i(){return t.call(this,e)||this}return E(i,t),i}(t)},t}(),et={name:"AO",shortName:"AO",calcParams:[5,34],figures:[{key:"ao",title:"AO: ",type:"bar",baseValue:0,styles:function(t){var e,i,r=t.data,n=t.indicator,o=t.defaultStyles,a=r.prev,s=r.current,l=null!==(e=null==a?void 0:a.ao)&&void 0!==e?e:Number.MIN_SAFE_INTEGER,u=null!==(i=null==s?void 0:s.ao)&&void 0!==i?i:Number.MIN_SAFE_INTEGER,c="";return{color:c=u>l?d(n.styles,"bars[0].upColor",o.bars[0].upColor):d(n.styles,"bars[0].downColor",o.bars[0].downColor),style:u>l?"stroke":"fill",borderColor:c}}}],calc:function(t,e){var i=e.calcParams,r=Math.max(i[0],i[1]),n=0,o=0,a=0,s=0;return t.map((function(e,l){var u={},c=(e.low+e.high)/2;if(n+=c,o+=c,l>=i[0]-1){a=n/i[0];var h=t[l-(i[0]-1)];n-=(h.low+h.high)/2}if(l>=i[1]-1){s=o/i[1];h=t[l-(i[1]-1)];o-=(h.low+h.high)/2}return l>=r-1&&(u.ao=a-s),u}))}};var it={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:function(t,e){var i=e.calcParams,r=i[0]-1,n=0;return t.map((function(e,o){var a=e.close,s={};if(n+=a,o>=r){s.mid=n/i[0];var l=function(t,e){var i=t.length,r=0;return t.forEach((function(t){var i=t.close-e;r+=i*i})),r=Math.abs(r),Math.sqrt(r/i)}(t.slice(o-r,o+1),s.mid);s.up=s.mid+i[1]*l,s.dn=s.mid-i[1]*l,n-=t[o-r].close}return s}))}},rt={name:"BBI",shortName:"BBI",series:"price",precision:2,calcParams:[3,6,12,24],shouldOhlc:!0,figures:[{key:"bbi",title:"BBI: ",type:"line"}],calc:function(t,e){var i=e.calcParams,r=Math.max.apply(Math,k([],D(i),!1)),n=[],o=[];return t.map((function(e,a){var s={},l=e.close;if(i.forEach((function(e,i){var r;n[i]=(null!==(r=n[i])&&void 0!==r?r:0)+l,a>=e-1&&(o[i]=n[i]/e,n[i]-=t[a-(e-1)].close)})),a>=r-1){var u=0;o.forEach((function(t){u+=t})),s.bbi=u/4}return s}))}},nt={name:"CCI",shortName:"CCI",calcParams:[20],figures:[{key:"cci",title:"CCI: ",type:"line"}],calc:function(t,e){var i=e.calcParams,r=i[0]-1,n=0,o=[];return t.map((function(e,a){var s={},l=(e.high+e.low+e.close)/3;if(n+=l,o.push(l),a>=r){var u=n/i[0],c=o.slice(a-r,a+1),h=0;c.forEach((function(t){h+=Math.abs(t-u)}));var d=h/i[0];s.cci=0!==d?(l-u)/d/.015:0;var p=(t[a-r].high+t[a-r].low+t[a-r].close)/3;n-=p}return s}))}},ot={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:function(t,e){var i=e.calcParams,r=Math.ceil(i[1]/2.5+1),n=Math.ceil(i[2]/2.5+1),o=Math.ceil(i[3]/2.5+1),a=Math.ceil(i[4]/2.5+1),s=0,l=[],u=0,c=[],h=0,d=[],p=0,g=[],v=[];return t.forEach((function(e,f){var m,y,_,x,b,w={},C=null!==(m=t[f-1])&&void 0!==m?m:e,E=(C.high+C.close+C.low+C.open)/4,T=Math.max(0,e.high-E),S=Math.max(0,E-e.low);f>=i[0]-1&&(w.cr=0!==S?T/S*100:0,s+=w.cr,u+=w.cr,h+=w.cr,p+=w.cr,f>=i[0]+i[1]-2&&(l.push(s/i[1]),f>=i[0]+i[1]+r-3&&(w.ma1=l[l.length-1-r]),s-=null!==(y=v[f-(i[1]-1)].cr)&&void 0!==y?y:0),f>=i[0]+i[2]-2&&(c.push(u/i[2]),f>=i[0]+i[2]+n-3&&(w.ma2=c[c.length-1-n]),u-=null!==(_=v[f-(i[2]-1)].cr)&&void 0!==_?_:0),f>=i[0]+i[3]-2&&(d.push(h/i[3]),f>=i[0]+i[3]+o-3&&(w.ma3=d[d.length-1-o]),h-=null!==(x=v[f-(i[3]-1)].cr)&&void 0!==x?x:0),f>=i[0]+i[4]-2&&(g.push(p/i[4]),f>=i[0]+i[4]+a-3&&(w.ma4=g[g.length-1-a]),p-=null!==(b=v[f-(i[4]-1)].cr)&&void 0!==b?b:0)),v.push(w)})),v}},at={name:"DMA",shortName:"DMA",calcParams:[10,50,10],figures:[{key:"dma",title:"DMA: ",type:"line"},{key:"ama",title:"AMA: ",type:"line"}],calc:function(t,e){var i=e.calcParams,r=Math.max(i[0],i[1]),n=0,o=0,a=0,s=[];return t.forEach((function(e,l){var u,c={},h=e.close;n+=h,o+=h;var d=0,p=0;if(l>=i[0]-1&&(d=n/i[0],n-=t[l-(i[0]-1)].close),l>=i[1]-1&&(p=o/i[1],o-=t[l-(i[1]-1)].close),l>=r-1){var g=d-p;c.dma=g,a+=g,l>=r+i[2]-2&&(c.ama=a/i[2],a-=null!==(u=s[l-(i[2]-1)].dma)&&void 0!==u?u:0)}s.push(c)})),s}},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:function(t,e){var i=e.calcParams,r=0,n=0,o=0,a=0,s=0,l=0,u=0,c=0,h=[];return t.forEach((function(e,d){var p,g,v={},f=null!==(p=t[d-1])&&void 0!==p?p:e,m=f.close,y=e.high,_=e.low,x=y-_,b=Math.abs(y-m),w=Math.abs(m-_),C=y-f.high,E=f.low-_,T=Math.max(Math.max(x,b),w),S=C>0&&C>E?C:0,P=E>0&&E>C?E:0;if(r+=T,n+=S,o+=P,d>=i[0]-1){d>i[0]-1?(a=a-a/i[0]+T,s=s-s/i[0]+S,l=l-l/i[0]+P):(a=r,s=n,l=o);var M=0,I=0;0!==a&&(M=100*s/a,I=100*l/a),v.pdi=M,v.mdi=I;var D=0;I+M!==0&&(D=Math.abs(I-M)/(I+M)*100),u+=D,d>=2*i[0]-2&&(c=d>2*i[0]-2?(c*(i[0]-1)+D)/i[0]:u/i[0],v.adx=c,d>=2*i[0]+i[1]-3&&(v.adxr=((null!==(g=h[d-(i[1]-1)].adx)&&void 0!==g?g:0)+c)/2))}h.push(v)})),h}},lt={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:function(t){var e,i,r=t.data,n=t.indicator,o=t.defaultStyles,a=r.prev,s=r.current,l=null!==(e=null==a?void 0:a.macd)&&void 0!==e?e:Number.MIN_SAFE_INTEGER,u=null!==(i=null==s?void 0:s.macd)&&void 0!==i?i:Number.MIN_SAFE_INTEGER,c="";return{style:l<u?"stroke":"fill",color:c=u>0?d(n.styles,"bars[0].upColor",o.bars[0].upColor):u<0?d(n.styles,"bars[0].downColor",o.bars[0].downColor):d(n.styles,"bars[0].noChangeColor",o.bars[0].noChangeColor),borderColor:c}}}],calc:function(t,e){var i=e.calcParams,r=0,n=0,o=0,a=0,s=0,l=0,u=Math.max(i[0],i[1]);return t.map((function(t,e){var c={},h=t.close;return r+=h,e>=i[0]-1&&(n=e>i[0]-1?(2*h+(i[0]-1)*n)/(i[0]+1):r/i[0]),e>=i[1]-1&&(o=e>i[1]-1?(2*h+(i[1]-1)*o)/(i[1]+1):r/i[1]),e>=u-1&&(a=n-o,c.dif=a,s+=a,e>=u+i[2]-2&&(l=e>u+i[2]-2?(2*a+l*(i[2]-1))/(i[2]+1):s/i[2],c.macd=2*(a-l),c.dea=l)),c}))}},ut={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:function(t){return t.map((function(t,e){var i=e+1;return{key:"rsi".concat(i),title:"RSI".concat(i,": "),type:"line"}}))},calc:function(t,e){var i=e.calcParams,r=e.figures,n=[],o=[];return t.map((function(e,a){var s,l={},u=(null!==(s=t[a-1])&&void 0!==s?s:e).close,c=e.close-u;return i.forEach((function(e,i){var s,u,h;if(c>0?n[i]=(null!==(s=n[i])&&void 0!==s?s:0)+c:o[i]=(null!==(u=o[i])&&void 0!==u?u:0)+Math.abs(c),a>=e-1){0!==o[i]?l[r[i].key]=100-100/(1+n[i]/o[i]):l[r[i].key]=0;var d=t[a-(e-1)],p=null!==(h=t[a-e])&&void 0!==h?h:d,g=d.close-p.close;g>0?n[i]-=g:o[i]-=Math.abs(g)}})),l}))}},ct={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:function(t,e){var i=e.calcParams,r=[];return t.forEach((function(e,n){var o,a,s,l,u={},c=e.close;if(n>=i[0]-1){var h=Y(t.slice(n-(i[0]-1),n+1),"high","low"),d=h[0],p=h[1],g=d-p,v=(c-p)/(0===g?1:g)*100;u.k=((i[1]-1)*(null!==(a=null===(o=r[n-1])||void 0===o?void 0:o.k)&&void 0!==a?a:50)+v)/i[1],u.d=((i[2]-1)*(null!==(l=null===(s=r[n-1])||void 0===s?void 0:s.d)&&void 0!==l?l:50)+u.k)/i[2],u.j=3*u.k-2*u.d}r.push(u)})),r}},ht={name:"SAR",shortName:"SAR",series:"price",calcParams:[2,2,20],precision:2,shouldOhlc:!0,figures:[{key:"sar",title:"SAR: ",type:"circle",styles:function(t){var e,i,r,n=t.data,o=t.indicator,a=t.defaultStyles,s=n.current;return{color:(null!==(e=null==s?void 0:s.sar)&&void 0!==e?e:Number.MIN_SAFE_INTEGER)<((null!==(i=null==s?void 0:s.high)&&void 0!==i?i:0)+(null!==(r=null==s?void 0:s.low)&&void 0!==r?r:0))/2?d(o.styles,"circles[0].upColor",a.circles[0].upColor):d(o.styles,"circles[0].downColor",a.circles[0].downColor)}}}],calc:function(t,e){var i=e.calcParams,r=i[0]/100,n=i[1]/100,o=i[2]/100,a=r,s=-100,l=!1,u=0;return t.map((function(e,i){var c=u,h=e.high,d=e.low;if(l){(-100===s||s<h)&&(s=h,a=Math.min(a+n,o)),u=c+a*(s-c);var p=Math.min(t[Math.max(1,i)-1].low,d);u>e.low?(u=s,a=r,s=-100,l=!l):u>p&&(u=p)}else{(-100===s||s>d)&&(s=d,a=Math.min(a+n,o)),u=c+a*(s-c);var g=Math.max(t[Math.max(1,i)-1].high,h);u<e.high?(u=s,a=0,s=-100,l=!l):u<g&&(u=g)}return{high:h,low:d,sar:u}}))}};function dt(){return{key:"volume",title:"VOLUME: ",type:"bar",baseValue:0,styles:function(t){var e=t.data,i=t.indicator,r=t.defaultStyles,n=e.current,o=d(i.styles,"bars[0].noChangeColor",r.bars[0].noChangeColor);return s(n)&&(n.close>n.open?o=d(i.styles,"bars[0].upColor",r.bars[0].upColor):n.close<n.open&&(o=d(i.styles,"bars[0].downColor",r.bars[0].downColor))),{color:o}}}}var pt={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"},dt()],regenerateFigures:function(t){var e=t.map((function(t,e){return{key:"ma".concat(e+1),title:"MA".concat(t,": "),type:"line"}}));return e.push(dt()),e},calc:function(t,e){var i=e.calcParams,r=e.figures,n=[];return t.map((function(e,o){var a,s=null!==(a=e.volume)&&void 0!==a?a:0,l={volume:s,open:e.open,close:e.close};return i.forEach((function(e,i){var a,u;n[i]=(null!==(a=n[i])&&void 0!==a?a:0)+s,o>=e-1&&(l[r[i].key]=n[i]/e,n[i]-=null!==(u=t[o-(e-1)].volume)&&void 0!==u?u:0)})),l}))}},gt={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:function(t){return t.map((function(t,e){return{key:"wr".concat(e+1),title:"WR".concat(e+1,": "),type:"line"}}))},calc:function(t,e){var i=e.calcParams,r=e.figures;return t.map((function(e,n){var o={},a=e.close;return i.forEach((function(e,i){var s=e-1;if(n>=s){var l=Y(t.slice(n-s,n+1),"high","low"),u=l[0],c=u-l[1];o[r[i].key]=0===c?0:(a-u)/c*100}})),o}))}},vt={},ft=[{name:"AVP",shortName:"AVP",series:"price",precision:2,figures:[{key:"avp",title:"AVP: ",type:"line"}],calc:function(t){var e=0,i=0;return t.map((function(t){var r,n,o={},a=null!==(r=t.turnover)&&void 0!==r?r:0,s=null!==(n=t.volume)&&void 0!==n?n:0;return e+=a,0!==(i+=s)&&(o.avp=e/i),o}))}},et,{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:function(t){return t.map((function(t,e){return{key:"bias".concat(e+1),title:"BIAS".concat(t,": "),type:"line"}}))},calc:function(t,e){var i=e.calcParams,r=e.figures,n=[];return t.map((function(e,o){var a={},s=e.close;return i.forEach((function(e,l){var u;if(n[l]=(null!==(u=n[l])&&void 0!==u?u:0)+s,o>=e-1){var c=n[l]/i[l];a[r[l].key]=(s-c)/c*100,n[l]-=t[o-(e-1)].close}})),a}))}},it,{name:"BRAR",shortName:"BRAR",calcParams:[26],figures:[{key:"br",title:"BR: ",type:"line"},{key:"ar",title:"AR: ",type:"line"}],calc:function(t,e){var i=e.calcParams,r=0,n=0,o=0,a=0;return t.map((function(e,s){var l,u,c={},h=e.high,d=e.low,p=e.open,g=(null!==(l=t[s-1])&&void 0!==l?l:e).close;if(o+=h-p,a+=p-d,r+=h-g,n+=g-d,s>=i[0]-1){c.ar=0!==a?o/a*100:0,c.br=0!==n?r/n*100:0;var v=t[s-(i[0]-1)],f=v.high,m=v.low,y=v.open,_=(null!==(u=t[s-i[0]])&&void 0!==u?u:t[s-(i[0]-1)]).close;r-=f-_,n-=_-m,o-=f-y,a-=y-m}return c}))}},rt,nt,ot,at,st,{name:"EMV",shortName:"EMV",calcParams:[14,9],figures:[{key:"emv",title:"EMV: ",type:"line"},{key:"maEmv",title:"MAEMV: ",type:"line"}],calc:function(t,e){var i=e.calcParams,r=0,n=[];return t.map((function(e,o){var a,s={};if(o>0){var l=t[o-1],u=e.high,c=e.low,h=null!==(a=e.volume)&&void 0!==a?a:0,d=(u+c)/2-(l.high+l.low)/2;if(0===h||u-c==0)s.emv=0;else{var p=h/1e8/(u-c);s.emv=d/p}r+=s.emv,n.push(s.emv),o>=i[0]&&(s.maEmv=r/i[0],r-=n[o-i[0]])}return s}))}},{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:function(t){return t.map((function(t,e){return{key:"ema".concat(e+1),title:"EMA".concat(t,": "),type:"line"}}))},calc:function(t,e){var i=e.calcParams,r=e.figures,n=0,o=[];return t.map((function(t,e){var a={},s=t.close;return n+=s,i.forEach((function(t,i){e>=t-1&&(o[i]=e>t-1?(2*s+(t-1)*o[i])/(t+1):n/t,a[r[i].key]=o[i])})),a}))}},{name:"MTM",shortName:"MTM",calcParams:[12,6],figures:[{key:"mtm",title:"MTM: ",type:"line"},{key:"maMtm",title:"MAMTM: ",type:"line"}],calc:function(t,e){var i=e.calcParams,r=0,n=[];return t.forEach((function(e,o){var a,s={};if(o>=i[0]){var l=e.close,u=t[o-i[0]].close;s.mtm=l-u,r+=s.mtm,o>=i[0]+i[1]-1&&(s.maMtm=r/i[1],r-=null!==(a=n[o-(i[1]-1)].mtm)&&void 0!==a?a:0)}n.push(s)})),n}},{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:function(t){return t.map((function(t,e){return{key:"ma".concat(e+1),title:"MA".concat(t,": "),type:"line"}}))},calc:function(t,e){var i=e.calcParams,r=e.figures,n=[];return t.map((function(e,o){var a={},s=e.close;return i.forEach((function(e,i){var l;n[i]=(null!==(l=n[i])&&void 0!==l?l:0)+s,o>=e-1&&(a[r[i].key]=n[i]/e,n[i]-=t[o-(e-1)].close)})),a}))}},lt,{name:"OBV",shortName:"OBV",calcParams:[30],figures:[{key:"obv",title:"OBV: ",type:"line"},{key:"maObv",title:"MAOBV: ",type:"line"}],calc:function(t,e){var i=e.calcParams,r=0,n=0,o=[];return t.forEach((function(e,a){var s,l,u,c,h=null!==(s=t[a-1])&&void 0!==s?s:e;e.close<h.close?n-=null!==(l=e.volume)&&void 0!==l?l:0:e.close>h.close&&(n+=null!==(u=e.volume)&&void 0!==u?u:0);var d={obv:n};r+=n,a>=i[0]-1&&(d.maObv=r/i[0],r-=null!==(c=o[a-(i[0]-1)].obv)&&void 0!==c?c:0),o.push(d)})),o}},{name:"PVT",shortName:"PVT",figures:[{key:"pvt",title:"PVT: ",type:"line"}],calc:function(t){var e=0;return t.map((function(i,r){var n,o,a={},s=i.close,l=null!==(n=i.volume)&&void 0!==n?n:1,u=(null!==(o=t[r-1])&&void 0!==o?o:i).close,c=0,h=u*l;return 0!==h&&(c=(s-u)/h),e+=c,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:function(t,e){var i=e.calcParams,r=0,n=0,o=[],a=[];return t.forEach((function(e,s){var l,u,c={},h=(null!==(l=t[s-1])&&void 0!==l?l:e).close,d=e.close-h>0?1:0;o.push(d),r+=d,s>=i[0]-1&&(c.psy=r/i[0]*100,n+=c.psy,s>=i[0]+i[1]-2&&(c.maPsy=n/i[1],n-=null!==(u=a[s-(i[1]-1)].psy)&&void 0!==u?u:0),r-=o[s-(i[0]-1)]),a.push(c)})),a}},{name:"ROC",shortName:"ROC",calcParams:[12,6],figures:[{key:"roc",title:"ROC: ",type:"line"},{key:"maRoc",title:"MAROC: ",type:"line"}],calc:function(t,e){var i=e.calcParams,r=[],n=0;return t.forEach((function(e,o){var a,s,l={};if(o>=i[0]-1){var u=e.close,c=(null!==(a=t[o-i[0]])&&void 0!==a?a:t[o-(i[0]-1)]).close;l.roc=0!==c?(u-c)/c*100:0,n+=l.roc,o>=i[0]-1+i[1]-1&&(l.maRoc=n/i[1],n-=null!==(s=r[o-(i[1]-1)].roc)&&void 0!==s?s:0)}r.push(l)})),r}},ut,{name:"SMA",shortName:"SMA",series:"price",calcParams:[12,2],precision:2,figures:[{key:"sma",title:"SMA: ",type:"line"}],shouldOhlc:!0,calc:function(t,e){var i=e.calcParams,r=0,n=0;return t.map((function(t,e){var o={},a=t.close;return r+=a,e>=i[0]-1&&(n=e>i[0]-1?(a*i[1]+n*(i[0]-i[1]+1))/(i[0]+1):r/i[0],o.sma=n),o}))}},ct,ht,{name:"TRIX",shortName:"TRIX",calcParams:[12,9],figures:[{key:"trix",title:"TRIX: ",type:"line"},{key:"maTrix",title:"MATRIX: ",type:"line"}],calc:function(t,e){var i=e.calcParams,r=0,n=0,o=0,a=0,s=0,l=0,u=0,c=[];return t.forEach((function(t,e){var h,d={},p=t.close;if(r+=p,e>=i[0]-1&&(n=e>i[0]-1?(2*p+(i[0]-1)*n)/(i[0]+1):r/i[0],s+=n,e>=2*i[0]-2&&(o=e>2*i[0]-2?(2*n+(i[0]-1)*o)/(i[0]+1):s/i[0],l+=o,e>=3*i[0]-3))){var g=0,v=0;e>3*i[0]-3?v=((g=(2*o+(i[0]-1)*a)/(i[0]+1))-a)/a*100:g=l/i[0],a=g,d.trix=v,u+=v,e>=3*i[0]+i[1]-4&&(d.maTrix=u/i[1],u-=null!==(h=c[e-(i[1]-1)].trix)&&void 0!==h?h:0)}c.push(d)})),c}},pt,{name:"VR",shortName:"VR",calcParams:[26,6],figures:[{key:"vr",title:"VR: ",type:"line"},{key:"maVr",title:"MAVR: ",type:"line"}],calc:function(t,e){var i=e.calcParams,r=0,n=0,o=0,a=0,s=[];return t.forEach((function(e,l){var u,c,h,d,p,g={},v=e.close,f=(null!==(u=t[l-1])&&void 0!==u?u:e).close,m=null!==(c=e.volume)&&void 0!==c?c:0;if(v>f?r+=m:v<f?n+=m:o+=m,l>=i[0]-1){var y=o/2;g.vr=n+y===0?0:(r+y)/(n+y)*100,a+=g.vr,l>=i[0]+i[1]-2&&(g.maVr=a/i[1],a-=null!==(h=s[l-(i[1]-1)].vr)&&void 0!==h?h:0);var _=t[l-(i[0]-1)],x=null!==(d=t[l-i[0]])&&void 0!==d?d:_,b=_.close,w=null!==(p=_.volume)&&void 0!==p?p:0;b>x.close?r-=w:b<x.close?n-=w:o-=w}s.push(g)})),s}},gt];function mt(t){var e;return null!==(e=vt[t])&&void 0!==e?e:null}function yt(t,e){var i,r=null!==(i=null==e?void 0:e.ignoreEvent)&&void 0!==i&&i;return l(r)?!r:!r.includes(t)}ft.forEach((function(t){vt[t.name]=tt.extend(t)}));var _t="overlay_figure_",xt=function(){function t(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)}return t.prototype.override=function(t){var o,a;this._prevOverlay=i(T(T({},this),{_prevOverlay:null}));var l=t.id,c=t.name;t.currentStep;var h=t.points,d=t.styles;if(e(this,S(t,["id","name","currentStep","points","styles"])),u(this.name)||(this.name=null!=c?c:""),!u(this.id)&&u(l)&&(this.id=l),s(d)&&(null!==(o=this.styles)&&void 0!==o||(this.styles={}),e(this.styles,d)),r(h)&&h.length>0){var p=0;if(this.points=k([],D(h),!1),h.length>=this.totalStep-1?(this.currentStep=-1,p=this.totalStep-1):(this.currentStep=h.length+1,p=h.length),n(this.performEventMoveForDrawing))for(var g=0;g<p;g++)this.performEventMoveForDrawing({currentStep:g+2,mode:this.mode,points:this.points,performPointIndex:g,performPoint:this.points[g]});-1===this.currentStep&&(null===(a=this.performEventPressedMove)||void 0===a||a.call(this,{currentStep:this.currentStep,mode:this.mode,points:this.points,performPointIndex:this.points.length-1,performPoint:this.points[this.points.length-1]}))}},t.prototype.getPrevZLevel=function(){return this._prevZLevel},t.prototype.setPrevZLevel=function(t){this._prevZLevel=t},t.prototype.shouldUpdate=function(){var 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}},t.prototype.nextStep=function(){this.currentStep===this.totalStep-1?this.currentStep=-1:this.currentStep++},t.prototype.forceComplete=function(){this.currentStep=-1},t.prototype.isDrawing=function(){return-1!==this.currentStep},t.prototype.isStart=function(){return 1===this.currentStep},t.prototype.eventMoveForDrawing=function(t){var e,i=this.currentStep-1,r={};a(t.timestamp)&&(r.timestamp=t.timestamp),a(t.dataIndex)&&(r.dataIndex=t.dataIndex),a(t.value)&&(r.value=t.value),this.points[i]=r,null===(e=this.performEventMoveForDrawing)||void 0===e||e.call(this,{currentStep:this.currentStep,mode:this.mode,points:this.points,performPointIndex:i,performPoint:r})},t.prototype.eventPressedPointMove=function(t,e){var i;this.points[e].timestamp=t.timestamp,a(t.value)&&(this.points[e].value=t.value),null===(i=this.performEventPressedMove)||void 0===i||i.call(this,{currentStep:this.currentStep,points:this.points,mode:this.mode,performPointIndex:e,performPoint:this.points[e]})},t.prototype.startPressedMove=function(t){this._prevPressedPoint=T({},t),this._prevPressedPoints=i(this.points)},t.prototype.eventPressedOtherMove=function(t,e){if(null!==this._prevPressedPoint){var i=null;a(t.dataIndex)&&a(this._prevPressedPoint.dataIndex)&&(i=t.dataIndex-this._prevPressedPoint.dataIndex);var r=null;a(t.value)&&a(this._prevPressedPoint.value)&&(r=t.value-this._prevPressedPoint.value),this.points=this._prevPressedPoints.map((function(t){var n;a(t.timestamp)&&(t.dataIndex=e.timestampToDataIndex(t.timestamp));var o=T({},t);return a(i)&&a(t.dataIndex)&&(o.dataIndex=t.dataIndex+i,o.timestamp=null!==(n=e.dataIndexToTimestamp(o.dataIndex))&&void 0!==n?n:void 0),a(r)&&a(t.value)&&(o.value=t.value+r),o}))}},t.extend=function(e){return function(t){function i(){return t.call(this,e)||this}return E(i,t),i}(t)},t}(),bt={name:"fibonacciLine",totalStep:3,needDefaultPointFigure:!0,needDefaultXAxisFigure:!0,needDefaultYAxisFigure:!0,createPointFigures:function(t){var e,i,r,n=t.chart,o=t.coordinates,s=t.bounding,l=t.overlay,u=t.yAxis,c=l.points;if(o.length>0){var h=0;if(null===(e=null==u?void 0:u.isInCandle())||void 0===e||e)h=null!==(r=null===(i=n.getSymbol())||void 0===i?void 0:i.pricePrecision)&&void 0!==r?r:U;else n.getIndicators({paneId:l.paneId}).forEach((function(t){h=Math.max(h,t.precision)}));var d=[],p=[],g=s.width;if(o.length>1&&a(c[0].value)&&a(c[1].value)){var v=o[0].y-o[1].y,f=c[0].value-c[1].value;[1,.786,.618,.5,.382,.236,0].forEach((function(t){var e,i=o[1].y+v*t,r=n.getDecimalFold().format(n.getThousandsSeparator().format(((null!==(e=c[1].value)&&void 0!==e?e:0)+f*t).toFixed(h)));d.push({coordinates:[{x:0,y:i},{x:g,y:i}]}),p.push({x:0,y:i,text:"".concat(r," (").concat((100*t).toFixed(1),"%)"),baseline:"bottom"})}))}return[{type:"line",attrs:d},{type:"text",isCheckEvent:!1,attrs:p}]}return[]}},wt={name:"horizontalRayLine",totalStep:3,needDefaultPointFigure:!0,needDefaultXAxisFigure:!0,needDefaultYAxisFigure:!0,createPointFigures:function(t){var e=t.coordinates,i=t.bounding,r={x:0,y:e[0].y};return s(e[1])&&e[0].x<e[1].x&&(r.x=i.width),[{type:"line",attrs:{coordinates:[e[0],r]}}]},performEventPressedMove:function(t){var e=t.points,i=t.performPoint;e[0].value=i.value,e[1].value=i.value},performEventMoveForDrawing:function(t){var e=t.currentStep,i=t.points,r=t.performPoint;2===e&&(i[0].value=r.value)}},Ct=function(){function t(){this._children=[],this._callbacks=new Map}return t.prototype.registerEvent=function(t,e){return this._callbacks.set(t,e),this},t.prototype.onEvent=function(t,e){var i=this._callbacks.get(t);return!(!s(i)||!this.checkEventOn(e))&&i(e)},t.prototype.dispatchEventToChildren=function(t,e){var i=this._children.length-1;if(i>-1)for(var r=i;r>-1;r--)if(this._children[r].dispatchEvent(t,e))return!0;return!1},t.prototype.dispatchEvent=function(t,e){return!!this.dispatchEventToChildren(t,e)||this.onEvent(t,e)},t.prototype.addChild=function(t){return this._children.push(t),this},t.prototype.clear=function(){this._children=[]},t}(),Et=function(t){function e(e){var i=t.call(this)||this;return i.attrs=e.attrs,i.styles=e.styles,i}return E(e,t),e.prototype.checkEventOn=function(t){return this.checkEventOnImp(t,this.attrs,this.styles)},e.prototype.setAttrs=function(t){return this.attrs=t,this},e.prototype.setStyles=function(t){return this.styles=t,this},e.prototype.draw=function(t){this.drawImp(t,this.attrs,this.styles)},e.extend=function(t){var i=function(e){function i(){return null!==e&&e.apply(this,arguments)||this}return E(i,e),i.prototype.checkEventOnImp=function(e,i,r){return t.checkEventOn(e,i,r)},i.prototype.drawImp=function(e,i,r){t.draw(e,i,r)},i}(e);return i},e}(Ct);function Tt(t,e){var i,r,n=[];n=n.concat(e);try{for(var o=I(n),a=o.next();!a.done;a=o.next()){var s=a.value.coordinates;if(s.length>1)for(var l=1;l<s.length;l++){var u=s[l-1],c=s[l];if(u.x===c.x){if(Math.abs(u.y-t.y)+Math.abs(c.y-t.y)-Math.abs(u.y-c.y)<4&&Math.abs(t.x-u.x)<2)return!0}else{var h=Mt(u,c),d=St(h,t),p=Math.abs(d-t.y);if(Math.abs(u.x-t.x)+Math.abs(c.x-t.x)-Math.abs(u.x-c.x)<4&&p*p/(h[0]*h[0]+1)<4)return!0}}}}catch(t){i={error:t}}finally{try{a&&!a.done&&(r=o.return)&&r.call(o)}finally{if(i)throw i.error}}return!1}function St(t,e){return null!==t?e.x*t[0]+t[1]:e.y}function Pt(t,e,i){return St(Mt(t,e),i)}function Mt(t,e){var i=t.x-e.x;if(0!==i){var r=(t.y-e.y)/i;return[r,t.y-r*t.x]}return null}function It(t,e,i){var r=e.length,n=a(i)?i>0&&i<1?i:0:i?.5:0;if(n>0&&r>2){for(var o=e[0].x,s=e[0].y,l=1;l<r-1;l++){var u=e[l-1],c=e[l],h=e[l+1],d=c.x-u.x,p=c.y-u.y,g=h.x-c.x,v=h.y-c.y,f=h.x-u.x,m=h.y-u.y,y=Math.sqrt(d*d+p*p),_=Math.sqrt(g*g+v*v),x=_/(_+y),b=c.x+f*n*x,w=c.y+m*n*x;b=Math.min(b,Math.max(h.x,c.x)),w=Math.min(w,Math.max(h.y,c.y)),b=Math.max(b,Math.min(h.x,c.x)),w=Math.max(w,Math.min(h.y,c.y)),f=b-c.x,m=w-c.y;var C=c.x-f*y/_,E=c.y-m*y/_;C=Math.min(C,Math.max(u.x,c.x)),E=Math.min(E,Math.max(u.y,c.y)),C=Math.max(C,Math.min(u.x,c.x)),E=Math.max(E,Math.min(u.y,c.y)),f=c.x-C,m=c.y-E,b=c.x+f*_/y,w=c.y+m*_/y,t.bezierCurveTo(o,s,C,E,c.x,c.y),o=b,s=w}var T=e[r-1];t.bezierCurveTo(o,s,T.x,T.y,T.x,T.y)}else for(l=1;l<r;l++)t.lineTo(e[l].x,e[l].y)}var Dt={name:"line",checkEventOn:Tt,draw:function(t,e,i){!function(t,e,i){var r=[];r=r.concat(e);var n=i.style,o=void 0===n?"solid":n,a=i.smooth,s=void 0!==a&&a,l=i.size,u=void 0===l?1:l,c=i.color,h=void 0===c?"currentColor":c,d=i.dashedValue,p=void 0===d?[2,2]:d;t.lineWidth=u,t.strokeStyle=h,"dashed"===o?t.setLineDash(p):t.setLineDash([]);var g=u%2==1?.5:0;r.forEach((function(e){var i=e.coordinates;i.length>1&&(2!==i.length||i[0].x!==i[1].x&&i[0].y!==i[1].y?(t.save(),u%2==1&&t.translate(.5,.5),t.beginPath(),t.moveTo(i[0].x,i[0].y),It(t,i,s),t.stroke(),t.closePath(),t.restore()):(t.beginPath(),i[0].x===i[1].x?(t.moveTo(i[0].x+g,i[0].y),t.lineTo(i[1].x+g,i[1].y)):(t.moveTo(i[0].x,i[0].y+g),t.lineTo(i[1].x,i[1].y+g)),t.stroke(),t.closePath()))}))}(t,e,i)}};function kt(t,e,i){var r=null!=i?i:0,n=[];if(t.length>1)if(t[0].x===t[1].x){var o=e.height;if(n.push({coordinates:[{x:t[0].x,y:0},{x:t[0].x,y:o}]}),t.length>2){n.push({coordinates:[{x:t[2].x,y:0},{x:t[2].x,y:o}]});for(var a=t[0].x-t[2].x,s=0;s<r;s++){var l=a*(s+1);n.push({coordinates:[{x:t[0].x+l,y:0},{x:t[0].x+l,y:o}]})}}}else{var u=e.width,c=Mt(t[0],t[1]),h=c[0],d=c[1];if(n.push({coordinates:[{x:0,y:0*h+d},{x:u,y:u*h+d}]}),t.length>2){var p=t[2].y-h*t[2].x;n.push({coordinates:[{x:0,y:0*h+p},{x:u,y:u*h+p}]});for(a=d-p,s=0;s<r;s++){var g=d+a*(s+1);n.push({coordinates:[{x:0,y:0*h+g},{x:u,y:u*h+g}]})}}}return n}function At(t,e){if(t.length>1){var 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:Pt(t[0],t[1],{x:0,y:t[0].y})}:{x:e.width,y:Pt(t[0],t[1],{x:e.width,y:t[0].y})},{coordinates:[t[0],i]}}return[]}var Ft={name:"simpleAnnotation",totalStep:2,styles:{line:{style:"dashed"}},createPointFigures:function(t){var e,i=t.overlay,r=t.coordinates,o="";s(i.extendData)&&(o=n(i.extendData)?i.extendData(i):null!==(e=i.extendData)&&void 0!==e?e:"");var a=r[0].x,l=r[0].y-6,u=l-50,c=u-5;return[{type:"line",attrs:{coordinates:[{x:a,y:l},{x:a,y:u}]},ignoreEvent:!0},{type:"polygon",attrs:{coordinates:[{x:a,y:u},{x:a-4,y:c},{x:a+4,y:c}]},ignoreEvent:!0},{type:"text",attrs:{x:a,y:c,text:o,align:"center",baseline:"bottom"},ignoreEvent:!0}]}},Bt={name:"simpleTag",totalStep:2,styles:{line:{style:"dashed"}},createPointFigures:function(t){var e=t.bounding,i=t.coordinates;return{type:"line",attrs:{coordinates:[{x:0,y:i[0].y},{x:e.width,y:i[0].y}]},ignoreEvent:!0}},createYAxisFigures:function(t){var e,i,r,o,l=t.chart,u=t.overlay,c=t.coordinates,h=t.bounding,d=t.yAxis,p="left",v=0;null!==(e=null==d?void 0:d.isFromZero())&&void 0!==e&&e?(p="left",v=0):(p="right",v=h.width);var f="";return s(u.extendData)&&(f=n(u.extendData)?u.extendData(u):null!==(i=u.extendData)&&void 0!==i?i:""),!s(f)&&a(u.points[0].value)&&(f=g(u.points[0].value,null!==(o=null===(r=l.getSymbol())||void 0===r?void 0:r.pricePrecision)&&void 0!==o?o:U)),{type:"text",attrs:{x:v,y:c[0].y,text:f,align:p,baseline:"middle"}}}},Rt={};function Lt(t){var e;return null!==(e=Rt[t])&&void 0!==e?e:null}[bt,wt,{name:"horizontalSegment",totalStep:3,needDefaultPointFigure:!0,needDefaultXAxisFigure:!0,needDefaultYAxisFigure:!0,createPointFigures:function(t){var e=t.coordinates,i=[];return 2===e.length&&i.push({coordinates:e}),[{type:"line",attrs:i}]},performEventPressedMove:function(t){var e=t.points,i=t.performPoint;e[0].value=i.value,e[1].value=i.value},performEventMoveForDrawing:function(t){var e=t.currentStep,i=t.points,r=t.performPoint;2===e&&(i[0].value=r.value)}},{name:"horizontalStraightLine",totalStep:2,needDefaultPointFigure:!0,needDefaultXAxisFigure:!0,needDefaultYAxisFigure:!0,createPointFigures:function(t){var e=t.coordinates,i=t.bounding;return[{type:"line",attrs:{coordinates:[{x:0,y:e[0].y},{x:i.width,y:e[0].y}]}}]}},{name:"parallelStraightLine",totalStep:4,needDefaultPointFigure:!0,needDefaultXAxisFigure:!0,needDefaultYAxisFigure:!0,createPointFigures:function(t){return[{type:"line",attrs:kt(t.coordinates,t.bounding)}]}},{name:"priceChannelLine",totalStep:4,needDefaultPointFigure:!0,needDefaultXAxisFigure:!0,needDefaultYAxisFigure:!0,createPointFigures:function(t){return[{type:"line",attrs:kt(t.coordinates,t.bounding,1)}]}},{name:"priceLine",totalStep:2,needDefaultPointFigure:!0,needDefaultXAxisFigure:!0,needDefaultYAxisFigure:!0,createPointFigures:function(t){var e,i,r,n=t.chart,o=t.coordinates,a=t.bounding,s=t.overlay,l=t.yAxis,u=0;null===(e=null==l?void 0:l.isInCandle())||void 0===e||e?u=null!==(r=null===(i=n.getSymbol())||void 0===i?void 0:i.pricePrecision)&&void 0!==r?r:U:n.getIndicators({paneId:s.paneId}).forEach((function(t){u=Math.max(u,t.precision)}));var c=s.points[0].value,h=void 0===c?0:c;return[{type:"line",attrs:{coordinates:[o[0],{x:a.width,y:o[0].y}]}},{type:"text",ignoreEvent:!0,attrs:{x:o[0].x,y:o[0].y,text:n.getDecimalFold().format(n.getThousandsSeparator().format(h.toFixed(u))),baseline:"bottom"}}]}},{name:"rayLine",totalStep:3,needDefaultPointFigure:!0,needDefaultXAxisFigure:!0,needDefaultYAxisFigure:!0,createPointFigures:function(t){return[{type:"line",attrs:At(t.coordinates,t.bounding)}]}},{name:"segment",totalStep:3,needDefaultPointFigure:!0,needDefaultXAxisFigure:!0,needDefaultYAxisFigure:!0,createPointFigures:function(t){var e=t.coordinates;return 2===e.length?[{type:"line",attrs:{coordinates:e}}]:[]}},{name:"straightLine",totalStep:3,needDefaultPointFigure:!0,needDefaultXAxisFigure:!0,needDefaultYAxisFigure:!0,createPointFigures:function(t){var e=t.coordinates,i=t.bounding;return 2===e.length?e[0].x===e[1].x?[{type:"line",attrs:{coordinates:[{x:e[0].x,y:0},{x:e[0].x,y:i.height}]}}]:[{type:"line",attrs:{coordinates:[{x:0,y:Pt(e[0],e[1],{x:0,y:e[0].y})},{x:i.width,y:Pt(e[0],e[1],{x:i.width,y:e[0].y})}]}}]:[]}},{name:"verticalRayLine",totalStep:3,needDefaultPointFigure:!0,needDefaultXAxisFigure:!0,needDefaultYAxisFigure:!0,createPointFigures:function(t){var e=t.coordinates,i=t.bounding;if(2===e.length){var r={x:e[0].x,y:0};return e[0].y<e[1].y&&(r.y=i.height),[{type:"line",attrs:{coordinates:[e[0],r]}}]}return[]},performEventPressedMove:function(t){var e=t.points,i=t.performPoint;e[0].timestamp=i.timestamp,e[0].dataIndex=i.dataIndex,e[1].timestamp=i.timestamp,e[1].dataIndex=i.dataIndex},performEventMoveForDrawing:function(t){var e=t.currentStep,i=t.points,r=t.performPoint;2===e&&(i[0].timestamp=r.timestamp,i[0].dataIndex=r.dataIndex)}},{name:"verticalSegment",totalStep:3,needDefaultPointFigure:!0,needDefaultXAxisFigure:!0,needDefaultYAxisFigure:!0,createPointFigures:function(t){var e=t.coordinates;return 2===e.length?[{type:"line",attrs:{coordinates:e}}]:[]},performEventPressedMove:function(t){var e=t.points,i=t.performPoint;e[0].timestamp=i.timestamp,e[0].dataIndex=i.dataIndex,e[1].timestamp=i.timestamp,e[1].dataIndex=i.dataIndex},performEventMoveForDrawing:function(t){var e=t.currentStep,i=t.points,r=t.performPoint;2===e&&(i[0].timestamp=r.timestamp,i[0].dataIndex=r.dataIndex)}},{name:"verticalStraightLine",totalStep:2,needDefaultPointFigure:!0,needDefaultXAxisFigure:!0,needDefaultYAxisFigure:!0,createPointFigures:function(t){var e=t.coordinates,i=t.bounding;return[{type:"line",attrs:{coordinates:[{x:e[0].x,y:0},{x:e[0].x,y:i.height}]}}]}},Ft,Bt].forEach((function(t){Rt[t.name]=xt.extend(t)}));var Ot={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 Wt(t){var e;return null!==(e=Ot[t])&&void 0!==e?e:null}var Vt="candle_pane",zt="indicator_pane_",Nt="x_axis_pane",Yt=1,Ht=50,Xt=function(){function t(t,e){var i,r,n,o,a,l=this;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:(a={show:!0,color:K.GREY,textOffset:5,textSize:10,textFamily:"Helvetica Neue",textWeight:"normal"},{type:"candle_solid",bar:{compareRule:"current_open",upColor:K.GREEN,downColor:K.RED,noChangeColor:K.GREY,upBorderColor:K.GREEN,downBorderColor:K.RED,noChangeBorderColor:K.GREY,upWickColor:K.GREEN,downWickColor:K.RED,noChangeWickColor:K.GREY},area:{lineSize:2,lineColor:K.BLUE,smooth:!1,value:"close",backgroundColor:[{offset:0,color:Q(K.BLUE,.01)},{offset:1,color:Q(K.BLUE,.2)}],point:{show:!0,color:K.BLUE,radius:4,rippleColor:Q(K.BLUE,.3),rippleRadius:8,animation:!0,animationDuration:1e3}},priceMark:{show:!0,high:T({},a),low:T({},a),last:{show:!0,compareRule:"current_open",upColor:K.GREEN,downColor:K.RED,noChangeColor:K.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:K.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:K.GREY,marginLeft:8,marginTop:4,marginRight:8,marginBottom:4,template:"{ticker} · {period}"},legend:{size:12,family:"Helvetica Neue",weight:"normal",color:K.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:[]}}),indicator:(n=Q(K.GREEN,.7),o=Q(K.RED,.7),{ohlc:{compareRule:"current_open",upColor:n,downColor:o,noChangeColor:K.GREY},bars:[{style:"fill",borderStyle:"solid",borderSize:1,borderDashedValue:[2,2],upColor:n,downColor