UNPKG

@viper-charts/viper-charts

Version:

A free and open-source cross market charting platform

2 lines 416 kB
/*! For license information please see viper.bundle.js.LICENSE.txt */ !function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports["viper-charts"]=t():e["viper-charts"]=t()}(self,(function(){return(()=>{var e={349:(e,t,n)=>{"use strict";function r(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}function o(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var n=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=n){var r,o,i=[],a=!0,u=!1;try{for(n=n.call(e);!(a=(r=n.next()).done)&&(i.push(r.value),!t||i.length!==t);a=!0);}catch(e){u=!0,o=e}finally{try{a||null==n.return||n.return()}finally{if(u)throw o}}return i}}(e,t)||function(e,t){if(e){if("string"==typeof e)return i(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?i(e,t):void 0}}(e,t)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function i(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n<t;n++)r[n]=e[n];return r}n.r(t),n.d(t,{default:()=>Ci});const a={uniqueId:function(){return Math.random().toString(36).substr(2,13)},getMinAndMax:function(e){for(var t=e.length,n=-1/0,r=1/0;t--;)n=e[t]>n?e[t]:n,r=e[t]<r?e[t]:r;return[r,n]},getAbsoluteMax:function(e,t){return e<0?Math.min(e,-t):Math.max(e,t)},randomHexColor:function(){return"#".concat(Math.floor(16777215*Math.random()).toString(16),"00000").substring(0,7)},getAllTimestampsIn:function(e,t,n){var r=((t+=n-t%n)-(e-=e%n))/n;return r%1!=0||0===r?[]:new Array(r).fill().map((function(t,r){return e+n*r}))},getTimestampByXCoord:function(e,t,n,r){return e+r/n*(t-e)},getXCoordByTimestamp:function(e,t,n,r){var o=(r-e)/(t-e);return Math.floor(o*n)},getYCoordByPrice:function(e,t,n,r){var o=(r-e)/(t-e);return-Math.floor(o*n-n)},getPriceByYCoord:function(e,t,n,r){return e+(1-r/n)*(t-e)},wipeObject:function(e){for(var t in e)delete e[t];return e},toFixed:function(e,t){return+parseFloat(e).toFixed(t)},getDecimalPlaces:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:1/0;if(isNaN(e))return 0;var n=e.toString();if(n.indexOf("e-")>-1){var r=n.split("e-"),i=o(r,2),a=(i[0],i[1]);return Math.min(parseInt(a,10),t)}return Math.floor(e)!==e?Math.min(e.toString().split(".")[1].length||0,t):0},isColorLight:function(e){var t,n,r;return e.match(/^rgb/)?(t=(e=e.match(/^rgba?\((\d+),\s*(\d+),\s*(\d+)(?:,\s*(\d+(?:\.\d+)?))?\)$/))[1],n=e[2],r=e[3]):(t=(e=+("0x"+e.slice(1).replace(e.length<5&&/./g,"$&$&")))>>16,n=e>>8&255,r=255&e),Math.sqrt(t*t*.299+n*n*.587+r*r*.114)>127.5},aZ:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:2;return"0000000000000000".concat(e).substr(-t)},DateWrapper:function(){function e(t){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),this.value=new Date(t)}var t,n;return t=e,(n=[{key:"time",value:function(){return this.value.getTime()}},{key:"ms",value:function(){return this.value.getMilliseconds()}},{key:"s",value:function(){return this.value.getSeconds()}},{key:"m",value:function(){return this.value.getMinutes()}},{key:"h",value:function(){return this.value.getHours()}},{key:"d",value:function(){return Math.floor(this.value.getTime()/864e5)}}])&&r(t.prototype,n),Object.defineProperty(t,"prototype",{writable:!1}),e}(),formatTimeLeft:function(e,t){var n=this.aZ,r=t-e%t,o=new this.DateWrapper(r);return r<6e4?"".concat(n(o.s()),".").concat(n(o.ms(),4)):r<36e5?"".concat(n(o.m()),"m:").concat(n(o.s()),"s"):r<864e5?"".concat(n(o.h()),"h:").concat(n(o.m()),"m"):"".concat(n(o.d()),"d:").concat(n(o.h()),"h")}};function u(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}var l=function(){function e(){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),this._events={}}var t,n;return t=e,n=[{key:"addEventListener",value:function(e,t){var n=a.uniqueId();return void 0!==this._events[e]?this._events[e].push(t):this._events[e]=[t],n}},{key:"removeEventListener",value:function(e,t){var n=this._events[e];if(n){var r=n.indexOf(t);-1!==r&&n.splice(r,1)}}},{key:"fireEvent",value:function(e){var t=Object.values(this._events[e]||{});if(t&&t.length){for(var n=arguments.length,r=new Array(n>1?n-1:0),o=1;o<n;o++)r[o-1]=arguments[o];for(var i=0,a=t;i<a.length;i++){var u=a[i];u.apply(void 0,r)}}}}],n&&u(t.prototype,n),Object.defineProperty(t,"prototype",{writable:!1}),e}(),s=1e3,c=6e4,f=36e5,d=24*f,h=7*d,p=4*h,y=365*d,v={ms:1,s,m:c,h:f,d,w:h,mo:p,y};const m={MILLISECOND:1,MILLISECOND100:100,SECOND:s,MINUTE:c,MINUTE5:3e5,MINUTE15:9e5,HOUR:f,HOUR4:144e5,HOUR12:432e5,DAY:d,WEEK:h,MONTH:p,YEAR:y,TIMESCALES:[10*y,5*y,3*y,2*y,y,6*p,4*p,3*p,2*p,p,15*d,10*d,7*d,5*d,3*d,2*d,d,12*f,6*f,4*f,2*f,f,18e5,9e5,6e5,3e5,12e4,c,3e4,15e3,1e4,5e3,2e3,s,500,250,100,50,1],TIMEFRAMES:v,MONTHS:[{short:"Jan",long:"January"},{short:"Feb",long:"February"},{short:"Mar",long:"March"},{short:"Apr",long:"April"},{short:"May",long:"May"},{short:"Jun",long:"June"},{short:"Jul",long:"July"},{short:"Aug",long:"August"},{short:"Sep",long:"September"},{short:"Oct",long:"October"},{short:"Nov",long:"November"},{short:"Dec",long:"December"}],getTimeframeText:function(e){for(var t=Object.keys(v),n=0;n<t.length;n++)if(e/v[t[n]]<1){var r=t[n-1];return"".concat(e/v[r]).concat(r)}}};function g(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function b(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?g(Object(n),!0).forEach((function(t){w(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):g(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}function w(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function k(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var n=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=n){var r,o,i=[],a=!0,u=!1;try{for(n=n.call(e);!(a=(r=n.next()).done)&&(i.push(r.value),!t||i.length!==t);a=!0);}catch(e){u=!0,o=e}finally{try{a||null==n.return||n.return()}finally{if(u)throw o}}return i}}(e,t)||function(e,t){if(e){if("string"==typeof e)return x(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?x(e,t):void 0}}(e,t)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function x(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n<t;n++)r[n]=e[n];return r}var S={"volume-bar":{version:"1.0.0",name:"Volume",dependencies:["ohlc","volume"],draw:function(e){var t=e.open,n=e.close,r=e.plotVolume,o=n>=t?this.upColor:this.downColor;r({volume:S,color:o})}}},_={bases:{line:{version:"1.0.0",name:"Line",dependencies:["value"],draw:function(e){var t=e.value;(0,e.plot)({value:t,title:"Line",color:this.color,linewidth:2,ylabel:!0})}},candlestick:{version:"1.0.0",name:"Candlestick",dependencies:["ohlc"],draw:function(e){var t=e.open,n=e.high,r=e.low,o=e.close,i=o>=t?"#C4FF49":"#FE3A64";(0,e.plotCandle)({open:t,high:n,low:r,close:o,title:"Candlestick",color:i,wickcolor:i,ylabel:!0})}},volumeBySide:{version:"1.0.0",name:"Volume By Side",dependencies:["volumeBySide"],draw:function(e){var t=e.buyVolume,n=e.sellVolume,r=e.plotBox,o=t-n,i=t+n;0!==i&&r({top:i,bottom:0,width:.9,center:!0,color:o>=0?"#C4FF4966":"#FE3A6466"}),0!==o&&r({top:Math.abs(o),bottom:0,width:.9,center:!0,color:o>=0?"#C4FF49":"#FE3A64"})}},footprint:{version:"1.0.0",name:"Footprint",dependencies:["footprint"],draw:function(e){var t=e.spread,n=e.prices,r=e.plotBox;for(var o in n){var i=n[o=+o],a=i.buy,u=i.sell;a&&r({top:o+t,bottom:o,width:a/3,color:"#C4FF49",text:a}),u&&r({top:o+t,bottom:o,width:-u/3,color:"#FE3A64",text:u})}}}},volume:S,indicators:{sma:{version:"1.0.0",name:"SMA",dependencies:["value"],draw:function(e){(0,e.plot)({value:(0,e.sma)({source:"value",length:20}),title:"MA20",color:this.color,linewidth:2})}},"ma-slope":{version:"1.0.0",name:"MA Slope",dependencies:["value"],draw:function(e){var t=e.plot,n=e.sma,r=e.math,o=e.setVar,i=e.getVar,a=n({source:"value",length:20});o({name:"ma20",value:a}),t({value:r.sub(a,i({name:"ma20",lookback:1})),title:"MA20 Slope",color:this.color,linewidth:2,ylabel:!0})}},bbands:{version:"1.0.0",name:"Bollinger Bands",dependencies:["value"],draw:function(e){var t=e.plot,n=e.fill,r=k((0,e.bbands)({source:"value",length:20,multiplier:2}),3),o=r[0],i=r[1],a=r[2];n({value1:i,value2:a,color:"#5142f511"}),t({value:o,color:"#ba7d13",linewidth:1}),t({value:i,color:"#5142f5",linewidth:1}),t({value:a,color:"#5142f5",linewidth:1})}},bbw:{version:"1.0.0",name:"Bollinger Bands Width",dependencies:["value"],draw:function(e){var t=e.plot,n=e.bbands,r=e.math,o=k(n({source:"value",length:20,multiplier:2}),3),i=o[0],a=o[1],u=o[2];t({value:+r.divide(r.sub(a,u),i).toFixed(4),color:this.color,linewidth:2,ylabel:!0})}},cvd:{version:"1.0.0",name:"Cumulative Volume Delta",dependencies:["volumeBySide"],draw:function(e){for(var t=e.plot,n=e.cum,r=n({source:"buyVolume"}),o=n({source:"sellVolume"}),i=0,a=0;a<r.length;a++)i+=r[a]-o[a];t({value:+i.toFixed(4),color:this.color,linewidth:2,ylabel:!0})}},"delta-bars":{version:"1.0.0",name:"Delta Bars",dependencies:["value"],draw:function(e){var t=e.plotBox,n=e.value;t({top:n>=0?n:0,bottom:n>=0?0:n,width:.9,center:!0,color:n>=0?"#C4FF49":"#FE3A64"})}},deltafootprint:{version:"1.0.0",name:"Delta Footprint",dependencies:["footprint"],draw:function(e){var t=e.spread,n=e.prices,r=e.plotBox;for(var o in n){var i=n[o=+o],a=i.buy-i.sell;r({top:o+t,bottom:o,width:Math.abs(a)/3,color:a>=0?"#C4FF49":"#FE3A64"})}}},volumePerTick:{version:"1.0.0",name:"Volume Per Tick",dependencies:["footprint"],draw:function(e){var t=e.spread,n=e.prices,r=e.plotBox,o=Object.keys(n),i=Math.max(Math.abs(o[0]-o[o.length-1])/t,t),a=0,u=0;for(var l in n)a+=n[l].buy,u+=n[l].sell;var s=a+u,c=a/i*s,f=u/i*s,d=c-f;r({top:Math.floor(c),bottom:0,width:.9,center:!0,color:"#C4FF4966"}),r({top:0,bottom:-Math.ceil(f),width:.9,center:!0,color:"#FE3A6466"}),r({top:d>0?Math.floor(d):0,bottom:d>0?0:Math.floor(d),width:.9,center:!0,color:d>0?"#C4FF49":"#FE3A64"})}},volumeProfileSession:{version:"1.0.0",name:"Volume Profile Session",dependencies:["footprint"],draw:function(e){var t=e.spread,n=e.prices,r=e.plotBox,o=e.math,i=0,a={};for(var u in n){var l=n[u],s=l.buy,c=l.sell,f=o.add(s,c),d=o.sub(s,c);a[u]={total:f,delta:d},f>i&&(i=f)}for(var h in a){var p=a[h=+h],y=p.total,v=p.delta;r({top:h+t,bottom:h,width:y/i*.9,color:v>=0?"#C4FF49AA":"#FE3A64AA"}),r({top:h+t,bottom:h,width:Math.abs(v)/i*.9,color:v>=0?"#C4FF49":"#FE3A64",text:"T:".concat(y," D:").concat(v)})}}},ohlcChange:{version:"1.0.0",name:"OHLC Change",dependencies:["ohlc"],draw:function(e){var t=e.open,n=e.high,r=e.low,o=e.close,i=e.plotBox,a=Math.max(n-t,0),u=Math.min(r-t,0),l=o-t;i({top:a,bottom:0,width:.9,center:!0,color:"#C4FF4966"}),i({top:0,bottom:u,width:.9,center:!0,color:"#FE3A6466"}),i({top:l,bottom:0,width:.9,center:!0,color:l>0?"#C4FF49":"#FE3A64"})}}}};for(var E in _)for(var O in _[E]){var C=_[E][O];C.id=O,C.type=E}const j=b(b({},_),{},{getIndicatorById:function(e){for(var t in _)for(var n in _[t])if(n===e)return _[t][n]}});var P=n(486),R=n.n(P);const T={main:{background:{},values:{},plots:{}},yScale:{background:{},scales:[],plots:{},crosshair:{}},xScale:{background:{},scales:[],crosshair:{}}};const I={scaleText:function(e,t){return"percent"===t?"".concat(e>=0?"+":"").concat(e,"%"):"".concat(e)}};function $(e){return $="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},$(e)}function L(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var n=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=n){var r,o,i=[],a=!0,u=!1;try{for(n=n.call(e);!(a=(r=n.next()).done)&&(i.push(r.value),!t||i.length!==t);a=!0);}catch(e){u=!0,o=e}finally{try{a||null==n.return||n.return()}finally{if(u)throw o}}return i}}(e,t)||D(e,t)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function M(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){if(Array.isArray(e)||(n=D(e))||t&&e&&"number"==typeof e.length){n&&(e=n);var r=0,o=function(){};return{s:o,n:function(){return r>=e.length?{done:!0}:{done:!1,value:e[r++]}},e:function(e){throw e},f:o}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var i,a=!0,u=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return a=e.done,e},e:function(e){u=!0,i=e},f:function(){try{a||null==n.return||n.return()}finally{if(u)throw i}}}}function D(e,t){if(e){if("string"==typeof e)return N(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?N(e,t):void 0}}function N(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n<t;n++)r[n]=e[n];return r}function A(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}var z=function(){function e(t){var n=t.canvas,r=t.$state,o=t.type;t.settings,function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),this.$state=r,this.canvas=n,this.type=o,this.overlayQueue=new Map,this.renderingOrder=[],this.initDraw()}var t,n;return t=e,n=[{key:"initDraw",value:function(){requestAnimationFrame(this.recursiveDraw.bind(this))}},{key:"recursiveDraw",value:function(){this.draw(),requestAnimationFrame(this.recursiveDraw.bind(this))}},{key:"draw",value:function(){var e,t=this,n=this.$state.chart.instructions[this.type],r=this.$state.global.layout.chartDimensions[this.$state.chart.id];if(this.canvas.ctx.clearRect(0,0,this.canvas.width,this.canvas.height),"yScale"===this.type){var o=Date.now(),i=!1;this.canvas.drawBox("#080019",[0,0,r.yScale.width,r.yScale.height]);var u=0;for(var l in n.scales){var s,c=M(n.scales[l]);try{for(c.s();!(s=c.n()).done;){var f=s.value,d=f.x,h=f.y,p=f.color,y=f.text;this.canvas.drawText(p,[d,h],y)}}catch(e){c.e(e)}finally{c.f()}}for(var v in n.plots)if(n.plots[v]){var g=n.plots[v],b=(g.layerId,g.values);if(b&&b.length){var w=L(b,2),k=w[0],x=w[1],S=this.canvas.ctx,_=Math.ceil(S.measureText(x.text).width);if(_>u&&(u=_),this.canvas.drawBox(k.color,[k.x,k.y,k.w,k.h]),this.canvas.drawText(x.color,[x.x,x.y],x.text,{font:x.font}),!i){var E=k.y+k.h,O=a.formatTimeLeft(o,this.$state.chart.timeframe);this.canvas.drawBox(k.color,[k.x,E,k.w,k.h]),this.canvas.drawText(x.color,[x.x,E+k.h/2],O,{font:x.font}),i=!0}}}u=Math.max(u+=10,50),Math.floor(u/5)!==Math.floor(r.yScale.width/5)&&(r.setYScaleWidth(u),this.$state.chart.setVisibleRange({}));var C=this.$state.global.crosshair.price,j=this.$state.global.crosshair.crosshairs[this.$state.chart.id].y;if(this.$state.global.crosshair.visible){var P=r.yScale.width;for(var R in j){var T=this.$state.chart.ranges.y[R];if(T){var A=I.scaleText(C,T.scaleType);this.canvas.drawBox("#424242",[0,j[R]-10,P,20]),this.canvas.drawText("#fff",[P/2,j[R]+3],A)}}}var z=r.main,B=z.width,F=z.layers;for(var U in this.canvas.drawBox("#2E2E2E",[0,0,B,2]),F){var G=F[U],W=G.top,V=G.height;this.canvas.drawBox("#2E2E2E",[0,W+V-2,B,4])}}if("xScale"===this.type){this.canvas.drawBox("#080019",[0,0,r.xScale.width,r.xScale.height]);var q,Q=M(n.scales);try{for(Q.s();!(q=Q.n()).done;){var H=q.value,Y=H.color,Z=H.x,K=H.y,X=H.text;this.canvas.drawText(Y,[Z,K],X)}}catch(e){Q.e(e)}finally{Q.f()}var J=this.$state.global.crosshair;if(J.visible){var ee=new Date(J.timestamp),te="0".concat(ee.getDate()).slice(-2),ne=m.MONTHS[ee.getMonth()].short,re=ee.getFullYear().toString().substr(2,2),oe=ee.getHours(),ie="0".concat(ee.getMinutes()).slice(-2),ae="".concat(te," ").concat(ne," '").concat(re," ").concat(oe,":").concat(ie),ue=J.crosshairs[this.$state.chart.id].x;this.canvas.drawBox("#424242",[ue-45,0,90,30]),this.canvas.drawText("#fff",[ue,15],ae)}}if("main"===this.type){this.canvas.drawBox("#080019",[0,0,r.main.width,r.main.height]),function(){var e,n=r.main,o=n.height,i=n.width,a=t.$state.chart.instructions,u=a.xScale,l=a.yScale,s="#43434377",c=M(u.scales);try{for(c.s();!(e=c.n()).done;){var f=e.value.x;t.canvas.drawLine(s,[f,0,f,o])}}catch(e){c.e(e)}finally{c.f()}for(var d in l.scales){var h,p=M(l.scales[d]);try{for(p.s();!(h=p.n()).done;){var y=h.value.y;t.canvas.drawLine(s,[0,y,i,y])}}catch(e){p.e(e)}finally{p.f()}}}();var le,se=function(e){if(Array.isArray(e))return N(e)}(e=this.renderingOrder)||function(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(e)||D(e)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}(),ce=M(se);try{var fe=function(){var e=le.value,r=t.overlayQueue.get(e);if(r){var o=r.overlay;return o.drawFunc.bind(o)(),"continue"}if(!n.values[e])return"continue";var i=n.values[e],a=(i.layerId,i.values);if(!a)return"continue";for(var u=Object.keys(a),l=function(e,n,r){if("line"===e.type){if(void 0===n||void 0===r)return;var o=a[u[n+1]];if(!o)return;if(!(o=o[r]))return;t.canvas.drawLine(e.color,[e.x,e.y,o.x,o.y],e.linewidth)}else if("fill"===e.type){if(void 0===n||void 0===r)return;var i=a[u[n+1]];if(!i)return;i=i[r],t.canvas.drawPolygon(e.color,[i.x,i.y1,e.x,e.y1,e.x,e.y2,i.x,i.y2])}else"polygon"===e.type?t.canvas.drawPolygon(e.color,e.coords):"box"===e.type?t.canvas.drawBox(e.color,[e.x,e.y,e.w,e.h]):"single-line"===e.type?t.canvas.drawLine(e.color,[e.x,e.y,e.x2,e.y2]):"text"===e.type&&t.canvas.drawText(e.color,[e.x,e.y],e.text,{font:e.font,textAlign:e.textAlign,stroke:e.stroke})},s=0;s<u.length;s++)for(var c=a[u[s]],f=0;f<c.length;f++)l(c[f],s,f)};for(ce.s();!(le=ce.n()).done;)fe()}catch(e){ce.e(e)}finally{ce.f()}var de=this.$state.chart,he=de.datasetGroups[de.selectedDatasetGroup];if(null!=he&&he.visible){var pe=he.datasets[0],ye=pe.source,ve=pe.name,me=this.$state.global.orders.datasets["".concat(ye,":").concat(ve)];if("object"===$(me))for(var ge in me){var be=me[ge],we=be.price,ke=be.side,xe=be.quantity,Se=this.$state.chart.getYCoordByPrice(we),_e=(r.yScale.width,r.xScale.width),Ee="buy"===ke?"#C4FF49":"#FE3A64";this.canvas.drawLine(Ee,[0,Se,_e,Se],1);var Oe="".concat(ke," ").concat(xe," at ").concat(we);this.canvas.drawText("#FFF",[_e-5*Oe.length,Se+10],Oe)}}var Ce,je=M(se);try{for(je.s();!(Ce=je.n()).done;){var Pe=Ce.value;if(n.plots[Pe]){var Re=n.plots[Pe],Te=(Re.layerId,Re.values);if(Te&&Te.length){var Ie=L(Te,2),$e=Ie[0],Le=Ie[1];this.canvas.drawBox($e.color,[$e.x,$e.y,$e.w,$e.h]),this.canvas.drawText(Le.color,[Le.x,Le.y],Le.text,{font:Le.font})}}}}catch(e){je.e(e)}finally{je.f()}var Me=this.$state.chart.ranges.y,De=Object.values(Me).find((function(e){return e.fullscreen}))?"#0a6102":"#2E2E2E",Ne=r.main,Ae=Ne.width,ze=Ne.height,Be=Ne.layers;for(var Fe in this.canvas.drawBox(De,[0,0,2,ze]),this.canvas.drawBox(De,[0,0,Ae,2]),this.canvas.drawBox(De,[Ae-2,0,2,ze]),Be){var Ue=Be[Fe],Ge=Ue.top,We=Ue.height;this.canvas.drawBox(De,[0,Ge+We-2,Ae,4])}}}},{key:"addToRenderingOrder",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:this.renderingOrder.length;this.renderingOrder.join(),this.renderingOrder.splice(t,0,e)}},{key:"removeFromRenderingOrder",value:function(e){var t=this.renderingOrder.indexOf(e);delete T[e],this.renderingOrder.splice(t,1)}},{key:"adjustInstructions",value:function(e){var t=e.newRange,n=e.oldRange,r=this.canvas;r.width,r.height,t.end,t.start,t.max,t.min,n.start,t.start,n.end,t.end,t.start,n.start,t.min,n.min}},{key:"addOverlay",value:function(e){var t=a.uniqueId();do{t=a.uniqueId()}while(this.renderingOrder.includes(t));return this.overlayQueue.set(t,{overlay:e,visible:!0}),this.addToRenderingOrder(t),t}}],n&&A(t.prototype,n),Object.defineProperty(t,"prototype",{writable:!1}),e}();function B(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function F(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function U(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var n=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=n){var r,o,i=[],a=!0,u=!1;try{for(n=n.call(e);!(a=(r=n.next()).done)&&(i.push(r.value),!t||i.length!==t);a=!0);}catch(e){u=!0,o=e}finally{try{a||null==n.return||n.return()}finally{if(u)throw o}}return i}}(e,t)||function(e,t){if(e){if("string"==typeof e)return G(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?G(e,t):void 0}}(e,t)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function G(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n<t;n++)r[n]=e[n];return r}function W(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}var V=function(){function e(t){var n=t.$state,r=t.canvas,o=t.type,i=void 0===o?"":o,a=t.cursor,u=void 0===a?"default":a;!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),this.$state=n,this.canvas=null,this.ctx=null,this.RE=null,this.type=i,this.cursor=u,this.isMouseDown=!1,this.width=0,this.height=0,this.setCanvasElement(r),this.init()}var t,n;return t=e,n=[{key:"init",value:function(){this.RE=new z({canvas:this,$state:this.$state,type:this.type})}},{key:"destroy",value:function(){this.canvas.removeEventListener("mousedown",this.onCanvasMouseDown),this.$state.global.events.removeEventListener("mouseup",this.onEventMouseUp)}},{key:"setCursor",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"";this.cursor=e,this.canvas.style.cursor=e}},{key:"setCanvasElement",value:function(e){var t=this;this.ctx=e.getContext("2d"),e.style.cursor=this.cursor,e.width=e.clientWidth,this.width=e.clientWidth,e.height=e.clientHeight,this.height=e.clientHeight,this.onCanvasMouseDown=function(){return t.isMouseDown=!0}.bind(this),e.addEventListener("mousedown",this.onCanvasMouseDown),this.onEventMouseUp=function(){return t.isMouseDown=!1}.bind(this),this.$state.global.events.addEventListener("mouseup",this.onEventMouseUp),this.canvas=e}},{key:"drawBox",value:function(e,t){var n=U(t,4),r=n[0],o=n[1],i=n[2],u=n[3];this.ctx.fillStyle=e,this.ctx.fillRect(r,o,a.getAbsoluteMax(i,1),a.getAbsoluteMax(u,1))}},{key:"drawText",value:function(e,t,n,r){var o=U(t,2),i=o[0],a=o[1];r=function(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?B(Object(n),!0).forEach((function(t){F(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):B(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}({textAlign:"center",font:"10px Arial",stroke:!1},r),this.ctx.textAlign=r.textAlign,this.ctx.font=r.font,this.ctx.fillStyle=e,r.stroke?this.ctx.strokeText(n,i,a):this.ctx.fillText(n,i,a)}},{key:"drawBoxByPriceAndPercWidthOfTime",value:function(e,t,n){var r=this.$state.chart.pixelsPerElement*n,o=this.$state.chart.getXCoordByTimestamp(t[0]),i=this.$state.chart.getYCoordByPrice(t[1]),a=this.$state.chart.getYCoordByPrice(t[2])-i;a>=0?this.drawBox(e,[o-r/2,i,Math.max(r,1),Math.max(a,1)]):this.drawBox(e,[o-r/2,i,Math.max(r,1),Math.min(a,1)])}},{key:"drawLine",value:function(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:1;this.ctx.strokeStyle=e,this.ctx.lineWidth=n,this.ctx.beginPath(),this.ctx.moveTo(Math.floor(t[0]),Math.floor(t[1])),this.ctx.lineTo(Math.floor(t[2]),Math.floor(t[3])),this.ctx.stroke(),this.ctx.closePath()}},{key:"drawPolygon",value:function(e,t){this.ctx.beginPath(),this.ctx.fillStyle=e,this.ctx.moveTo(t[0],t[1]);for(var n=2;n<t.length;n+=2)this.ctx.lineTo(t[n],t[n+1]);this.ctx.fill(),this.ctx.closePath()}},{key:"drawLineByPriceAndTime",value:function(e,t){this.ctx.strokeStyle=e,this.ctx.beginPath();var n=this.$state.chart.getXCoordByTimestamp(t[0]),r=this.$state.chart.getYCoordByPrice(t[1]);this.ctx.moveTo(n,r);var o=this.$state.chart.getXCoordByTimestamp(t[2]),i=this.$state.chart.getYCoordByPrice(t[3]);this.ctx.lineTo(o,i),this.ctx.stroke(),this.ctx.closePath()}},{key:"drawTextAtPriceAndTime",value:function(e,t,n){this.ctx.textAlign="center",this.ctx.fillStyle=e;var r=this.$state.chart.getXCoordByTimestamp(t[0]);this.ctx.fillText(n,r,t[1])}},{key:"setWidth",value:function(e){this.width=e,this.canvas.width=e,this.canvas.style.width="".concat(e,"px"),this.RE&&this.RE.draw()}},{key:"setHeight",value:function(e){this.height=e,this.canvas.height=e,this.canvas.style.height="".concat(e,"px"),this.RE&&this.RE.draw()}},{key:"onMouseDown",value:function(){this.isMouseDown=!0}},{key:"onMouseUp",value:function(){this.isMouseDown=!1}}],n&&W(t.prototype,n),Object.defineProperty(t,"prototype",{writable:!1}),e}();function q(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}function Q(e,t,n){return t&&q(e.prototype,t),n&&q(e,n),Object.defineProperty(e,"prototype",{writable:!1}),e}function H(e){return H="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},H(e)}function Y(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}function Z(e,t){return Z=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e},Z(e,t)}function K(e,t){if(t&&("object"===H(t)||"function"==typeof t))return t;if(void 0!==t)throw new TypeError("Derived constructors may only return object or undefined");return function(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(e)}function X(e){return X=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)},X(e)}var J=function(e){!function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),Object.defineProperty(e,"prototype",{writable:!1}),t&&Z(e,t)}(a,e);var t,n,r,o,i=(r=a,o=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}(),function(){var e,t=X(r);if(o){var n=X(this).constructor;e=Reflect.construct(t,arguments,n)}else e=t.apply(this,arguments);return K(this,e)});function a(e){var t,n=e.canvas,r=e.$state;return function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,a),(t=i.call(this)).$state=r,t.canvas=n,t}return t=a,(n=[{key:"init",value:function(e){this.drawImplementation=e,this.canvas.RE.addOverlay(this)}},{key:"drawFunc",value:function(){this.drawImplementation()}}])&&Y(t.prototype,n),Object.defineProperty(t,"prototype",{writable:!1}),a}(Q((function e(){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e)})));function ee(e){return ee="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},ee(e)}function te(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}function ne(e,t){return ne=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e},ne(e,t)}function re(e,t){if(t&&("object"===ee(t)||"function"==typeof t))return t;if(void 0!==t)throw new TypeError("Derived constructors may only return object or undefined");return oe(e)}function oe(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function ie(e){return ie=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)},ie(e)}var ae=function(e){!function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),Object.defineProperty(e,"prototype",{writable:!1}),t&&ne(e,t)}(a,e);var t,n,r,o,i=(r=a,o=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}(),function(){var e,t=ie(r);if(o){var n=ie(this).constructor;e=Reflect.construct(t,arguments,n)}else e=t.apply(this,arguments);return re(this,e)});function a(e){var t,n=e.$state,r=e.canvas;return function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,a),(t=i.call(this,{canvas:r,$state:n})).init(t.draw.bind(oe(t))),t}return t=a,(n=[{key:"draw",value:function(){if(this.$state.global.crosshair.visible){var e=this.$state.global.crosshair.crosshairs[this.$state.chart.id],t=e.x,n=e.y;for(var r in this.canvas.drawLine("#ffffff88",[t,0,t,this.canvas.height]),n)this.canvas.drawLine("#ffffff88",[0,n[r],this.canvas.width,n[r]])}}}])&&te(t.prototype,n),Object.defineProperty(t,"prototype",{writable:!1}),a}(J);function ue(e){return ue="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},ue(e)}function le(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}function se(e,t){return se=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e},se(e,t)}function ce(e,t){if(t&&("object"===ue(t)||"function"==typeof t))return t;if(void 0!==t)throw new TypeError("Derived constructors may only return object or undefined");return fe(e)}function fe(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function de(e){return de=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)},de(e)}var he=function(e){!function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),Object.defineProperty(e,"prototype",{writable:!1}),t&&se(e,t)}(a,e);var t,n,r,o,i=(r=a,o=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}(),function(){var e,t=de(r);if(o){var n=de(this).constructor;e=Reflect.construct(t,arguments,n)}else e=t.apply(this,arguments);return ce(this,e)});function a(e){var t,n=e.$state,r=e.canvas;return function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,a),(t=i.call(this,{$state:n,canvas:r})).upColor="#C4FF4966",t.downColor="#FE3A6466",t.init(t.draw.bind(fe(t))),t}return t=a,(n=[{key:"draw",value:function(){}}])&&le(t.prototype,n),Object.defineProperty(t,"prototype",{writable:!1}),a}(J);function pe(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}var ye=function(){function e(t){var n=t.$state;!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),this.$state=n,this.canvas=null,this.scrollListener=null,this.mousemoveListener=null,this.mouseleaveListener=null,this.layerToMove=-1,this.change={x:0,y:0},this.debounceSetVisibleRange=R().throttle(this.calculateNewVisibleRange.bind(this),16)}var t,n;return t=e,n=[{key:"init",value:function(){var e=this,t=this.$state.global.ui.charts[this.$state.chart.id].subcharts;this.setCanvasElement(t.main.current),new he({$state:this.$state,canvas:this.canvas}),new ae({$state:this.$state,canvas:this.canvas}),this.onResizeChart=function(t){var n=t.main;e.canvas.setWidth(n.width),e.canvas.setHeight(n.height),e.$state.chart.setVisibleRange()}.bind(this),this.$state.global.layout.addEventListener("resize-".concat(this.$state.chart.id),this.onResizeChart),this.onResizeYScale=function(t){var n=t.main;e.canvas.setWidth(n.width)}.bind(this),this.$state.global.layout.addEventListener("resize-y-scale-".concat(this.$state.chart.id),this.onResizeYScale),this.onWindowMouseMoveListener=this.onWindowMouseMove.bind(this),this.$state.global.events.addEventListener("mousemove",this.onWindowMouseMoveListener)}},{key:"destroy",value:function(){this.$state.global.layout.removeEventListener("resize-".concat(this.$state.chart.id),this.onResizeChart),this.$state.global.layout.removeEventListener("resize-y-scale-".concat(this.$state.chart.id),this.onResizeYScale),this.$state.global.events.removeEventListener("mousemove",this.onWindowMouseMoveListener),this.removeCanvasListeners(this.canvas.canvas)}},{key:"setCanvasElement",value:function(e){this.canvas&&this.canvas.canvas&&this.removeCanvasListeners(this.canvas.canvas),this.canvas||(this.canvas=new V({$state:this.$state,id:"canvas-".concat(this.$state.chart.id,"-main"),canvas:e,type:"main",height:this.$state.dimensions.height-20,width:this.$state.dimensions.width-50,cursor:"crosshair"})),this.scrollListener=this.onScroll.bind(this),e.addEventListener("wheel",this.scrollListener),this.mousemoveListener=this.onMouseMove.bind(this),e.addEventListener("mousemove",this.mousemoveListener),this.mouseLeaveListener=this.onMouseLeave.bind(this),e.addEventListener("mouseleave",this.mouseLeaveListener),this.mouseEnterListener=this.onMouseEnter.bind(this),e.addEventListener("mouseenter",this.mouseEnterListener),this.canvas.setCanvasElement(e)}},{key:"removeCanvasListeners",value:function(e){e.removeEventListener("wheel",this.scrollListener),e.removeEventListener("mousemove",this.mousemoveListener),e.removeEventListener("mouseleave",this.mouseLeaveListener),e.removeEventListener("mouseenter",this.mouseEnterListener)}},{key:"onScroll",value:function(e){e.preventDefault();var t=e.deltaX,n=e.deltaY,r=e.offsetX,o=e.offsetY,i=this.$state.chart.id,a=this.$state.global.layout.chartDimensions[i].main,u=a.width;if(0!==t){var l=this.$state.chart,s=u/l.pixelsPerElement*(t>0?100*t:-100*-t)*(l.timeframe/6e4),c=this.$state.chart.ranges.x,f=c.start,d=c.end;f+=s,d+=s,this.$state.chart.setVisibleRange({start:f,end:d})}else if(0!==n){var h=this.$state.chart.getLayerByYCoord(o),p=this.$state.chart.ranges.y[h],y=this.$state.chart.ranges.x,v=y.start,m=y.end,g=p.range,b=g.min,w=g.max;if(this.$state.global.events.keys.Control||this.$state.global.events.keys.Shift){p.lockedYScale=!1;var k=a.layers[h],x=(o-k.top)/k.height,S=1-x,_=w-b;this.$state.global.events.keys.Shift&&(n=-n),n<0?(w-=_*x/10,b+=_*S/10):(w+=_*x/10,b-=_*S/10)}if(!this.$state.global.events.keys.Shift){var E=r/u,O=1-E,C=m-v;n>0?(v-=C*E/10,m+=C*O/10):(v+=C*E/10,m-=C*O/10)}this.$state.chart.setVisibleRange({start:v,end:m,min:b,max:w},h)}}},{key:"onMouseMove",value:function(e){this.$state.global.crosshair.updateCrosshair(this.$state.chart,e.offsetX,e.offsetY)}},{key:"onMouseLeave",value:function(e){this.$state.global.crosshair.visible=!1}},{key:"onMouseEnter",value:function(){this.$state.global.crosshair.visible=!0}},{key:"onWindowMouseMove",value:function(e){var t=e.movementX,n=e.movementY,r=e.layerY;if(this.canvas.isMouseDown){if(-1===this.layerToMove){var o=this.$state.chart.getLayerByYCoord(r);this.layerToMove=o}this.change.x+=t,this.change.y+=n,this.debounceSetVisibleRange()}else this.layerToMove=-1}},{key:"calculateNewVisibleRange",value:function(){var e=this.change,t=e.x,n=e.y;this.change={x:0,y:0};var r=this.$state.chart.id,o=this.$state.global.layout.chartDimensions[r].main.layers,i=this.$state.chart.ranges.x,a=i.start,u=i.end,l=this.$state.chart.ranges.y[this.layerToMove];if(l){var s=l.range,c=s.min,f=s.max,d=t/this.$state.chart.pixelsPerElement,h=this.$state.chart.timeframe*d;if(a-=h,u-=h,!this.$state.chart.ranges.y[this.layerToMove].lockedYScale){var p=n/(o[this.layerToMove].height/(f-c));c+=p,f+=p}this.$state.chart.setVisibleRange({start:a,end:u,min:c,max:f},this.layerToMove)}}}],n&&pe(t.prototype,n),Object.defineProperty(t,"prototype",{writable:!1}),e}();function ve(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}var me=function(){function e(t){var n=t.$state;!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),this.$state=n,this.canvas=null}var t,n;return t=e,(n=[{key:"init",value:function(){var e=this;this.canvas=new V({$state:this.$state,id:"canvas-timescale",canvas:this.$state.global.ui.charts[this.$state.chart.id].subcharts.xScale.current,type:"xScale",height:20,width:this.$state.dimensions.width-50,cursor:"e-resize",position:"bottom"}),this.onResizeChartListener=function(t){var n=t.xScale;e.canvas.setWidth(n.width),e.canvas.setHeight(n.height)}.bind(this),this.$state.global.layout.addEventListener("resize-".concat(this.$state.chart.id),this.onResizeChartListener),this.mouseMoveListener=this.onWindowMouseMove.bind(this),this.$state.global.events.addEventListener("mousemove",this.mouseMoveListener)}},{key:"onWindowMouseMove",value:function(e){var t=e.movementX;if(this.canvas.isMouseDown&&0!==t){var n=-(t>0?-10*-t:10*t);this.$state.chart.resizeXRange(n)}}},{key:"destroy",value:function(){this.$state.global.layout.removeEventListener("resize-".concat(this.$state.chart.id),this.onResizeChartListener),this.$state.global.events.removeEventListener("mousemove",this.mouseMoveListener)}}])&&ve(t.prototype,n),Object.defineProperty(t,"prototype",{writable:!1}),e}();function ge(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}var be=function(){function e(t){var n=t.$state;!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),this.$state=n,this.canvas=null,this.layerToMove=-1}var t,n;return t=e,n=[{key:"init",value:function(){var e=this;this.canvas=new V({$state:this.$state,id:"canvas-pricescale",canvas:this.$state.global.ui.charts[this.$state.chart.id].subcharts.yScale.current,type:"yScale",height:this.$state.dimensions.height-20,width:50,cursor:"n-resize",position:"right"}),this.resizeChartLayoutListener=function(t){var n=t.yScale;e.canvas.setHeight(n.height),e.canvas.setWidth(n.width)}.bind(this),this.$state.global.layout.addEventListener("resize-".concat(this.$state.chart.id),this.resizeChartLayoutListener),this.onResizeYScale=function(t){var n=t.yScale;e.canvas.setHeight(n.height),e.canvas.setWidth(n.width)}.bind(this),this.$state.global.layout.addEventListener("resize-y-scale-".concat(this.$state.chart.id),this.onResizeYScale),this.mouseMoveListener=this.onWindowMouseMove.bind(this),this.$state.global.events.addEventListener("mousemove",this.mouseMoveListener)}},{key:"destroy",value:function(){this.$state.global.events.removeEventListener("mousemove",this.mouseMoveListener),this.$state.global.layout.removeEventListener("resize-".concat(this.$state.chart.id),this.resizeChartLayoutListener),this.$state.global.layout.removeEventListener("resize-y-scale-".concat(this.$state.chart.id),this.onResizeYScale)}},{key:"onWindowMouseMove",value:function(e){var t=e.movementY,n=e.layerY;if(this.canvas.isMouseDown){if(0!==t){var r=this.$state.chart;if(-1===this.layerToMove){var o=r.getLayerByYCoord(n);this.layerToMove=o}var i=r.ranges.y[this.layerToMove].range,a=i.min,u=i.max,l=.01*(u-a)*-t;a+=l,u-=l,r.ranges.y[this.layerToMove].lockedYScale=!1,r.setVisibleRange({min:a,max:u},this.layerToMove)}}else this.layerToMove=-1}}],n&&ge(t.prototype,n),Object.defineProperty(t,"prototype",{writable:!1}),e}();function we(e){return we="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},we(e)}function ke(e,t,n,r,o,i,a){try{var u=e[i](a),l=u.value}catch(e){return void n(e)}u.done?t(l):Promise.resolve(l).then(r,o)}function xe(e){return function(){var t=this,n=arguments;return new Promise((function(r,o){var i=e.apply(t,n);function a(e){ke(i,r,o,a,u,"next",e)}function u(e){ke(i,r,o,a,u,"throw",e)}a(void 0)}))}}function Se(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function _e(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?Se(Object(n),!0).forEach((function(t){Ee(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):Se(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}function Ee(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function Oe(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}function Ce(e,t){return Ce=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e},Ce(e,t)}function je(e,t){if(t&&("object"===we(t)||"function"==typeof t))return t;if(void 0!==t)throw new TypeError("Derived constructors may only return object or undefined");return Pe(e)}function Pe(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function Re(e){return Re=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)},Re(e)}var Te=function(e){!function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),Object.defineProperty(e,"prototype",{writable:!1}),t&&Ce(e,t)}(s,e);var t,n,r,o,i,u,l=(i=s,u=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}(),function(){var e,t=Re(i);if(u){var n=Re(this).constructor;e=Reflect.construct(t,arguments,n)}else e=t.apply(this,arguments);return je(this,e)});function s(e){var t,n=e.$global,r=e.id,o=void 0===r?a.uniqueId():r,i=e.name,u=void 0===i?"":i,c=e.ranges,f=void 0===c?{x:{start:0,end:0},y:{}}:c,d=e.pixelsPerElement,h=void 0===d?10:d,p=e.timeframe,y=void 0===p?m.HOUR:p,v=e.settings,g=void 0===v?{}:v;return function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,s),(t=l.call(this)).$global=n,t.isInitialized=!1,t.id=o,t.timeframe=0,t.datasets={},t.datasetGroups={},t.selectedDatasetGroup="",t.maxDecimalPlaces=0,t.instructions=T,t.computedState=t.$global.workers.createComputedState(Pe(t)),t.subcharts={main:void 0,xScale:void 0,yScale:void 0},t.ranges=JSON.parse(JSON.stringify(f)),t.renderedRanges=JSON.parse(JSON.stringify(f)),t.settings=_e({syncRange:!1,syncWithCrosshair:""},g),t.$global.settings.onChartAdd(t.id,{settings:t.settings}),t.setPixelsPerElement(h),t.setTimeframe(y),t.setName(u),t}return t=s,n=[{key:"init",value:function(){var e=this;if(!this.isInitialized){this.onResizeListener=function(){return e.resizeXRange(0)}.bind(this),this.$global.layout.addEventListener("resize-".concat(this.id),this.onResizeListener);var t={chart:this,global:this.$global,dimensions:this.$global.layout.chartDimensions[this.id]};Object.keys(this.ranges.y).length||this.addLayer(10),this.$global.crosshair.addCrosshair(this.id),this.subcharts={main:new ye({$state:t}),xScale:new me({$state:t}),yScale:new be({$state:t})},this.setInitialVisibleRange(),this.subcharts.main.init(),this.subcharts.xScale.init(),this.subcharts.yScale.init(),this.isInitialized=!0,this.fireEvent("init")}}},{key:"destroy",value:function(){null!==this.newTimeInterval&&clearInterval(this.newTimeInterval),this.$global.removeEventListener("resize-".concat(this.id),this.onResizeListener),this.subcharts.main.destroy(),this.subcharts.yScale.destroy(),this.subcharts.xScale.destroy(),this.$global.layout.removeChart(this.id),this.$global.settings.onChartDelete(this.id),delete this.$global.charts[this.id]}},{key:"setName",value:function(){for(var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"",t=0,n=Object.values(this.$global.charts);t<n.length;t++){var r=n[t];if(r.name===e)return{error:"A chart with that name already exists."}}this.name=e,this.$global.settings.onChartChangeName(this.id,e),this.fireEvent("set-name",this.name)}},{key:"createDatasetGroup",value:function(e,t){var n=this,r=t.visible,o=void 0===r||r,i=t.synced,u=void 0===i?{}:i,l=a.uniqueId();return e=e.map((function(e){var t=n.$global.data.addOrGetDataset({source:e.source,name:e.name,timeframe:n.timeframe});return{source:t.source,name:t.name}})),this.datasetGroups[l]={id:l,visible:o,datasets:e,indicators:{},synced:u},this.selectedDatasetGroup.length||this.setSelectedDatasetGroup(l),this.$global.ui.charts[this.id].updateDatasetGroups(this.datasetGroups),this.datasetGroups[l]}},{key:"updateDatasetGroup",value:function(e,t){var n=this,r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},o=r.updateUI,i=void 0===o||o,a=this.datasetGroups[e],u="".concat(a.datasets[0].source,":").concat(a.datasets[0].name),l=this.datasets[u],s=this.$global.data.addOrGetDataset({source:t[0].source,name:t[0].name,timeframe:this.timeframe}),c=s.getTimeframeAgnosticId(),f=[],d={},h=function(e){f=l.removeSubscriber(n.id,e);var t=a.indicators[e];for(var r in t.datasetId=c,n.$global.data.sources)if(r===s.source){var o=n.$global.data.sources[r][s.name];if(!o)throw new Error("Couldn't find dataset ".concat(datasetId," in sources model."));var i=o.models[t.model.id];if(i=i?JSON.parse(JSON.stringify(i)):_e(_e({},t.model),{},{notFound:!0}),Array.isArray(i.model)){var u=i.model.find((function(e){return e.id===t.model.childId}));if(!u)throw new Error("Couldn't find childModel ".concat(t.model.childId));i.model=u,i.label=u.label,i.childId=u.id}t.model=i;break}t.model.notFound||(d[e]={datasetId:c,model:t.model},s.addSubscriber(n.id,e,[t.model.id])),n.computedState.emptySet({renderingQueueId:e})};for(var p in a.indicators)h(p);f&&!Object.keys(f).length&&delete this.datasets[u],this.datasets[c]=s,a.datasets=t.map((function(e){return{source:e.source,name:e.name}})),this.computedState.updateIndicators(d),i&&this.$global.ui.charts[this.id].updateDatasetGroups(this.datasetGroups),this.$global.settings.onChartDatasetGroupsChange(this.id,this.datasetGroups),this.computedState.generateAllInstructions(),this.fireEvent("update-dataset-group",a)}},{key:"addIndicator",value:(o=xe(regeneratorRuntime.mark((function e(t,n,r,o){var i,u,l,s,c,f,d,h,p,y,v,m,g,b,w,k,x,S,_=arguments;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return i=o.visible,u=void 0===i||i,l=o.layerId,s=void 0===l?Object.keys(this.ranges.y)[0]:l,c=_.length>4&&void 0!==_[4]?_[4]:{},f=c.updateUI,d=void 0===f||f,"string"==typeof t&&(t=j.getIndicatorById(t)),s&&this.ranges.y[s]||(s=this.addLayer(3)),h=this.datasetGroups[n],p=h.datasets[0],y=p.source,v=p.name,m=this.$global.data.addOrGetDataset({source:y,name:v,timeframe:this.timeframe}),g=m.getTimeframeAgnosticId(),b=a.randomHexColor(),t=_e(_e({},t),{},{visible:u,datasetId:g,model:r,color:b,layerId:s}),e.next=13,this.computedState.