trade-chart.js
Advanced tools
Comparing version 1.0.4 to 1.0.5
@@ -1,1 +0,1 @@ | ||
!function(t,i){"object"==typeof exports&&"object"==typeof module?module.exports=i():"function"==typeof define&&define.amd?define([],i):"object"==typeof exports?exports.TradeChart=i():t.TradeChart=i()}(window,(function(){return function(t){var i={};function e(n){if(i[n])return i[n].exports;var o=i[n]={i:n,l:!1,exports:{}};return t[n].call(o.exports,o,o.exports,e),o.l=!0,o.exports}return e.m=t,e.c=i,e.d=function(t,i,n){e.o(t,i)||Object.defineProperty(t,i,{enumerable:!0,get:n})},e.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},e.t=function(t,i){if(1&i&&(t=e(t)),8&i)return t;if(4&i&&"object"==typeof t&&t&&t.__esModule)return t;var n=Object.create(null);if(e.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:t}),2&i&&"string"!=typeof t)for(var o in t)e.d(n,o,function(i){return t[i]}.bind(null,o));return n},e.n=function(t){var i=t&&t.__esModule?function(){return t.default}:function(){return t};return e.d(i,"a",i),i},e.o=function(t,i){return Object.prototype.hasOwnProperty.call(t,i)},e.p="",e(e.s=1)}([function(t,i){t.exports="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAJ8AAAAaCAYAAACpZo6LAAAACXBIWXMAAAsTAAALEwEAmpwYAAAFyGlUWHRYTUw6Y29tLmFkb2JlLnhtcAAAAAAAPD94cGFja2V0IGJlZ2luPSLvu78iIGlkPSJXNU0wTXBDZWhpSHpyZVN6TlRjemtjOWQiPz4gPHg6eG1wbWV0YSB4bWxuczp4PSJhZG9iZTpuczptZXRhLyIgeDp4bXB0az0iQWRvYmUgWE1QIENvcmUgNi4wLWMwMDIgNzkuMTY0NDYwLCAyMDIwLzA1LzEyLTE2OjA0OjE3ICAgICAgICAiPiA8cmRmOlJERiB4bWxuczpyZGY9Imh0dHA6Ly93d3cudzMub3JnL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VdPeHnk7ilNoZZRqKZn7LYHVRmm++EkWUCrmR6hs105N9igq6YVxESegIkjTsDVkIiwWC/a9ina3PTt4HNVk44TowVWJQCmJsKCb5jvrH72MLEfcxegx9yxukm12ra/ZQBrVhyqqGYcDiRoqFvj6DxB5m2j9jhItyYKyJe/hj+g3hHzbSa7x7kbO58f4z5750I3OCcYPgk4j1d4Oujz9gaKyA0Q3z402+h9DrkYdBTAnUaQ3j4TZj3JeNrJfxj+Xy8iM9aBA4BcozWXXbgAdJLDn9VbwHwHzIU0jY8a5K8d3Pgyl3PMdYgCKkc/nV+xEZ9jSIqFBJIxxZDKnaS1BlZHQ9iFtV4/dXwA+or10DojQb+Zo9wnFKxwg7XQKnQmsI63vO1ALSledxn9sawmlP04ggm1H6aikfj6iNf1VNGH/yJCXfGWkOaz6rCG/42mitU3Qwg6gBGb4+VFzLaHo+AFS2fb3Bj34F24SncXLKpz7xpwXM0gT/TvhfrzY7sMk8BtEln2e+02kVc+TPpc54H1kWvfTOo+sfh6Hg6QAtbQfEJ1A5CqC87io6DlkPotGjxYBqqqcpb1obhvZP4BqIAFmnaYZxpm6m2QfNh1EG7ALl5ecQcQqgn7Tl13D8G9O0jCKNvNm/gnqw4369doCIl78NxA7UN5nlOwk5deDQvXkS3zz8t0WNjHSyPc2yeF+gPy2BdyBgzTtZA9cDqGdbI8PlZD2WUVR5m1zFY04t/AY4r+SBIExBlg2GgAAAABJRU5ErkJggg=="},function(t,i,e){"use strict";var n;e.r(i),function(t){t.left="left",t.right="right"}(n||(n={}));var o,a=n;!function(t){t.up="up",t.down="down"}(o||(o={}));var r=o,h=function(){function t(t,i){this.initState(t,i)}return t.prototype.canvasMouseDown=function(t){},t.prototype.canvasMouseWheel=function(t){},t.prototype.canvasMouseMove=function(t){},t.prototype.canvasMouseUp=function(t){},t.prototype.initState=function(i,e){this.ctx=null,this.canvas=null,t.isTimeToUpdateCurCandle=!0,this.option=e,this.addStatus(this.option.data),t.allData=this.option.data,t.chartType=this.option.chartType||"candle",t.showDataNum="pc"===this.option.mode?50:30,this.container=i,this.fontSize=this.option.fontSize||"18px",this.cPadding=this.option.cPadding,this.tSpace=this.option.tSpace||100,this.originX=this.option.cPadding,this.originY=this.option.height-this.cPadding,this.chartRightPadding="mobile"===this.option.mode?.15*this.option.width:.08*this.option.width},t.prototype.drawTrigon=function(t,i,e,n,o){if("right"===n){var a=t-10,r="maxHigh"===o?i+1:i-1;this.ctx.beginPath(),this.ctx.setLineDash([]),this.ctx.strokeStyle="#A0A4AB",this.ctx.moveTo(a+60,r),this.ctx.lineTo(a+30,r),this.ctx.stroke(),this.ctx.beginPath(),this.ctx.moveTo(a+30,r),this.ctx.lineTo(a+45,r-10),this.ctx.lineTo(a+35,r),this.ctx.lineTo(a+45,r+10),this.ctx.fillStyle="#A0A4AB",this.ctx.fill(),this.ctx.font="20px Arial",this.ctx.textBaseline="middle",this.ctx.textAlign="left",this.ctx.fillText(e,a+65,r)}else{var h=t+10,s="maxHigh"===o?i+1:i-1;this.ctx.beginPath(),this.ctx.setLineDash([]),this.ctx.strokeStyle="#A0A4AB",this.ctx.moveTo(h-30,s),this.ctx.lineTo(h-60,s),this.ctx.stroke(),this.ctx.beginPath(),this.ctx.moveTo(h-30,s),this.ctx.lineTo(h-45,s-10),this.ctx.lineTo(h-35,s),this.ctx.lineTo(h-45,s+10),this.ctx.fillStyle="#A0A4AB",this.ctx.fill(),this.ctx.font="20px Arial",this.ctx.textBaseline="middle",this.ctx.textAlign="left",this.ctx.fillText(e,h-145,s)}},t.prototype.drawLine=function(t,i,e,n,o){void 0===o&&(o={}),this.ctx.setLineDash([]),this.ctx.moveTo(t,i),o&&(o.color&&(this.ctx.strokeStyle=o.color),o.dottal&&this.ctx.setLineDash([o.dottal.x,o.dottal.y]),o.width&&(this.ctx.lineWidth=o.width)),this.ctx.lineTo(e,n)},t.prototype.drawRect=function(t,i,e,n,o){this.ctx.beginPath(),o&&(this.ctx.fillStyle=o.fillStyle),this.ctx.fillRect(t,i,e,n)},t.prototype.clearCanvas=function(){this.canvas.height=this.option.height,this.canvas.width=this.option.width},t.prototype.dateFormat=function(t,i){var e,n={"Y+":i.getFullYear().toString(),"m+":(i.getMonth()+1).toString(),"d+":i.getDate().toString(),"H+":i.getHours().toString(),"M+":i.getMinutes().toString(),"S+":i.getSeconds().toString()};for(var o in n)n.hasOwnProperty(o)&&(e=new RegExp("("+o+")").exec(t))&&(t=t.replace(e[1],1===e[1].length?n[o]:n[o].padStart(e[1].length,"0")));return t},t.prototype.drawLogo=function(){var t=document.createElement("img");t.setAttribute("src",e(0)),t.style.position="absolute",t.style.left="1%",t.style.maxWidth="100px",t.style.opacity="0.5",t.style.bottom="5%",t.style.userSelect="none",this.container.appendChild(t)},t.prototype.Pythagorean=function(t,i){var e=Math.abs(t.clientX-i.clientX),n=Math.abs(t.clientY-i.clientY);return Math.sqrt(Math.pow(e,2)+Math.pow(n,2))},t.prototype.addStatus=function(t){t.forEach((function(t,i,e){t.open>t.close?e[i].status=r.down:e[i].status=r.up}))},t.tHeight=15,t.TimeHorizonHeight=30,t.minVal=9999999,t.maxVal=0,t.candleMargin=1,t.isTouch=!1,t.infoContainerPosition=a.left,t.curCandleCoord={offsetX:0,offsetY:0},t}();function s(t,i){void 0===i&&(i={});var e=document.createElement(t);for(var n in i)Object.prototype.hasOwnProperty.call(i,n)&&(e[n]=i[n]);return e}function l(t,i){for(var e in i)Object.prototype.hasOwnProperty.call(i,e)&&(t.style[e]=i[e])}var c,d,p=function(){function t(t,i){this.container=t,this.option=i}return t.prototype.createInfoElement=function(t){var i=s("div");return i.id=t,l(i,{minWidth:"25%",background:"#1D2027",border:"#eee",padding:"6px 5px",display:"flex",flexDirection:"column",position:"absolute",top:"7%"}),"left"===this.infoContainerPosition?l(i,{left:"2%"}):l(i,{right:"2%"}),i},t.prototype.updateCurCandleInfo=function(){h.isTimeToUpdateCurCandle&&(h.curCandle=h.allData[h.allData.length-1],this.drawCurCandleMAInfo(),this.curCandleOHLCInfoContainer&&(l(this.curCandleOHLCInfoContainer,{color:"up"===h.curCandle.status?"#57CF8D":"#EB2F34"}),this.appendCurCandleOHLCInfo()))},t.prototype.drawCurCandleMAInfo=function(){"candle"===h.chartType&&(this.curCandleMAContainer?(this.curCandleMAContainer=this.container.querySelector("#curCandleMAContainer"),this.patchCurCandleMAInfo(this.curCandleMAContainer)):(this.curCandleMAContainer=s("div"),this.curCandleMAContainer.setAttribute("id","curCandleMAContainer"),l(this.curCandleMAContainer,{position:"absolute",marginTop:"5px",display:"flex",top:"0%",left:"2%",userSelect:"none"}),this.patchCurCandleMAInfo(this.curCandleMAContainer),this.container.appendChild(this.curCandleMAContainer)))},t.prototype.patchCurCandleMAInfo=function(t){var i="";if(this.option.MA&&this.option.MA.length){for(var e=0;e<this.option.MA.length;e++){var n=this.option.MA[e];h.curCandle["MA"+n.interval]?i+='\n <div style="color: '+n.color+';text-align: left;margin-top: 5px;margin-right:8px">\n MA'+n.interval+": "+h.curCandle["MA"+n.interval]+"\n </div>\n ":i+='\n <div style="color: '+n.color+';text-align: left;margin-top: 5px;margin-right:8px">\n MA'+n.interval+" : -- --\n </div>\n "}t.innerHTML=i}},t.prototype.drawCurCandleOHLCInfo=function(){this.curCandleOHLCInfoContainer?"mobile"===this.option.mode?(this.container.removeChild(this.curCandleOHLCInfoContainer),this.curCandleOHLCInfoContainer=null):(l(this.curCandleOHLCInfoContainer,{color:"up"===h.curCandle.status?"#57CF8D":"#EB2F34"}),"left"===h.infoContainerPosition?l(this.curCandleOHLCInfoContainer,{right:"unset",left:"2%"}):l(this.curCandleOHLCInfoContainer,{left:"unset",right:"2%"}),this.appendCurCandleOHLCInfo()):(this.curCandleOHLCInfoContainer=this.createInfoElement("curCandleOHLCInfoContainer"),l(this.curCandleOHLCInfoContainer,{color:"up"===h.curCandle.status?"#57CF8D":"#EB2F34",userSelect:"none"}),this.appendCurCandleOHLCInfo(),this.container.appendChild(this.curCandleOHLCInfoContainer))},t.prototype.appendCurCandleOHLCInfo=function(){var t=h.curCandle.close-h.curCandle.open,i=t/h.curCandle.open;this.curCandleOHLCInfoContainer&&(this.curCandleOHLCInfoContainer.innerHTML='\n <div style="flex:1;display:flex; width:100%;justify-content:space-between;">\n <span>Open:</span>\n <span>'+h.curCandle.open+'</span>\n </div>\n <div style="flex:1;display:flex;width:100%;justify-content:space-between;">\n <span>High:</span>\n <span>'+h.curCandle.high+'</span>\n </div>\n <div style="flex:1;display:flex;width:100%;justify-content:space-between;">\n <span>Low:</span>\n <span>'+h.curCandle.low+'</span>\n </div>\n <div style="flex:1;display:flex;width:100%;justify-content:space-between;">\n <span>Close:</span>\n <span>'+h.curCandle.close+'</span>\n </div>\n <div style="flex:1;display:flex;width:100%;justify-content:space-between;">\n <span>change:</span>\n <span>'+(t>0?"+":"")+t.toFixed(this.option.priceDigitnumber)+'</span>\n </div>\n <div style="flex:1;display:flex;width:100%;justify-content:space-between;">\n <span>change%:</span>\n <span>'+(i>0?"+":"")+(100*i).toFixed(2)+"%</span>\n </div>\n ")},t}(),u=(c=function(t,i){return(c=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,i){t.__proto__=i}||function(t,i){for(var e in i)Object.prototype.hasOwnProperty.call(i,e)&&(t[e]=i[e])})(t,i)},function(t,i){if("function"!=typeof i&&null!==i)throw new TypeError("Class extends value "+String(i)+" is not a constructor or null");function e(){this.constructor=t}c(t,i),t.prototype=null===i?Object.create(i):(e.prototype=i.prototype,new e)}),f=function(t,i,e,n){return new(e||(e=Promise))((function(o,a){function r(t){try{s(n.next(t))}catch(t){a(t)}}function h(t){try{s(n.throw(t))}catch(t){a(t)}}function s(t){var i;t.done?o(t.value):(i=t.value,i instanceof e?i:new e((function(t){t(i)}))).then(r,h)}s((n=n.apply(t,i||[])).next())}))},g=function(t,i){var e,n,o,a,r={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return a={next:h(0),throw:h(1),return:h(2)},"function"==typeof Symbol&&(a[Symbol.iterator]=function(){return this}),a;function h(a){return function(h){return function(a){if(e)throw new TypeError("Generator is already executing.");for(;r;)try{if(e=1,n&&(o=2&a[0]?n.return:a[0]?n.throw||((o=n.return)&&o.call(n),0):n.next)&&!(o=o.call(n,a[1])).done)return o;switch(n=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return r.label++,{value:a[1],done:!1};case 5:r.label++,n=a[1],a=[0];continue;case 7:a=r.ops.pop(),r.trys.pop();continue;default:if(!(o=r.trys,(o=o.length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){r=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){r.label=a[1];break}if(6===a[0]&&r.label<o[1]){r.label=o[1],o=a;break}if(o&&r.label<o[2]){r.label=o[2],r.ops.push(a);break}o[2]&&r.ops.pop(),r.trys.pop();continue}a=i.call(t,r)}catch(t){a=[6,t],n=0}finally{e=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,h])}}},m=function(t,i){var e="function"==typeof Symbol&&t[Symbol.iterator];if(!e)return t;var n,o,a=e.call(t),r=[];try{for(;(void 0===i||i-- >0)&&!(n=a.next()).done;)r.push(n.value)}catch(t){o={error:t}}finally{try{n&&!n.done&&(e=a.return)&&e.call(a)}finally{if(o)throw o.error}}return r},C=function(t,i){for(var e=0,n=i.length,o=t.length;e<n;e++,o++)t[o]=i[e];return t},x=function(t){function i(i,e){var n=t.call(this,i,e)||this;return n.loadMore=!1,n.quotePanel=new p(i,e),n.createCanvasElement(i),n.ctx=n.canvas.getContext("2d"),n.lineBgColorBegin=n.option.lineBgColorBegin||"rgba(133,171,212,0.6)",n.lineBgColorEnd=n.option.lineBgColorEnd||"rgba(133,171,212,0.1)",n.BrokenLineColor=n.option.BrokenLineColor||"#3696F3",n.yLegendNum=10,h.legendYMargin=(n.option.height-4*n.option.cPadding)/(n.yLegendNum-1),n.xLegendNum=4,n.lastClientX=0,n.rightCandleOffset=0,n.leftCandleOffset=0,n.formatData(),h.showData=h.allData.slice(-h.showDataNum),n.quotePanel.updateCurCandleInfo(),n.candleNum=h.showData.length,n.candleWidth=(n.option.width-n.chartRightPadding-(3*n.cPadding-h.candleMargin)-h.candleMargin*(n.candleNum-1))/n.candleNum,n.ctr=e.animate?1:100,n.numctr=100,n.speed=3,n.ctx.font="24px Arial",n.ctx.textAlign="end",n.drawChart(),n.lastDiff=0,n}return u(i,t),i.prototype.createCanvasElement=function(t){this.canvas=s("canvas"),this.canvas.height=this.option.height,this.canvas.width=this.option.width,this.canvas.style.width=this.option.originalWidth+"px",this.canvas.style.height=this.option.originalHeight+"px",t.appendChild(this.canvas)},i.prototype.drawMinMaxText=function(){var t=0,i={high:0,low:0,close:0,open:0};h.showData.forEach((function(e,n){e.high>i.high&&(i=e,t=n)}));var e=this.originX+this.option.cPadding+t*this.candleWidth+(t-1)*h.candleMargin+this.candleWidth/2,n=(h.maxVal-i.high)/(h.maxVal-h.minVal)*(this.option.height-this.option.cPadding),o="left";t<=15&&(o="right"),this.drawTrigon(e,n,i.high.toString(),o,"maxHigh");var a=0,r={high:0,low:Number.MAX_VALUE,close:0,open:0};h.showData.forEach((function(t,i){t.low<r.low&&(r=t,a=i)}));var s=this.originX+this.option.cPadding+a*this.candleWidth+(a-1)*h.candleMargin+this.candleWidth/2,l=(h.maxVal-r.low)/(h.maxVal-h.minVal)*(this.option.height-this.option.cPadding),c="left";a<=15&&(c="right"),this.drawTrigon(s,l,r.low.toString(),c,"minLow")},i.prototype.formatData=function(){var t=this;h.allData.forEach((function(i,e,n){"1m"===t.option.interval||"5m"===t.option.interval?t.xLegendNum=8:"15m"===t.option.interval||"30m"===t.option.interval||"60m"===t.option.interval?(t.xLegendNum=5,t.tSpace=50):"1d"===t.option.interval&&(t.xLegendNum=8),n[e].formatedTime=t.dateFormat(t.formatTimeRule(),new Date(Number(i.time)))}))},i.prototype.formatTimeRule=function(){return"1m"===this.option.interval||"5m"===this.option.interval?"HH:MM":"15m"===this.option.interval||"30m"===this.option.interval||"60m"===this.option.interval?"mm/dd HH:MM":"1d"===this.option.interval?"mm/dd":"yyyy-mm-dd HH:MM:SS"},i.prototype.drawChart=function(){this.clearCanvas(),this.getYlengend(),this.drawCandles(),this.drawAxis(),this.drawRealTimeHorizon(),"candle"===h.chartType&&(this.drawMinMaxText(),this.drawMAs())},i.prototype.getYlengend=function(){h.maxVal=0,h.minVal=9999999,h.showData.forEach((function(t){t.high>h.maxVal&&(h.maxVal=Number(t.high)),t.low<h.minVal&&(h.minVal=Number(t.low))}));var t=h.maxVal-h.minVal;h.maxVal+=.15*t,h.minVal-=.05*t,h.yAxisLegendTextLength=12*h.maxVal.toFixed(this.option.priceDigitnumber).length},i.prototype.drawAxis=function(){this.drawLine(this.originX,this.originY,this.option.width-this.option.cPadding,this.originY,{color:this.option.axisColor}),this.drawLine(this.originX,this.originY,this.originX,this.option.cPadding,{color:this.option.axisColor}),this.drawYAxis(),this.drawXAxis()},i.prototype.drawYAxis=function(){this.ctx.beginPath();var t=(h.maxVal-h.minVal)/(this.yLegendNum-1);this.ctx.fillStyle=this.option.legendColor;for(var i=0;i<this.yLegendNum;i++){var e=this.originY-h.tHeight-h.legendYMargin*i,n=(h.minVal+i*t).toFixed(this.option.priceDigitnumber);this.ctx.font="20px Arial","left"!==this.option.yAxisDirection&&this.option.yAxisDirection?"right"===this.option.yAxisDirection&&(this.ctx.textBaseline="top",this.ctx.textAlign="right",this.ctx.fillText(n,this.option.width-this.option.cPadding,e)):this.ctx.fillText(n,this.originX,e),this.ctx.textBaseline="alphabetic"}},i.prototype.drawXAxis=function(){var t=Math.round(h.showData.length/this.xLegendNum)+1;this.ctx.textAlign="left";for(var i=0;i<h.showData.length;i+=t){var e=h.showData[i];e.formatedTime&&this.ctx.fillText(e.formatedTime,e.leftCoordinate+(e.rightCoordinate-e.leftCoordinate)/2,this.option.height-this.option.cPadding)}},i.prototype.drawCandlestick=function(t,i){this.ctx.beginPath(),this.ctx.lineWidth=3;var e=this.originX+this.option.cPadding+i*this.candleWidth+(i-1)*h.candleMargin+this.candleWidth/2,n=(h.maxVal-t.high)/(h.maxVal-h.minVal)*(this.option.height-this.option.cPadding),o=(h.maxVal-t.low)/(h.maxVal-h.minVal)*(this.option.height-this.option.cPadding);t.open>t.close?this.drawLine(e,n,e,o,{color:this.option.downColor,width:3}):this.drawLine(e,n,e,o,{color:this.option.upColor,width:3}),this.ctx.stroke()},i.prototype.drawCandle=function(t,i){var e,n,o=this.originX+this.option.cPadding+i*this.candleWidth+(i-1)*h.candleMargin;t.open>t.close?(n=(t.open-t.close)/(h.maxVal-h.minVal)*(this.option.height-this.option.cPadding),e=(h.maxVal-t.open)/(h.maxVal-h.minVal)*(this.option.height-this.option.cPadding),this.drawRect(o,e,this.candleWidth*this.ctr/this.numctr,n,{fillStyle:this.option.downColor})):(n=(t.close-t.open)/(h.maxVal-h.minVal)*(this.option.height-this.option.cPadding),e=(h.maxVal-t.close)/(h.maxVal-h.minVal)*(this.option.height-this.option.cPadding),this.drawRect(o,e,this.candleWidth*this.ctr/this.numctr,n,{fillStyle:this.option.upColor}))},i.prototype.drawBrokenLine=function(t,i,e){void 0===e&&(e={});var n=this.originX+this.option.cPadding+i*this.candleWidth+(i-1)*h.candleMargin+this.candleWidth/2,o=(h.maxVal-t.close)/(h.maxVal-h.minVal)*(this.option.height-this.cPadding);0===i?this.ctx.moveTo(n,o):this.ctx.lineTo(n,o),this.ctx.strokeStyle=e.color||this.BrokenLineColor,e.width&&(this.ctx.lineWidth=e.width)},i.prototype.drawCandles=function(){var t=this;if(this.ctx.beginPath(),this.ctx.setLineDash([]),h.showData.forEach((function(i,e,n){"line"===h.chartType?(t.addCandleCoordinate(i,e,n),t.drawBrokenLine(i,e,{width:3})):(t.addCandleCoordinate(i,e,n),t.drawCandle(i,e),t.drawCandlestick(i,e))})),this.ctx.stroke(),"line"===h.chartType){var i=this.originX+this.option.cPadding-Number(h.candleMargin)+this.candleWidth/2,e=this.originX+this.option.cPadding+(h.showData.length-1)*this.candleWidth+(h.showData.length-2)*h.candleMargin+this.candleWidth/2;this.ctx.lineTo(e,this.originY),this.ctx.lineTo(i,this.originY);var n=this.ctx.createLinearGradient(0,0,0,300);n.addColorStop(0,this.lineBgColorBegin),n.addColorStop(1,this.lineBgColorEnd),this.ctx.fillStyle=n,this.ctx.fill(),this.ctx.closePath()}this.ctr<this.numctr&&(this.ctr++,setTimeout((function(){t.drawChart(),t.drawRealTimeHorizon()}),this.speed))},i.prototype.drawRealTimeHorizon=function(){this.ctx.beginPath(),this.ctx.textAlign="left";var t=h.allData.length-1,i=h.allData[t],e=h.showData.length-1;this.ctx.font="20px Arial";var n,o,a=this.originX+this.option.cPadding+e*(this.candleWidth+h.candleMargin);if("line"===h.chartType?(n=this.BrokenLineColor,o=(h.maxVal-i.close)/(h.maxVal-h.minVal)*(this.option.height-2*this.cPadding)):(n=Number(i.open)>Number(i.close)?this.option.downColor:this.option.upColor,o=(h.maxVal-i.close)/(h.maxVal-h.minVal)*(this.option.height-2*this.cPadding)+this.cPadding),"left"!==this.option.yAxisDirection&&this.option.yAxisDirection){if("right"===this.option.yAxisDirection){var r=this.originX+this.option.width;this.drawLine(r,o,this.originX,o,{color:n,dottal:{x:1,y:1}}),this.ctx.stroke(),this.drawRect(r-h.yAxisLegendTextLength,o-h.TimeHorizonHeight/2,h.yAxisLegendTextLength,h.TimeHorizonHeight,{fillStyle:n}),this.ctx.fillStyle="#fff",this.ctx.textAlign="center",this.ctx.textBaseline="middle",this.ctx.fillText(i.close,r-h.yAxisLegendTextLength/2,o)}}else this.drawLine(a,o,this.originX,o,{color:n,dottal:{x:1,y:1}}),this.ctx.stroke(),this.drawRect(this.originX,o-7,50,15,{fillStyle:n}),this.ctx.fillStyle="#fff",this.ctx.fillText(i.close,this.originX+5,o+3.5)},i.prototype.addCandleCoordinate=function(t,i,e){var n=this.originX+this.option.cPadding+i*this.candleWidth+(i-1)*h.candleMargin;e[i].leftCoordinate=n.toFixed(2),e[i].leftCoordinate=Number(e[i].leftCoordinate),e[i].rightCoordinate=(n+this.candleWidth*this.ctr/this.numctr).toFixed(2),e[i].rightCoordinate=Number(e[i].rightCoordinate)},i.prototype.drawMA=function(t,i){this.ctx.beginPath();var e,n,o,a=Number(t);this.leftCandleOffset=h.allData.length-this.rightCandleOffset-this.candleNum,this.leftCandleOffset<a?(n=this.candleNum+this.leftCandleOffset,e=0,o=!0):(n=this.candleNum+a-1,e=-this.candleNum-this.rightCandleOffset-a+1,o=!1);var r=e+n;0===r&&(r=h.allData.length-1);for(var s=h.allData.slice(e,r+1),l=a-1;l<n;l++){for(var c=0,d=l-a+1;d<=l;d++)void 0===s[d].close&&console.log(s,s[d],d),c+=Number(s[d].close);var p=c/a,u=l-a+1;o&&(u=l-this.leftCandleOffset),h.showData[u]["MA"+a]=Number(p.toFixed(this.option.priceDigitnumber)),this.drawBrokenLine({open:0,high:0,low:0,close:p},u,{color:i,width:2})}this.ctx.stroke()},i.prototype.drawMAs=function(){var t=this;this.ctx.setLineDash([]),this.option.MA&&this.option.MA.length&&this.option.MA.forEach((function(i){t.drawMA(i.interval,i.color)}))},i.prototype.canvasMouseDown=function(t){"offsetX"in t&&0===this.lastClientX&&(this.lastClientX=t.offsetX)},i.prototype.canvasMouseWheel=function(t){var i=0;t.touches?(0===this.lastDiff&&(this.lastDiff=this.Pythagorean(t.touches[0],t.touches[1])),i=this.Pythagorean(t.touches[0],t.touches[1])/this.lastDiff>1?1:-1,this.lastDiff=this.Pythagorean(t.touches[0],t.touches[1])):t.wheelDelta?(i=t.wheelDelta/120,window.opera&&(i=-i)):t.detail&&(i=-t.detail/3),i&&this.chartZoom(i)},i.prototype.chartZoom=function(t){var i=Math.round(h.showDataNum/25);if(i<3&&(i=3),t<0){if(h.showDataNum>=h.allData.length)return;h.showDataNum+=i,0===this.rightCandleOffset?h.showData=h.allData.slice(-h.showDataNum):h.showData=h.allData.slice(-h.showDataNum-this.rightCandleOffset,h.allData.length-this.rightCandleOffset),this.candleNum=h.showData.length,this.candleWidth=(this.option.width-this.chartRightPadding-(3*this.cPadding-h.candleMargin)-h.candleMargin*(this.candleNum-1))/this.candleNum,this.drawChart()}else{if(h.showDataNum<=13)return;h.showDataNum-=i,h.showData=h.allData.slice(-h.showDataNum-this.rightCandleOffset,h.allData.length-this.rightCandleOffset),0===this.rightCandleOffset&&(h.showData=h.allData.slice(-h.showDataNum)),this.candleNum=h.showData.length,this.candleWidth=(this.option.width-this.chartRightPadding-(3*this.cPadding-h.candleMargin)-h.candleMargin*(this.candleNum-1))/this.candleNum,this.drawChart()}},i.prototype.canvasMouseMove=function(t){return f(this,void 0,void 0,(function(){var i,e;return g(this,(function(n){switch(n.label){case 0:return(e=parseInt(String(h.showData.length/50)))<1&&(e=1),i=t.touches?t.touches[0].clientX:t.clientX,this.lastClientX<i?(this.rightCandleOffset+=e,this.rightCandleOffset>=h.allData.length-this.candleNum&&(this.rightCandleOffset=h.allData.length-this.candleNum)):this.lastClientX>i&&(this.rightCandleOffset-=e,this.rightCandleOffset<=0&&(this.rightCandleOffset=0)),h.showData=h.allData.slice(-this.candleNum-this.rightCandleOffset,h.allData.length-this.rightCandleOffset),this.lastClientX=i,this.leftCandleOffset=h.allData.length-this.rightCandleOffset-this.candleNum,[4,this.loadMoreData()];case 1:return n.sent(),this.drawChart(),[2]}}))}))},i.prototype.loadMoreData=function(){return f(this,void 0,void 0,(function(){var t,i;return g(this,(function(e){switch(e.label){case 0:return this.leftCandleOffset||this.loadMore||!this.option.loadMoreCallback?[3,2]:(this.loadMore=!0,[4,this.option.loadMoreCallback()]);case 1:if(0===(t=e.sent()).length)return[2];this.addStatus(t),(i=h.allData).unshift.apply(i,C([],m(t))),this.formatData(),this.loadMore=!1,e.label=2;case 2:return[2]}}))}))},i.prototype.updateLastCandle=function(t,i,e,n){if(i)e>n.high?(h.allData[h.allData.length-1].high=e,h.allData[h.allData.length-1].close=e):e<n.low?(h.allData[h.allData.length-1].low=e,h.allData[h.allData.length-1].close=e):h.allData[h.allData.length-1].close=e,h.allData[h.allData.length-1].status=h.allData[h.allData.length-1].close>h.allData[h.allData.length-1].open?r.up:r.down;else{var o=h.allData[h.allData.length-1].close,a={open:o,low:o<e?o:e,close:e,high:o>e?o:e,time:t,formatedTime:this.dateFormat(this.formatTimeRule(),new Date(Date.now()))};h.allData.push(a),0===this.rightCandleOffset?h.showData=h.allData.slice(-this.candleNum):this.rightCandleOffset++}},i.prototype.timeCheck=function(t,i){if(this.option.timeCheckErrorHandler){var e=Math.abs(new Date(i).getMinutes()-new Date(t).getMinutes());switch(this.option.interval){case"1m":e>1&&this.option.timeCheckErrorHandler(e-1);break;case"5m":e>5&&this.option.timeCheckErrorHandler(e-5);break;case"15m":e>15&&this.option.timeCheckErrorHandler(e-15);break;case"30m":e>30&&this.option.timeCheckErrorHandler(e-30);break;case"60m":e>60&&this.option.timeCheckErrorHandler(e-60);break;case"1d":e>1440&&this.option.timeCheckErrorHandler(e-1440)}}},i.prototype.subscribeBars=function(t,i){return f(this,void 0,void 0,(function(){var e,n,o,a,r,s,l,c;return g(this,(function(d){return t=Number(t),e=h.allData[h.allData.length-1],n=new Date(Number(e.time)),o=Number(this.dateFormat("M",n)),a=Number(this.dateFormat("H",n)),r=Number(this.dateFormat("d",n)),s=Number(this.dateFormat("d",new Date(t))),l=Number(this.dateFormat("M",new Date(t))),c=Number(this.dateFormat("H",new Date(t))),this.timeCheck(n.getTime(),t),"1m"===this.option.interval?this.updateLastCandle(t,l===o,i,e):"5m"===this.option.interval?this.updateLastCandle(t,Math.abs(l-o)<=5||55===Math.abs(l-o),i,e):"15m"===this.option.interval?this.updateLastCandle(t,Math.abs(l-o)<=15||45===Math.abs(l-o),i,e):"30m"===this.option.interval?this.updateLastCandle(t,Math.abs(l-o)<=30,i,e):"60m"===this.option.interval?this.updateLastCandle(t,c===a,i,e):"1d"===this.option.interval&&this.updateLastCandle(t,r===s,i,e),this.quotePanel.updateCurCandleInfo(),this.drawChart(),[2]}))}))},i}(h),w=0,y=function(){function t(t,i,e,n,o,a,r,h,s){this.container=t,this.originX=i,this.width=e,this.height=n,this.cPadding=o,this.chartRightPadding=a,this.brokenLineColor=r,this.markerList=[],this.purchaseTime=h.purchaseTime,this.deliveryTime=h.deliveryTime,this.option=s,this.createInfoElement(this.container)}return t.prototype.createInfoElement=function(t){var i=document.getElementById("infoContainer");i||((i=s("div")).id="infoContainer"),this.drawQuoteLine(i),t.appendChild(i)},t.prototype.getQuoteLineCoordinate=function(){var t=h.allData.length-1,i=h.allData[t];return{x:this.originX+this.width-this.chartRightPadding,y:(h.maxVal-i.close)/(h.maxVal-h.minVal)*(this.height-2*this.cPadding),time:i.time}},t.prototype.getPrice=function(){var t=h.allData.length-1;return h.allData[t].close},t.prototype.drawQuoteLine=function(t){this.quoteLine=s("div",{id:"quoteLine"}),this.quoteRect=s("div",{id:"quoteRect"}),this.quoteSpan=s("span",{id:"quoteSpan"}),this.quoteDot=s("i",{id:"quoteDot"});var i=this.getQuoteLineCoordinate(),e=i.x,n=i.y,o=this.getPrice();l(this.quoteLine,{width:this.chartRightPadding/2+"px",top:n/2+"px",left:e/2+"px",backgroundImage:"linear-gradient(\n to right,\n "+this.brokenLineColor+" 0%,\n "+this.brokenLineColor+" 50%,\n transparent 50%\n )"}),l(this.quoteDot,{top:n/2+"px",left:e/2-10+"px",backgroundColor:this.brokenLineColor}),l(this.quoteRect,{width:h.yAxisLegendTextLength/2+"px",height:h.TimeHorizonHeight/2+"px",top:(n-h.TimeHorizonHeight/2)/2+"px",left:(this.width-h.yAxisLegendTextLength)/2+"px",backgroundColor:this.brokenLineColor}),l(this.quoteSpan,{top:n/2+"px",left:(this.width-h.yAxisLegendTextLength/2)/2+"px"}),this.quoteSpan.innerHTML=o.toString(),t.appendChild(this.quoteLine),t.appendChild(this.quoteDot),t.appendChild(this.quoteRect),t.appendChild(this.quoteSpan)},t.prototype.update=function(){this.updateQuoteLine(),this.updateMarkers()},t.prototype.updateQuoteLine=function(){var t=this.getQuoteLineCoordinate(),i=t.x,e=t.y,n=this.getPrice();l(this.quoteLine,{width:this.chartRightPadding/2+"px",top:e/2+"px",left:i/2+"px"}),l(this.quoteDot,{top:e/2+"px",left:i/2-5+"px"}),l(this.quoteRect,{width:h.yAxisLegendTextLength/2+"px",height:h.TimeHorizonHeight/2+"px",top:(e-h.TimeHorizonHeight/2)/2+"px",left:(this.width-h.yAxisLegendTextLength)/2+"px"}),this.quoteSpan.innerHTML=n.toString(),l(this.quoteSpan,{top:e/2+"px",left:(this.width-h.yAxisLegendTextLength/2)/2+"px"})},t.prototype.mark=function(t){var i=this.getQuoteLineCoordinate(),e=i.x,n=i.y,o=i.time,a=s("mark"),r=s("div",{className:"round"}),h=s("div",{className:"rect"}),l=s("div",{className:"markPriceLine"}),c=s("span",{className:"markPriceSpan"});a.appendChild(r),a.appendChild(h),a.appendChild(l),a.appendChild(c);var d={id:w++,price:this.getPrice(),x:e,y:n,el:a,createTime:o,children:{round:r,rect:h,markPriceLine:l,markPriceSpan:c},type:t};this.setMarkerStyle(d),this.markerList.push(d),this.patchMarker(d)},t.prototype.setMarkerStyle=function(t){var i=t.type===r.down?this.option.downColor:this.option.upColor;l(t.el,{left:t.x/2+"px",top:t.y/2+"px"}),l(t.children.round,{backgroundColor:i}),l(t.children.rect,{backgroundColor:i}),l(t.children.markPriceSpan,{backgroundColor:i,width:h.yAxisLegendTextLength/2+"px",height:h.TimeHorizonHeight/2+"px",left:(this.option.width-t.x)/2+"px"}),t.children.markPriceSpan.innerHTML=t.price.toString(),l(t.children.markPriceLine,{width:(this.option.width-t.x)/2+"px",backgroundImage:"linear-gradient(\n to right,\n "+i+" 0%,\n "+i+" 50%,\n transparent 50%\n )"})},t.prototype.updateMarkers=function(){var t=this;this.markerList.length&&this.markerList.forEach((function(i,e,n){var o=t.fetchMarkerCoordinate(n[e]),a=o.x,r=o.y;n[e].x=a,n[e].y=r,t.setMarkerStyle(n[e])}))},t.prototype.fetchMarkerCoordinate=function(t){var i=h.showData.find((function(i){return i.time===t.createTime})),e=0,n=(h.maxVal-t.price)/(h.maxVal-h.minVal)*(this.height-2*this.cPadding);return i&&i.leftCoordinate&&i.rightCoordinate&&(e=i.leftCoordinate),{x:e,y:n}},t.prototype.patchMarker=function(t){this.markContainer||(this.markContainer=s("div"),this.markContainer.id="markContainer",this.container.appendChild(this.markContainer)),l(t.el,{left:t.x/2+"px",top:t.y/2+"px"}),this.markContainer.appendChild(t.el)},t.prototype.flushMarker=function(){this.markContainer&&(this.markContainer.innerHTML=""),this.markerList=[]},t}(),v=function(){var t=function(i,e){return(t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,i){t.__proto__=i}||function(t,i){for(var e in i)Object.prototype.hasOwnProperty.call(i,e)&&(t[e]=i[e])})(i,e)};return function(i,e){if("function"!=typeof e&&null!==e)throw new TypeError("Class extends value "+String(e)+" is not a constructor or null");function n(){this.constructor=i}t(i,e),i.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)}}(),b=function(t,i,e,n){return new(e||(e=Promise))((function(o,a){function r(t){try{s(n.next(t))}catch(t){a(t)}}function h(t){try{s(n.throw(t))}catch(t){a(t)}}function s(t){var i;t.done?o(t.value):(i=t.value,i instanceof e?i:new e((function(t){t(i)}))).then(r,h)}s((n=n.apply(t,i||[])).next())}))},D=function(t,i){var e,n,o,a,r={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return a={next:h(0),throw:h(1),return:h(2)},"function"==typeof Symbol&&(a[Symbol.iterator]=function(){return this}),a;function h(a){return function(h){return function(a){if(e)throw new TypeError("Generator is already executing.");for(;r;)try{if(e=1,n&&(o=2&a[0]?n.return:a[0]?n.throw||((o=n.return)&&o.call(n),0):n.next)&&!(o=o.call(n,a[1])).done)return o;switch(n=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return r.label++,{value:a[1],done:!1};case 5:r.label++,n=a[1],a=[0];continue;case 7:a=r.ops.pop(),r.trys.pop();continue;default:if(!(o=r.trys,(o=o.length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){r=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){r.label=a[1];break}if(6===a[0]&&r.label<o[1]){r.label=o[1],o=a;break}if(o&&r.label<o[2]){r.label=o[2],r.ops.push(a);break}o[2]&&r.ops.pop(),r.trys.pop();continue}a=i.call(t,r)}catch(t){a=[6,t],n=0}finally{e=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,h])}}},M=function(t){function i(i,e){var n=t.call(this,i,e)||this;return n.container=i,n.createCanvasElement(i),n.ctx=n.canvas.getContext("2d"),n.lineBgColorBegin=n.option.lineBgColorBegin||"rgba(133,171,212,0.6)",n.lineBgColorEnd=n.option.lineBgColorEnd||"rgba(133,171,212,0.1)",n.BrokenLineColor=n.option.BrokenLineColor||"#3696F3",n.yLegendNum=10,h.legendYMargin=(n.option.height-4*n.option.cPadding)/(n.yLegendNum-1),n.xLegendNum=4,n.lastClientX=0,n.rightCandleOffset=0,n.leftCandleOffset=0,n.chartRightPadding="mobile"===n.option.mode?.15*n.option.width:.3*n.option.width,n.formatData(),h.showData=h.allData.slice(-200),n.candleNum=h.showData.length,n.candleWidth=(n.option.width-n.chartRightPadding-(3*n.cPadding-h.candleMargin)-h.candleMargin*(n.candleNum-1))/n.candleNum,n.ctx.font="24px Arial",n.ctx.textAlign="end",n.optionPanel=new y(n.container,n.originX,n.option.width,n.option.height,n.cPadding,n.chartRightPadding,n.BrokenLineColor,n.option.optionConf,n.option),n.drawChart(),n}return v(i,t),i.prototype.createCanvasElement=function(t){this.canvas=s("canvas"),this.canvas.height=this.option.height,this.canvas.width=this.option.width,this.canvas.style.width=this.option.originalWidth+"px",this.canvas.style.height=this.option.originalHeight+"px",t.appendChild(this.canvas)},i.prototype.formatData=function(){var t=this;h.allData.forEach((function(i,e,n){n[e].formatedTime=t.dateFormat("mm-dd HH:MM:SS",new Date(Number(i.time)))}))},i.prototype.drawChart=function(){this.clearCanvas(),this.getYlegend(),this.drawCandles(),this.drawAxis(),this.optionPanel.update()},i.prototype.getYlegend=function(){h.maxVal=0,h.minVal=9999999,h.showData.forEach((function(t){t.high>h.maxVal&&(h.maxVal=Number(t.high)),t.low<h.minVal&&(h.minVal=Number(t.low))}));var t=h.maxVal-h.minVal;h.maxVal+=.15*t,h.minVal-=.05*t,h.yAxisLegendTextLength=12*h.maxVal.toFixed(this.option.priceDigitnumber).length},i.prototype.drawAxis=function(){this.drawLine(this.originX,this.originY,this.option.width-this.option.cPadding,this.originY,{color:this.option.axisColor}),this.drawLine(this.originX,this.originY,this.originX,this.option.cPadding,{color:this.option.axisColor}),this.drawYAxis(),this.drawXAxis()},i.prototype.drawYAxis=function(){this.ctx.beginPath();var t=(h.maxVal-h.minVal)/(this.yLegendNum-1);this.ctx.fillStyle=this.option.legendColor;for(var i=0;i<this.yLegendNum;i++){var e=this.originY-h.tHeight-h.legendYMargin*i,n=(h.minVal+i*t).toFixed(this.option.priceDigitnumber);this.ctx.font="20px Arial","left"!==this.option.yAxisDirection&&this.option.yAxisDirection?"right"===this.option.yAxisDirection&&(this.ctx.textBaseline="top",this.ctx.textAlign="right",this.ctx.fillText(n,this.option.width-this.option.cPadding,e)):this.ctx.fillText(n,this.originX,e),this.ctx.textBaseline="alphabetic"}},i.prototype.drawXAxis=function(){var t=Math.round(h.showData.length/this.xLegendNum)+1;this.ctx.textAlign="left";for(var i=0;i<h.showData.length;i+=t){var e=h.showData[i];e.formatedTime&&this.ctx.fillText(e.formatedTime,e.leftCoordinate+(e.rightCoordinate-e.leftCoordinate)/2,this.option.height-this.option.cPadding)}},i.prototype.drawCandlestick=function(t,i){this.ctx.beginPath(),this.ctx.lineWidth=3;var e=this.originX+this.option.cPadding+i*this.candleWidth+(i-1)*h.candleMargin+this.candleWidth/2,n=(h.maxVal-t.high)/(h.maxVal-h.minVal)*(this.option.height-this.option.cPadding),o=(h.maxVal-t.low)/(h.maxVal-h.minVal)*(this.option.height-this.option.cPadding);t.open>t.close?this.drawLine(e,n,e,o,{color:this.option.downColor,width:3}):this.drawLine(e,n,e,o,{color:this.option.upColor,width:3}),this.ctx.stroke()},i.prototype.drawCandle=function(t,i){var e,n,o=this.originX+this.option.cPadding+i*this.candleWidth+(i-1)*h.candleMargin;t.open>t.close?(n=(t.open-t.close)/(h.maxVal-h.minVal)*(this.option.height-this.option.cPadding),e=(h.maxVal-t.open)/(h.maxVal-h.minVal)*(this.option.height-this.option.cPadding),this.drawRect(o,e,this.candleWidth,n,{fillStyle:this.option.downColor})):(n=(t.close-t.open)/(h.maxVal-h.minVal)*(this.option.height-this.option.cPadding),e=(h.maxVal-t.close)/(h.maxVal-h.minVal)*(this.option.height-this.option.cPadding),this.drawRect(o,e,this.candleWidth,n,{fillStyle:this.option.upColor}))},i.prototype.drawBrokenLine=function(t,i,e){void 0===e&&(e={});var n=this.originX+this.option.cPadding+i*this.candleWidth+(i-1)*h.candleMargin+this.candleWidth/2,o=(h.maxVal-t.close)/(h.maxVal-h.minVal)*(this.option.height-this.cPadding);0===i?this.ctx.moveTo(n,o):this.ctx.lineTo(n,o),this.ctx.strokeStyle=e.color||this.BrokenLineColor,e.width&&(this.ctx.lineWidth=e.width)},i.prototype.drawCandles=function(){var t=this;if(this.ctx.beginPath(),this.ctx.setLineDash([]),h.showData.forEach((function(i,e,n){"line"===h.chartType?(t.addCandleCoordinate(i,e,n),t.drawBrokenLine(i,e,{width:3})):(t.addCandleCoordinate(i,e,n),t.drawCandle(i,e),t.drawCandlestick(i,e))})),this.ctx.stroke(),"line"===h.chartType){var i=this.originX+this.option.cPadding-Number(h.candleMargin)+this.candleWidth/2,e=this.originX+this.option.cPadding+(h.showData.length-1)*this.candleWidth+(h.showData.length-2)*h.candleMargin+this.candleWidth/2;this.ctx.lineTo(e,this.originY),this.ctx.lineTo(i,this.originY);var n=this.ctx.createLinearGradient(0,0,0,300);n.addColorStop(0,this.lineBgColorBegin),n.addColorStop(1,this.lineBgColorEnd),this.ctx.fillStyle=n,this.ctx.fill(),this.ctx.closePath()}},i.prototype.addCandleCoordinate=function(t,i,e){var n=this.originX+this.option.cPadding+i*this.candleWidth+(i-1)*h.candleMargin;e[i].leftCoordinate=Number(n.toFixed(2)),e[i].leftCoordinate=Number(e[i].leftCoordinate),e[i].rightCoordinate=Number((n+this.candleWidth).toFixed(2)),e[i].rightCoordinate=Number(e[i].rightCoordinate)},i.prototype.canvasMouseDown=function(){},i.prototype.canvasMouseWheel=function(){},i.prototype.canvasMouseMove=function(){},i.prototype.updateLastCandle=function(t,i){var e=h.allData[h.allData.length-1].close,n={open:e,low:e<i?e:i,close:i,high:e>i?e:i,time:t,formatedTime:this.dateFormat("mm-dd HH:MM:SS",new Date(Date.now()))};h.allData.push(n),0===this.rightCandleOffset?h.showData=h.allData.slice(-this.candleNum):this.rightCandleOffset++},i.prototype.timeCheck=function(t,i){if(this.option.timeCheckErrorHandler){var e=Math.abs(new Date(i).getMinutes()-new Date(t).getMinutes());switch(this.option.interval){case"1m":e>1&&this.option.timeCheckErrorHandler(e-1);break;case"5m":e>5&&this.option.timeCheckErrorHandler(e-5);break;case"15m":e>15&&this.option.timeCheckErrorHandler(e-15);break;case"30m":e>30&&this.option.timeCheckErrorHandler(e-30);break;case"60m":e>60&&this.option.timeCheckErrorHandler(e-60);break;case"1d":e>1440&&this.option.timeCheckErrorHandler(e-1440)}}},i.prototype.subscribeBars=function(t,i){return b(this,void 0,void 0,(function(){var e,n;return D(this,(function(o){return t=Number(t),e=h.allData[h.allData.length-1],n=new Date(Number(e.time)),this.timeCheck(n.getTime(),t),this.updateLastCandle(t,i),this.drawChart(),[2]}))}))},i.prototype.mark=function(t){this.optionPanel.mark(t)},i}(h),A=function(){var t=function(i,e){return(t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,i){t.__proto__=i}||function(t,i){for(var e in i)Object.prototype.hasOwnProperty.call(i,e)&&(t[e]=i[e])})(i,e)};return function(i,e){if("function"!=typeof e&&null!==e)throw new TypeError("Class extends value "+String(e)+" is not a constructor or null");function n(){this.constructor=i}t(i,e),i.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)}}(),L=function(t){function i(i,e){var n=t.call(this,i,e)||this;return n.option=e,n.createCanvasElement(i),n.ctx=n.canvas.getContext("2d"),n.quotePanel=new p(n.container,e),n}return A(i,t),i.prototype.createCanvasElement=function(t){this.canvas=s("canvas"),this.canvas.height=this.option.height,this.canvas.width=this.option.width,this.canvas.style.width=this.option.originalWidth+"px",this.canvas.style.height=this.option.originalHeight+"px",this.canvas.style.position="absolute",this.canvas.style.top="0",this.canvas.style.left="0",this.canvas.style.zIndex="10",t.appendChild(this.canvas)},i.prototype.canvasMouseMove=function(t,i){void 0===i&&(i=!0),this.clearCanvas();var e,n,o=0,a=0;t.offsetX?(e=t.offsetX,n=t.offsetY):(e=t.touches[0].clientX,n=t.touches[0].clientY-this.container.getBoundingClientRect().y);for(var r=0;r<h.showData.length;r++){var s=h.showData[r];2*e<s.rightCoordinate&&2*e>=s.leftCoordinate-h.candleMargin&&(o=(s.rightCoordinate/2-s.leftCoordinate/2)/2+s.leftCoordinate/2,a=n)}a>=5&&a<=this.container.clientHeight-10&&this.drawCrossAxis(2*o,2*a)},i.prototype.canvasMouseDown=function(t){this.clearCanvas();for(var i=0,e=0,n=0;n<h.showData.length;n++){var o=h.showData[n],a=void 0,r=void 0;a="touches"in t?t.touches[0].clientX:t.offsetX,r="touches"in t?t.touches[0].clientY-this.container.getBoundingClientRect().y:t.offsetY,2*a<o.rightCoordinate&&2*a>=o.leftCoordinate-h.candleMargin&&(i=(o.rightCoordinate/2-o.leftCoordinate/2)/2+o.leftCoordinate/2,e=r)}this.findCurCandle(2*i),e>=5&&e<=this.container.clientHeight-10&&this.drawCrossAxis(2*i,2*e),this.drawCurCandleBg(null!=document.getElementById("curCandleOHLCInfoContainer"))},i.prototype.drawCrossAxis=function(t,i){"pc"===this.option.mode&&(this.clearCanvas(),this.findCurCandle(t),this.drawCurCandleBg(null!=document.getElementById("curCandleOHLCInfoContainer"))),this.drawLine(0,i,this.option.width,i,{dottal:{x:5,y:5},color:"#fff",width:1}),"line"===h.chartType&&this.drawLine(t,0,t,this.option.height,{dottal:{x:5,y:5},color:"#fff",width:1}),this.ctx.stroke(),this.drawXLegend(t),this.drawYLegend(i)},i.prototype.drawXLegend=function(t){if(h.curCandle){var i=this.dateFormat("dd-mm-YYYY HH:MM",new Date(Number(h.curCandle.time))),e=12*i.length,n=this.option.height-this.cPadding-h.TimeHorizonHeight;this.drawRect(t-e/2,n,e,h.TimeHorizonHeight,{fillStyle:"#5e606d"}),this.ctx.font="20px Arial",this.ctx.fillStyle="#fff",this.ctx.textAlign="center",this.ctx.textBaseline="middle",this.ctx.fillText(i,t,this.option.height-this.cPadding-h.TimeHorizonHeight/2)}},i.prototype.drawYLegend=function(t){var i=this.originX+this.option.width,e=h.maxVal-h.minVal,n=this.option.height-2*this.cPadding,o=(h.maxVal-t*e/n).toFixed(this.option.priceDigitnumber);this.drawRect(i-h.yAxisLegendTextLength,t-h.TimeHorizonHeight/2,h.yAxisLegendTextLength,h.TimeHorizonHeight,{fillStyle:"#5e606d"}),this.ctx.font="20px Arial",this.ctx.fillStyle="#fff",this.ctx.textAlign="center",this.ctx.textBaseline="middle",this.ctx.fillText(o,i-h.yAxisLegendTextLength/2,t)},i.prototype.drawCurCandleBg=function(t){if("candle"===h.chartType&&t&&h.curCandle.leftCoordinate){var i=this.ctx.createLinearGradient(h.curCandle.leftCoordinate,0,h.curCandle.leftCoordinate,this.option.height-this.cPadding);i.addColorStop(0,"rgba(0,0,0,0.2)"),i.addColorStop(.5,"rgba(255,255,255,0.2)"),i.addColorStop(1,"rgba(0,0,0,0.2)"),this.drawRect(h.curCandle.leftCoordinate,0,h.curCandle.rightCoordinate-h.curCandle.leftCoordinate,this.option.height-this.cPadding,{fillStyle:i})}},i.prototype.findCurCandle=function(t){h.isTimeToUpdateCurCandle=!0;for(var i=0;i<h.showData.length;i++){var e=h.showData[i];if(t<e.rightCoordinate&&t>=e.leftCoordinate-h.candleMargin){i!==h.showData.length-1&&(h.isTimeToUpdateCurCandle=!1),i<h.showData.length/2?h.infoContainerPosition=a.right:h.infoContainerPosition=a.left,("pc"===this.option.mode&&h.curCandle&&h.curCandle.time!==e.time||"mobile"===this.option.mode)&&(h.curCandle=e,"candle"===h.chartType&&(this.quotePanel.drawCurCandleOHLCInfo(),this.quotePanel.drawCurCandleMAInfo()));break}}this.quotePanel.updateCurCandleInfo()},i}(h);!function(t){t.quote="quote",t.option="option"}(d||(d={}));var P=d,k=function(){return(k=Object.assign||function(t){for(var i,e=1,n=arguments.length;e<n;e++)for(var o in i=arguments[e])Object.prototype.hasOwnProperty.call(i,o)&&(t[o]=i[o]);return t}).apply(this,arguments)},T=function(t,i,e,n){return new(e||(e=Promise))((function(o,a){function r(t){try{s(n.next(t))}catch(t){a(t)}}function h(t){try{s(n.throw(t))}catch(t){a(t)}}function s(t){var i;t.done?o(t.value):(i=t.value,i instanceof e?i:new e((function(t){t(i)}))).then(r,h)}s((n=n.apply(t,i||[])).next())}))},O=function(t,i){var e,n,o,a,r={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return a={next:h(0),throw:h(1),return:h(2)},"function"==typeof Symbol&&(a[Symbol.iterator]=function(){return this}),a;function h(a){return function(h){return function(a){if(e)throw new TypeError("Generator is already executing.");for(;r;)try{if(e=1,n&&(o=2&a[0]?n.return:a[0]?n.throw||((o=n.return)&&o.call(n),0):n.next)&&!(o=o.call(n,a[1])).done)return o;switch(n=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return r.label++,{value:a[1],done:!1};case 5:r.label++,n=a[1],a=[0];continue;case 7:a=r.ops.pop(),r.trys.pop();continue;default:if(!(o=r.trys,(o=o.length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){r=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){r.label=a[1];break}if(6===a[0]&&r.label<o[1]){r.label=o[1],o=a;break}if(o&&r.label<o[2]){r.label=o[2],r.ops.push(a);break}o[2]&&r.ops.pop(),r.trys.pop();continue}a=i.call(t,r)}catch(t){a=[6,t],n=0}finally{e=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,h])}}},N=function(){function t(t){this.initOption(t),this.addStatus(this.option.data),this.patchChart()}return t.prototype.initOption=function(t){this.mergeOption(t),this.initOptionFun(t)},t.prototype.mergeOption=function(t){var i=JSON.parse(JSON.stringify(t)),e=k({width:2*i.originalWidth,height:2*i.originalHeight},i);this.option=e},t.prototype.initOptionFun=function(t){for(var i=Object.keys(t),e=0;e<i.length;e++){var n=i[e],o=t[n];"function"==typeof o&&(this.option[n]=o)}},t.prototype.patchChart=function(){if(null===document.getElementById(this.option.container))throw new Error("container not found");switch(this.container=document.getElementById(this.option.container),this.container.className="__tcContainer__",this.container.style.position="relative",this.container.style.cursor="crosshair",this.container.innerHTML="",this.cursorChart=new L(this.container,this.option),this.option.chartSeries){case P.quote:this.mainChart=new x(this.container,this.option);break;case P.option:this.mainChart=new M(this.container,this.option);break;default:this.mainChart=new x(this.container,this.option)}this.bindEvents(),this.cursorChart.drawLogo()},t.prototype.subscribeBars=function(t,i){return T(this,void 0,void 0,(function(){return O(this,(function(e){switch(e.label){case 0:return[4,this.mainChart.subscribeBars(t,i)];case 1:return e.sent(),[2]}}))}))},t.prototype.addStatus=function(t){t.forEach((function(t,i,e){t.open>t.close?e[i].status=r.down:e[i].status=r.up}))},t.prototype.bindEvents=function(){"mobile"===this.option.mode?this.container.ontouchstart=this.canvasMouseDown.bind(this):this.container.onmousedown=this.canvasMouseDown.bind(this),this.container.onmousewheel=this.canvasMouseWheel.bind(this),this.container.addEventListener("DOMMouseScroll",this.canvasMouseWheel.bind(this),!1),"pc"===this.option.mode&&(this.container.onmousemove=this.cursorChart.canvasMouseMove.bind(this.cursorChart))},t.prototype.canvasMouseDown=function(t){this.container.style.cursor="move",this.cursorChart.canvasMouseDown(t),this.mainChart.canvasMouseDown(t),"pc"===this.option.mode?(this.container.onmousemove=this.canvasMouseMove.bind(this),this.container.onmouseup=this.canvasMouseUp.bind(this)):(this.container.ontouchmove=this.canvasMouseMove.bind(this),this.container.ontouchend=this.canvasMouseUp.bind(this))},t.prototype.canvasMouseMove=function(t){return T(this,void 0,void 0,(function(){return O(this,(function(i){switch(i.label){case 0:return t.touches&&t.touches.length>1&&this.canvasMouseWheel(t),t.touches&&1===t.touches.length?(this.cursorChart.canvasMouseMove(t),[4,this.mainChart.canvasMouseMove(t)]):[3,2];case 1:i.sent(),i.label=2;case 2:return"pc"!==this.option.mode?[3,4]:(this.cursorChart.canvasMouseMove(t),[4,this.mainChart.canvasMouseMove(t)]);case 3:i.sent(),i.label=4;case 4:return[2]}}))}))},t.prototype.canvasMouseWheel=function(t){this.mainChart.canvasMouseWheel(t),this.cursorChart.canvasMouseWheel(t)},t.prototype.canvasMouseUp=function(t){this.mainChart.canvasMouseUp(t),this.cursorChart.canvasMouseUp(t),this.container.onmousemove=null,this.container.ontouchmove=null,this.container.onmouseup=null,this.container.ontouchend=null,"pc"===this.option.mode&&(this.container.onmousemove=this.cursorChart.canvasMouseMove.bind(this.cursorChart)),this.container.style.cursor="crosshair"},t.prototype.mark=function(t){this.mainChart instanceof M&&this.mainChart.mark(t)},t}();i.default=N}])})); | ||
!function(t,i){"object"==typeof exports&&"object"==typeof module?module.exports=i():"function"==typeof define&&define.amd?define([],i):"object"==typeof exports?exports.TradeChart=i():t.TradeChart=i()}(this,(function(){return function(t){var i={};function e(n){if(i[n])return i[n].exports;var o=i[n]={i:n,l:!1,exports:{}};return t[n].call(o.exports,o,o.exports,e),o.l=!0,o.exports}return e.m=t,e.c=i,e.d=function(t,i,n){e.o(t,i)||Object.defineProperty(t,i,{enumerable:!0,get:n})},e.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},e.t=function(t,i){if(1&i&&(t=e(t)),8&i)return t;if(4&i&&"object"==typeof t&&t&&t.__esModule)return t;var n=Object.create(null);if(e.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:t}),2&i&&"string"!=typeof t)for(var o in t)e.d(n,o,function(i){return t[i]}.bind(null,o));return n},e.n=function(t){var i=t&&t.__esModule?function(){return t.default}:function(){return t};return e.d(i,"a",i),i},e.o=function(t,i){return Object.prototype.hasOwnProperty.call(t,i)},e.p="",e(e.s=1)}([function(t,i){t.exports="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAJ8AAAAaCAYAAACpZo6LAAAACXBIWXMAAAsTAAALEwEAmpwYAAAFyGlUWHRYTUw6Y29tLmFkb2JlLnhtcAAAAAAAPD94cGFja2V0IGJlZ2luPSLvu78iIGlkPSJXNU0wTXBDZWhpSHpyZVN6TlRjemtjOWQiPz4gPHg6eG1wbWV0YSB4bWxuczp4PSJhZG9iZTpuczptZXRhLyIgeDp4bXB0az0iQWRvYmUgWE1QIENvcmUgNi4wLWMwMDIgNzkuMTY0NDYwLCAyMDIwLzA1LzEyLTE2OjA0OjE3ICAgICAgICAiPiA8cmRmOlJERiB4bWxuczpyZGY9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkvMDIvMjItcmRmLXN5bnRheC1ucyMiPiA8cmRmOkRlc2NyaXB0aW9uIHJkZjphYm91dD0iIiB4bWxuczp4bXA9Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC8iIHhtbG5zOnhtcE1NPSJodHRwOi8vbnMuYWRvYmUuY29tL3hhcC8xLjAvbW0vIiB4bWxuczpzdEV2dD0iaHR0cDovL25zLmFkb2JlLmNvbS94YXAvMS4wL3NUeXBlL1Jlc291cmNlRXZlbnQjIiB4bWxuczpkYz0iaHR0cDovL3B1cmwub3JnL2RjL2VsZW1lbnRzLzEuMS8iIHhtbG5zOnBob3Rvc2hvcD0iaHR0cDovL25zLmFkb2JlLmNvbS9waG90b3Nob3AvMS4wLyIgeG1wO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6aikfj6iNf1VNGH/yJCXfGWkOaz6rCG/42mitU3Qwg6gBGb4+VFzLaHo+AFS2fb3Bj34F24SncXLKpz7xpwXM0gT/TvhfrzY7sMk8BtEln2e+02kVc+TPpc54H1kWvfTOo+sfh6Hg6QAtbQfEJ1A5CqC87io6DlkPotGjxYBqqqcpb1obhvZP4BqIAFmnaYZxpm6m2QfNh1EG7ALl5ecQcQqgn7Tl13D8G9O0jCKNvNm/gnqw4369doCIl78NxA7UN5nlOwk5deDQvXkS3zz8t0WNjHSyPc2yeF+gPy2BdyBgzTtZA9cDqGdbI8PlZD2WUVR5m1zFY04t/AY4r+SBIExBlg2GgAAAABJRU5ErkJggg=="},function(t,i,e){"use strict";var n;e.r(i),function(t){t.left="left",t.right="right"}(n||(n={}));var o,a=n;!function(t){t.up="up",t.down="down"}(o||(o={}));var r=o,h=function(){function t(t,i){this.initState(t,i)}return t.prototype.canvasMouseDown=function(t){},t.prototype.canvasMouseWheel=function(t){},t.prototype.canvasMouseMove=function(t){},t.prototype.canvasMouseUp=function(t){},t.prototype.initState=function(i,e){this.ctx=null,this.canvas=null,t.isTimeToUpdateCurCandle=!0,this.option=e,this.addStatus(this.option.data),t.allData=this.option.data,t.chartType=this.option.chartType||"candle",t.showDataNum="pc"===this.option.mode?50:30,this.container=i,this.fontSize=this.option.fontSize||"18px",this.cPadding=this.option.cPadding,this.tSpace=this.option.tSpace||100,this.originX=this.option.cPadding,this.originY=this.option.height-this.cPadding,this.chartRightPadding="mobile"===this.option.mode?.15*this.option.width:.08*this.option.width},t.prototype.drawTrigon=function(t,i,e,n,o){if("right"===n){var a=t-10,r="maxHigh"===o?i+1:i-1;this.ctx.beginPath(),this.ctx.setLineDash([]),this.ctx.strokeStyle="#A0A4AB",this.ctx.moveTo(a+60,r),this.ctx.lineTo(a+30,r),this.ctx.stroke(),this.ctx.beginPath(),this.ctx.moveTo(a+30,r),this.ctx.lineTo(a+45,r-10),this.ctx.lineTo(a+35,r),this.ctx.lineTo(a+45,r+10),this.ctx.fillStyle="#A0A4AB",this.ctx.fill(),this.ctx.font="20px Arial",this.ctx.textBaseline="middle",this.ctx.textAlign="left",this.ctx.fillText(e,a+65,r)}else{var h=t+10,s="maxHigh"===o?i+1:i-1;this.ctx.beginPath(),this.ctx.setLineDash([]),this.ctx.strokeStyle="#A0A4AB",this.ctx.moveTo(h-30,s),this.ctx.lineTo(h-60,s),this.ctx.stroke(),this.ctx.beginPath(),this.ctx.moveTo(h-30,s),this.ctx.lineTo(h-45,s-10),this.ctx.lineTo(h-35,s),this.ctx.lineTo(h-45,s+10),this.ctx.fillStyle="#A0A4AB",this.ctx.fill(),this.ctx.font="20px Arial",this.ctx.textBaseline="middle",this.ctx.textAlign="left",this.ctx.fillText(e,h-145,s)}},t.prototype.drawLine=function(t,i,e,n,o){void 0===o&&(o={}),this.ctx.setLineDash([]),this.ctx.moveTo(t,i),o&&(o.color&&(this.ctx.strokeStyle=o.color),o.dottal&&this.ctx.setLineDash([o.dottal.x,o.dottal.y]),o.width&&(this.ctx.lineWidth=o.width)),this.ctx.lineTo(e,n)},t.prototype.drawLineTransition=function(t,i,e,n,o){void 0===o&&(o={});var a=[{x:t,y:i},{x:e,y:n}],r=this.calcWaypoints(a);this.ctx.beginPath(),this.ctx.moveTo(r[0].x,r[0].y),this.ctx.lineTo(r[1].x,r[1].y),this.ctx.stroke()},t.prototype.calcWaypoints=function(t){for(var i=[],e=1;e<t.length;e++)for(var n=t[e-1],o=t[e],a=o.x-n.x,r=o.y-n.y,h=0;h<100;h++){var s=n.x+a*h/100,l=n.y+r*h/100;i.push({x:s,y:l})}return i},t.prototype.drawRect=function(t,i,e,n,o){this.ctx.beginPath(),o&&(this.ctx.fillStyle=o.fillStyle),this.ctx.fillRect(t,i,e,n)},t.prototype.clearCanvas=function(){this.canvas.height=this.option.height,this.canvas.width=this.option.width},t.prototype.dateFormat=function(t,i){var e,n={"Y+":i.getFullYear().toString(),"m+":(i.getMonth()+1).toString(),"d+":i.getDate().toString(),"H+":i.getHours().toString(),"M+":i.getMinutes().toString(),"S+":i.getSeconds().toString()};for(var o in n)n.hasOwnProperty(o)&&(e=new RegExp("("+o+")").exec(t))&&(t=t.replace(e[1],1===e[1].length?n[o]:n[o].padStart(e[1].length,"0")));return t},t.prototype.drawLogo=function(){var t=document.createElement("img");t.setAttribute("src",e(0)),t.style.position="absolute",t.style.left="1%",t.style.maxWidth="100px",t.style.opacity="0.5",t.style.bottom="5%",t.style.userSelect="none",this.container.appendChild(t)},t.prototype.Pythagorean=function(t,i){var e=Math.abs(t.clientX-i.clientX),n=Math.abs(t.clientY-i.clientY);return Math.sqrt(Math.pow(e,2)+Math.pow(n,2))},t.prototype.addStatus=function(t){t.forEach((function(t,i,e){t.open>t.close?e[i].status=r.down:e[i].status=r.up}))},t.tHeight=15,t.TimeHorizonHeight=30,t.minVal=9999999,t.maxVal=0,t.candleMargin=1,t.isTouch=!1,t.infoContainerPosition=a.left,t.curCandleCoord={offsetX:0,offsetY:0},t}();function s(t,i){void 0===i&&(i={});var e=document.createElement(t);for(var n in i)Object.prototype.hasOwnProperty.call(i,n)&&(e[n]=i[n]);return e}function l(t,i){for(var e in i)Object.prototype.hasOwnProperty.call(i,e)&&(t.style[e]=i[e])}var c,d,p=function(){function t(t,i){this.container=t,this.option=i}return t.prototype.createInfoElement=function(t){var i=s("div");return i.id=t,l(i,{minWidth:"25%",background:"#1D2027",border:"#eee",padding:"6px 5px",display:"flex",flexDirection:"column",position:"absolute",top:"7%"}),"left"===this.infoContainerPosition?l(i,{left:"2%"}):l(i,{right:"2%"}),i},t.prototype.updateCurCandleInfo=function(){h.isTimeToUpdateCurCandle&&(h.curCandle=h.allData[h.allData.length-1],this.drawCurCandleMAInfo(),this.curCandleOHLCInfoContainer&&(l(this.curCandleOHLCInfoContainer,{color:"up"===h.curCandle.status?"#57CF8D":"#EB2F34"}),this.appendCurCandleOHLCInfo()))},t.prototype.drawCurCandleMAInfo=function(){"candle"===h.chartType&&(this.curCandleMAContainer?(this.curCandleMAContainer=this.container.querySelector("#curCandleMAContainer"),this.patchCurCandleMAInfo(this.curCandleMAContainer)):(this.curCandleMAContainer=s("div"),this.curCandleMAContainer.setAttribute("id","curCandleMAContainer"),l(this.curCandleMAContainer,{position:"absolute",marginTop:"5px",display:"flex",top:"0%",left:"2%",userSelect:"none"}),this.patchCurCandleMAInfo(this.curCandleMAContainer),this.container.appendChild(this.curCandleMAContainer)))},t.prototype.patchCurCandleMAInfo=function(t){var i="";if(this.option.MA&&this.option.MA.length){for(var e=0;e<this.option.MA.length;e++){var n=this.option.MA[e];h.curCandle["MA"+n.interval]?i+='\n <div style="color: '+n.color+';text-align: left;margin-top: 5px;margin-right:8px">\n MA'+n.interval+": "+h.curCandle["MA"+n.interval]+"\n </div>\n ":i+='\n <div style="color: '+n.color+';text-align: left;margin-top: 5px;margin-right:8px">\n MA'+n.interval+" : -- --\n </div>\n "}t.innerHTML=i}},t.prototype.drawCurCandleOHLCInfo=function(){this.curCandleOHLCInfoContainer?"mobile"===this.option.mode?(this.container.removeChild(this.curCandleOHLCInfoContainer),this.curCandleOHLCInfoContainer=null):(l(this.curCandleOHLCInfoContainer,{color:"up"===h.curCandle.status?"#57CF8D":"#EB2F34"}),"left"===h.infoContainerPosition?l(this.curCandleOHLCInfoContainer,{right:"unset",left:"2%"}):l(this.curCandleOHLCInfoContainer,{left:"unset",right:"2%"}),this.appendCurCandleOHLCInfo()):(this.curCandleOHLCInfoContainer=this.createInfoElement("curCandleOHLCInfoContainer"),l(this.curCandleOHLCInfoContainer,{color:"up"===h.curCandle.status?"#57CF8D":"#EB2F34",userSelect:"none"}),this.appendCurCandleOHLCInfo(),this.container.appendChild(this.curCandleOHLCInfoContainer))},t.prototype.appendCurCandleOHLCInfo=function(){var t=h.curCandle.close-h.curCandle.open,i=t/h.curCandle.open;this.curCandleOHLCInfoContainer&&(this.curCandleOHLCInfoContainer.innerHTML='\n <div style="flex:1;display:flex; width:100%;justify-content:space-between;">\n <span>Open:</span>\n <span>'+h.curCandle.open+'</span>\n </div>\n <div style="flex:1;display:flex;width:100%;justify-content:space-between;">\n <span>High:</span>\n <span>'+h.curCandle.high+'</span>\n </div>\n <div style="flex:1;display:flex;width:100%;justify-content:space-between;">\n <span>Low:</span>\n <span>'+h.curCandle.low+'</span>\n </div>\n <div style="flex:1;display:flex;width:100%;justify-content:space-between;">\n <span>Close:</span>\n <span>'+h.curCandle.close+'</span>\n </div>\n <div style="flex:1;display:flex;width:100%;justify-content:space-between;">\n <span>change:</span>\n <span>'+(t>0?"+":"")+t.toFixed(this.option.priceDigitnumber)+'</span>\n </div>\n <div style="flex:1;display:flex;width:100%;justify-content:space-between;">\n <span>change%:</span>\n <span>'+(i>0?"+":"")+(100*i).toFixed(2)+"%</span>\n </div>\n ")},t}(),u=(c=function(t,i){return(c=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,i){t.__proto__=i}||function(t,i){for(var e in i)Object.prototype.hasOwnProperty.call(i,e)&&(t[e]=i[e])})(t,i)},function(t,i){function e(){this.constructor=t}c(t,i),t.prototype=null===i?Object.create(i):(e.prototype=i.prototype,new e)}),f=function(t,i,e,n){return new(e||(e=Promise))((function(o,a){function r(t){try{s(n.next(t))}catch(t){a(t)}}function h(t){try{s(n.throw(t))}catch(t){a(t)}}function s(t){var i;t.done?o(t.value):(i=t.value,i instanceof e?i:new e((function(t){t(i)}))).then(r,h)}s((n=n.apply(t,i||[])).next())}))},g=function(t,i){var e,n,o,a,r={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return a={next:h(0),throw:h(1),return:h(2)},"function"==typeof Symbol&&(a[Symbol.iterator]=function(){return this}),a;function h(a){return function(h){return function(a){if(e)throw new TypeError("Generator is already executing.");for(;r;)try{if(e=1,n&&(o=2&a[0]?n.return:a[0]?n.throw||((o=n.return)&&o.call(n),0):n.next)&&!(o=o.call(n,a[1])).done)return o;switch(n=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return r.label++,{value:a[1],done:!1};case 5:r.label++,n=a[1],a=[0];continue;case 7:a=r.ops.pop(),r.trys.pop();continue;default:if(!(o=r.trys,(o=o.length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){r=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){r.label=a[1];break}if(6===a[0]&&r.label<o[1]){r.label=o[1],o=a;break}if(o&&r.label<o[2]){r.label=o[2],r.ops.push(a);break}o[2]&&r.ops.pop(),r.trys.pop();continue}a=i.call(t,r)}catch(t){a=[6,t],n=0}finally{e=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,h])}}},m=function(t,i){var e="function"==typeof Symbol&&t[Symbol.iterator];if(!e)return t;var n,o,a=e.call(t),r=[];try{for(;(void 0===i||i-- >0)&&!(n=a.next()).done;)r.push(n.value)}catch(t){o={error:t}}finally{try{n&&!n.done&&(e=a.return)&&e.call(a)}finally{if(o)throw o.error}}return r},C=function(){for(var t=[],i=0;i<arguments.length;i++)t=t.concat(m(arguments[i]));return t},x=function(t){function i(i,e){var n=t.call(this,i,e)||this;return n.loadMore=!1,n.quotePanel=new p(i,e),n.createCanvasElement(i),n.ctx=n.canvas.getContext("2d"),n.lineBgColorBegin=n.option.lineBgColorBegin||"rgba(133,171,212,0.6)",n.lineBgColorEnd=n.option.lineBgColorEnd||"rgba(133,171,212,0.1)",n.BrokenLineColor=n.option.BrokenLineColor||"#3696F3",n.yLegendNum=10,h.legendYMargin=(n.option.height-4*n.option.cPadding)/(n.yLegendNum-1),n.xLegendNum=4,n.lastClientX=0,n.rightCandleOffset=0,n.leftCandleOffset=0,n.formatData(),h.showData=h.allData.slice(-h.showDataNum),n.quotePanel.updateCurCandleInfo(),n.candleNum=h.showData.length,n.candleWidth=(n.option.width-n.chartRightPadding-(3*n.cPadding-h.candleMargin)-h.candleMargin*(n.candleNum-1))/n.candleNum,n.ctr=e.animate?1:100,n.numctr=100,n.speed=3,n.ctx.font="24px Arial",n.ctx.textAlign="end",n.drawChart(),n.lastDiff=0,n}return u(i,t),i.prototype.createCanvasElement=function(t){this.canvas=s("canvas"),this.canvas.height=this.option.height,this.canvas.width=this.option.width,this.canvas.style.width=this.option.originalWidth+"px",this.canvas.style.height=this.option.originalHeight+"px",t.appendChild(this.canvas)},i.prototype.drawMinMaxText=function(){var t=0,i={high:0,low:0,close:0,open:0};h.showData.forEach((function(e,n){e.high>i.high&&(i=e,t=n)}));var e=this.originX+this.option.cPadding+t*this.candleWidth+(t-1)*h.candleMargin+this.candleWidth/2,n=(h.maxVal-i.high)/(h.maxVal-h.minVal)*(this.option.height-this.option.cPadding),o="left";t<=15&&(o="right"),this.drawTrigon(e,n,i.high.toString(),o,"maxHigh");var a=0,r={high:0,low:Number.MAX_VALUE,close:0,open:0};h.showData.forEach((function(t,i){t.low<r.low&&(r=t,a=i)}));var s=this.originX+this.option.cPadding+a*this.candleWidth+(a-1)*h.candleMargin+this.candleWidth/2,l=(h.maxVal-r.low)/(h.maxVal-h.minVal)*(this.option.height-this.option.cPadding),c="left";a<=15&&(c="right"),this.drawTrigon(s,l,r.low.toString(),c,"minLow")},i.prototype.formatData=function(){var t=this;h.allData.forEach((function(i,e,n){"1m"===t.option.interval||"5m"===t.option.interval?t.xLegendNum=8:"15m"===t.option.interval||"30m"===t.option.interval||"60m"===t.option.interval?(t.xLegendNum=5,t.tSpace=50):"1d"===t.option.interval&&(t.xLegendNum=8),n[e].formatedTime=t.dateFormat(t.formatTimeRule(),new Date(Number(i.time)))}))},i.prototype.formatTimeRule=function(){return"1m"===this.option.interval||"5m"===this.option.interval?"HH:MM":"15m"===this.option.interval||"30m"===this.option.interval||"60m"===this.option.interval?"mm/dd HH:MM":"1d"===this.option.interval?"mm/dd":"yyyy-mm-dd HH:MM:SS"},i.prototype.drawChart=function(){this.clearCanvas(),this.getYlengend(),this.drawCandles(),this.drawAxis(),this.drawRealTimeHorizon(),"candle"===h.chartType&&(this.drawMinMaxText(),this.drawMAs())},i.prototype.getYlengend=function(){h.maxVal=0,h.minVal=9999999,h.showData.forEach((function(t){t.high>h.maxVal&&(h.maxVal=Number(t.high)),t.low<h.minVal&&(h.minVal=Number(t.low))}));var t=h.maxVal-h.minVal;h.maxVal+=.15*t,h.minVal-=.05*t,h.yAxisLegendTextLength=12*h.maxVal.toFixed(this.option.priceDigitnumber).length},i.prototype.drawAxis=function(){this.drawLine(this.originX,this.originY,this.option.width-this.option.cPadding,this.originY,{color:this.option.axisColor}),this.drawLine(this.originX,this.originY,this.originX,this.option.cPadding,{color:this.option.axisColor}),this.drawYAxis(),this.drawXAxis()},i.prototype.drawYAxis=function(){this.ctx.beginPath();var t=(h.maxVal-h.minVal)/(this.yLegendNum-1);this.ctx.fillStyle=this.option.legendColor;for(var i=0;i<this.yLegendNum;i++){var e=this.originY-h.tHeight-h.legendYMargin*i,n=(h.minVal+i*t).toFixed(this.option.priceDigitnumber);this.ctx.font="20px Arial","left"!==this.option.yAxisDirection&&this.option.yAxisDirection?"right"===this.option.yAxisDirection&&(this.ctx.textBaseline="top",this.ctx.textAlign="right",this.ctx.fillText(n,this.option.width-this.option.cPadding,e)):this.ctx.fillText(n,this.originX,e),this.ctx.textBaseline="alphabetic"}},i.prototype.drawXAxis=function(){var t=Math.round(h.showData.length/this.xLegendNum)+1;this.ctx.textAlign="left";for(var i=0;i<h.showData.length;i+=t){var e=h.showData[i];e.formatedTime&&this.ctx.fillText(e.formatedTime,e.leftCoordinate+(e.rightCoordinate-e.leftCoordinate)/2,this.option.height-this.option.cPadding)}},i.prototype.drawCandlestick=function(t,i){this.ctx.beginPath(),this.ctx.lineWidth=3;var e=this.originX+this.option.cPadding+i*this.candleWidth+(i-1)*h.candleMargin+this.candleWidth/2,n=(h.maxVal-t.high)/(h.maxVal-h.minVal)*(this.option.height-this.option.cPadding),o=(h.maxVal-t.low)/(h.maxVal-h.minVal)*(this.option.height-this.option.cPadding);t.open>t.close?this.drawLine(e,n,e,o,{color:this.option.downColor,width:3}):this.drawLine(e,n,e,o,{color:this.option.upColor,width:3}),this.ctx.stroke()},i.prototype.drawCandle=function(t,i){var e,n,o=this.originX+this.option.cPadding+i*this.candleWidth+(i-1)*h.candleMargin;t.open>t.close?(n=(t.open-t.close)/(h.maxVal-h.minVal)*(this.option.height-this.option.cPadding),e=(h.maxVal-t.open)/(h.maxVal-h.minVal)*(this.option.height-this.option.cPadding),this.drawRect(o,e,this.candleWidth*this.ctr/this.numctr,n,{fillStyle:this.option.downColor})):(n=(t.close-t.open)/(h.maxVal-h.minVal)*(this.option.height-this.option.cPadding),e=(h.maxVal-t.close)/(h.maxVal-h.minVal)*(this.option.height-this.option.cPadding),this.drawRect(o,e,this.candleWidth*this.ctr/this.numctr,n,{fillStyle:this.option.upColor}))},i.prototype.drawBrokenLine=function(t,i,e){void 0===e&&(e={});var n=this.originX+this.option.cPadding+i*this.candleWidth+(i-1)*h.candleMargin+this.candleWidth/2,o=(h.maxVal-t.close)/(h.maxVal-h.minVal)*(this.option.height-this.cPadding);0===i?this.ctx.moveTo(n,o):this.ctx.lineTo(n,o),this.ctx.strokeStyle=e.color||this.BrokenLineColor,e.width&&(this.ctx.lineWidth=e.width)},i.prototype.drawCandles=function(){var t=this;if(this.ctx.beginPath(),this.ctx.setLineDash([]),h.showData.forEach((function(i,e,n){"line"===h.chartType?(t.addCandleCoordinate(i,e,n),t.drawBrokenLine(i,e,{width:3})):(t.addCandleCoordinate(i,e,n),t.drawCandle(i,e),t.drawCandlestick(i,e))})),this.ctx.stroke(),"line"===h.chartType){var i=this.originX+this.option.cPadding-Number(h.candleMargin)+this.candleWidth/2,e=this.originX+this.option.cPadding+(h.showData.length-1)*this.candleWidth+(h.showData.length-2)*h.candleMargin+this.candleWidth/2;this.ctx.lineTo(e,this.originY),this.ctx.lineTo(i,this.originY);var n=this.ctx.createLinearGradient(0,0,0,300);n.addColorStop(0,this.lineBgColorBegin),n.addColorStop(1,this.lineBgColorEnd),this.ctx.fillStyle=n,this.ctx.fill(),this.ctx.closePath()}this.ctr<this.numctr&&(this.ctr++,setTimeout((function(){t.drawChart(),t.drawRealTimeHorizon()}),this.speed))},i.prototype.drawRealTimeHorizon=function(){this.ctx.beginPath(),this.ctx.textAlign="left";var t=h.allData.length-1,i=h.allData[t],e=h.showData.length-1;this.ctx.font="20px Arial";var n,o,a=this.originX+this.option.cPadding+e*(this.candleWidth+h.candleMargin);if("line"===h.chartType?(n=this.BrokenLineColor,o=(h.maxVal-i.close)/(h.maxVal-h.minVal)*(this.option.height-2*this.cPadding)):(n=Number(i.open)>Number(i.close)?this.option.downColor:this.option.upColor,o=(h.maxVal-i.close)/(h.maxVal-h.minVal)*(this.option.height-2*this.cPadding)+this.cPadding),"left"!==this.option.yAxisDirection&&this.option.yAxisDirection){if("right"===this.option.yAxisDirection){var r=this.originX+this.option.width;this.drawLine(r,o,this.originX,o,{color:n,dottal:{x:1,y:1}}),this.ctx.stroke(),this.drawRect(r-h.yAxisLegendTextLength,o-h.TimeHorizonHeight/2,h.yAxisLegendTextLength,h.TimeHorizonHeight,{fillStyle:n}),this.ctx.fillStyle="#fff",this.ctx.textAlign="center",this.ctx.textBaseline="middle",this.ctx.fillText(i.close,r-h.yAxisLegendTextLength/2,o)}}else this.drawLine(a,o,this.originX,o,{color:n,dottal:{x:1,y:1}}),this.ctx.stroke(),this.drawRect(this.originX,o-7,50,15,{fillStyle:n}),this.ctx.fillStyle="#fff",this.ctx.fillText(i.close,this.originX+5,o+3.5)},i.prototype.addCandleCoordinate=function(t,i,e){var n=this.originX+this.option.cPadding+i*this.candleWidth+(i-1)*h.candleMargin;e[i].leftCoordinate=n.toFixed(2),e[i].leftCoordinate=Number(e[i].leftCoordinate),e[i].rightCoordinate=(n+this.candleWidth*this.ctr/this.numctr).toFixed(2),e[i].rightCoordinate=Number(e[i].rightCoordinate)},i.prototype.drawMA=function(t,i){this.ctx.beginPath();var e,n,o,a=Number(t);this.leftCandleOffset=h.allData.length-this.rightCandleOffset-this.candleNum,this.leftCandleOffset<a?(n=this.candleNum+this.leftCandleOffset,e=0,o=!0):(n=this.candleNum+a-1,e=-this.candleNum-this.rightCandleOffset-a+1,o=!1);var r=e+n;0===r&&(r=h.allData.length-1);for(var s=h.allData.slice(e,r+1),l=a-1;l<n;l++){for(var c=0,d=l-a+1;d<=l;d++)void 0===s[d].close&&console.log(s,s[d],d),c+=Number(s[d].close);var p=c/a,u=l-a+1;o&&(u=l-this.leftCandleOffset),h.showData[u]["MA"+a]=Number(p.toFixed(this.option.priceDigitnumber)),this.drawBrokenLine({open:0,high:0,low:0,close:p},u,{color:i,width:2})}this.ctx.stroke()},i.prototype.drawMAs=function(){var t=this;this.ctx.setLineDash([]),this.option.MA&&this.option.MA.length&&this.option.MA.forEach((function(i){t.drawMA(i.interval,i.color)}))},i.prototype.canvasMouseDown=function(t){"offsetX"in t&&0===this.lastClientX&&(this.lastClientX=t.offsetX)},i.prototype.canvasMouseWheel=function(t){var i=0;t.touches?(0===this.lastDiff&&(this.lastDiff=this.Pythagorean(t.touches[0],t.touches[1])),i=this.Pythagorean(t.touches[0],t.touches[1])/this.lastDiff>1?1:-1,this.lastDiff=this.Pythagorean(t.touches[0],t.touches[1])):t.wheelDelta?(i=t.wheelDelta/120,window.opera&&(i=-i)):t.detail&&(i=-t.detail/3),i&&this.chartZoom(i)},i.prototype.chartZoom=function(t){var i=Math.round(h.showDataNum/25);if(i<3&&(i=3),t<0){if(h.showDataNum>=h.allData.length)return;h.showDataNum+=i,0===this.rightCandleOffset?h.showData=h.allData.slice(-h.showDataNum):h.showData=h.allData.slice(-h.showDataNum-this.rightCandleOffset,h.allData.length-this.rightCandleOffset),this.candleNum=h.showData.length,this.candleWidth=(this.option.width-this.chartRightPadding-(3*this.cPadding-h.candleMargin)-h.candleMargin*(this.candleNum-1))/this.candleNum,this.drawChart()}else{if(h.showDataNum<=13)return;h.showDataNum-=i,h.showData=h.allData.slice(-h.showDataNum-this.rightCandleOffset,h.allData.length-this.rightCandleOffset),0===this.rightCandleOffset&&(h.showData=h.allData.slice(-h.showDataNum)),this.candleNum=h.showData.length,this.candleWidth=(this.option.width-this.chartRightPadding-(3*this.cPadding-h.candleMargin)-h.candleMargin*(this.candleNum-1))/this.candleNum,this.drawChart()}},i.prototype.canvasMouseMove=function(t){return f(this,void 0,void 0,(function(){var i,e;return g(this,(function(n){switch(n.label){case 0:return(e=parseInt(String(h.showData.length/50)))<1&&(e=1),i=t.touches?t.touches[0].clientX:t.clientX,this.lastClientX<i?(this.rightCandleOffset+=e,this.rightCandleOffset>=h.allData.length-this.candleNum&&(this.rightCandleOffset=h.allData.length-this.candleNum)):this.lastClientX>i&&(this.rightCandleOffset-=e,this.rightCandleOffset<=0&&(this.rightCandleOffset=0)),h.showData=h.allData.slice(-this.candleNum-this.rightCandleOffset,h.allData.length-this.rightCandleOffset),this.lastClientX=i,this.leftCandleOffset=h.allData.length-this.rightCandleOffset-this.candleNum,[4,this.loadMoreData()];case 1:return n.sent(),this.drawChart(),[2]}}))}))},i.prototype.loadMoreData=function(){return f(this,void 0,void 0,(function(){var t,i;return g(this,(function(e){switch(e.label){case 0:return this.leftCandleOffset||this.loadMore||!this.option.loadMoreCallback?[3,2]:(this.loadMore=!0,[4,this.option.loadMoreCallback()]);case 1:if(0===(t=e.sent()).length)return[2];this.addStatus(t),(i=h.allData).unshift.apply(i,C(t)),this.formatData(),this.loadMore=!1,e.label=2;case 2:return[2]}}))}))},i.prototype.updateLastCandle=function(t,i,e,n){if(i)e>n.high?(h.allData[h.allData.length-1].high=e,h.allData[h.allData.length-1].close=e):e<n.low?(h.allData[h.allData.length-1].low=e,h.allData[h.allData.length-1].close=e):h.allData[h.allData.length-1].close=e,h.allData[h.allData.length-1].status=h.allData[h.allData.length-1].close>h.allData[h.allData.length-1].open?r.up:r.down;else{var o=h.allData[h.allData.length-1].close,a={open:o,low:o<e?o:e,close:e,high:o>e?o:e,time:t,formatedTime:this.dateFormat(this.formatTimeRule(),new Date(Date.now()))};h.allData.push(a),0===this.rightCandleOffset?h.showData=h.allData.slice(-this.candleNum):this.rightCandleOffset++}},i.prototype.timeCheck=function(t,i){if(this.option.timeCheckErrorHandler){var e=Math.abs(new Date(i).getMinutes()-new Date(t).getMinutes());switch(this.option.interval){case"1m":e>1&&this.option.timeCheckErrorHandler(e-1);break;case"5m":e>5&&this.option.timeCheckErrorHandler(e-5);break;case"15m":e>15&&this.option.timeCheckErrorHandler(e-15);break;case"30m":e>30&&this.option.timeCheckErrorHandler(e-30);break;case"60m":e>60&&this.option.timeCheckErrorHandler(e-60);break;case"1d":e>1440&&this.option.timeCheckErrorHandler(e-1440)}}},i.prototype.subscribeBars=function(t,i){return f(this,void 0,void 0,(function(){var e,n,o,a,r,s,l,c;return g(this,(function(d){return t=Number(t),e=h.allData[h.allData.length-1],n=new Date(Number(e.time)),o=Number(this.dateFormat("M",n)),a=Number(this.dateFormat("H",n)),r=Number(this.dateFormat("d",n)),s=Number(this.dateFormat("d",new Date(t))),l=Number(this.dateFormat("M",new Date(t))),c=Number(this.dateFormat("H",new Date(t))),this.timeCheck(n.getTime(),t),"1m"===this.option.interval?this.updateLastCandle(t,l===o,i,e):"5m"===this.option.interval?this.updateLastCandle(t,Math.abs(l-o)<=5||55===Math.abs(l-o),i,e):"15m"===this.option.interval?this.updateLastCandle(t,Math.abs(l-o)<=15||45===Math.abs(l-o),i,e):"30m"===this.option.interval?this.updateLastCandle(t,Math.abs(l-o)<=30,i,e):"60m"===this.option.interval?this.updateLastCandle(t,c===a,i,e):"1d"===this.option.interval&&this.updateLastCandle(t,r===s,i,e),this.quotePanel.updateCurCandleInfo(),this.drawChart(),[2]}))}))},i}(h),y=0,w=function(){function t(t,i,e,n,o,a,r,h,s){this.container=t,this.originX=i,this.width=e,this.height=n,this.cPadding=o,this.chartRightPadding=a,this.brokenLineColor=r,this.markerList=[],this.purchaseTime=h.purchaseTime,this.deliveryTime=h.deliveryTime,this.option=s,this.createInfoElement(this.container)}return t.prototype.createInfoElement=function(t){var i=document.getElementById("infoContainer");i||((i=s("div")).id="infoContainer"),this.drawQuoteLine(i),t.appendChild(i)},t.prototype.getQuoteLineCoordinate=function(){var t=h.allData.length-1,i=h.allData[t];return{x:this.originX+this.width-this.chartRightPadding,y:(h.maxVal-i.close)/(h.maxVal-h.minVal)*(this.height-2*this.cPadding),time:i.time}},t.prototype.getPrice=function(){var t=h.allData.length-1;return h.allData[t].close},t.prototype.drawQuoteLine=function(t){this.quoteLine=s("div",{id:"quoteLine"}),this.quoteRect=s("div",{id:"quoteRect"}),this.quoteSpan=s("span",{id:"quoteSpan"}),this.quoteDot=s("i",{id:"quoteDot"});var i=this.getQuoteLineCoordinate(),e=i.x,n=i.y,o=this.getPrice();l(this.quoteLine,{width:this.chartRightPadding/2+"px",top:n/2+"px",left:e/2+"px",backgroundImage:"linear-gradient(\n to right,\n "+this.brokenLineColor+" 0%,\n "+this.brokenLineColor+" 50%,\n transparent 50%\n )"}),l(this.quoteDot,{top:n/2+"px",left:e/2-10+"px",backgroundColor:this.brokenLineColor}),l(this.quoteRect,{width:h.yAxisLegendTextLength/2+"px",height:h.TimeHorizonHeight/2+"px",top:(n-h.TimeHorizonHeight/2)/2+"px",left:(this.width-h.yAxisLegendTextLength)/2+"px",backgroundColor:this.brokenLineColor}),l(this.quoteSpan,{top:n/2+"px",left:(this.width-h.yAxisLegendTextLength/2)/2+"px"}),this.quoteSpan.innerHTML=o.toString(),t.appendChild(this.quoteLine),t.appendChild(this.quoteDot),t.appendChild(this.quoteRect),t.appendChild(this.quoteSpan)},t.prototype.update=function(){this.updateQuoteLine(),this.updateMarkers()},t.prototype.updateQuoteLine=function(){var t=this.getQuoteLineCoordinate(),i=t.x,e=t.y,n=this.getPrice();l(this.quoteLine,{width:this.chartRightPadding/2+"px",top:e/2+"px",left:i/2+"px"}),l(this.quoteDot,{top:e/2+"px",left:i/2-5+"px"}),l(this.quoteRect,{width:h.yAxisLegendTextLength/2+"px",height:h.TimeHorizonHeight/2+"px",top:(e-h.TimeHorizonHeight/2)/2+"px",left:(this.width-h.yAxisLegendTextLength)/2+"px"}),this.quoteSpan.innerHTML=n.toString(),l(this.quoteSpan,{top:e/2+"px",left:(this.width-h.yAxisLegendTextLength/2)/2+"px"})},t.prototype.mark=function(t){var i=this.getQuoteLineCoordinate(),e=i.x,n=i.y,o=i.time,a=s("mark"),r=s("div",{className:"round"}),h=s("div",{className:"rect"}),l=s("div",{className:"markPriceLine"}),c=s("span",{className:"markPriceSpan"});a.appendChild(r),a.appendChild(h),a.appendChild(l),a.appendChild(c);var d={id:y++,price:this.getPrice(),x:e,y:n,el:a,createTime:o,children:{round:r,rect:h,markPriceLine:l,markPriceSpan:c},type:t};this.setMarkerStyle(d),this.markerList.push(d),this.patchMarker(d)},t.prototype.setMarkerStyle=function(t){var i=t.type===r.down?this.option.downColor:this.option.upColor;l(t.el,{left:t.x/2+"px",top:t.y/2+"px"}),l(t.children.round,{backgroundColor:i}),l(t.children.rect,{backgroundColor:i}),l(t.children.markPriceSpan,{backgroundColor:i,width:h.yAxisLegendTextLength/2+"px",height:h.TimeHorizonHeight/2+"px",left:(this.option.width-t.x)/2+"px"}),t.children.markPriceSpan.innerHTML=t.price.toString(),l(t.children.markPriceLine,{width:(this.option.width-t.x)/2+"px",backgroundImage:"linear-gradient(\n to right,\n "+i+" 0%,\n "+i+" 50%,\n transparent 50%\n )"})},t.prototype.updateMarkers=function(){var t=this;this.markerList.length&&this.markerList.forEach((function(i,e,n){var o=t.fetchMarkerCoordinate(n[e]),a=o.x,r=o.y;n[e].x=a,n[e].y=r,t.setMarkerStyle(n[e])}))},t.prototype.fetchMarkerCoordinate=function(t){var i=h.showData.find((function(i){return i.time===t.createTime})),e=0,n=(h.maxVal-t.price)/(h.maxVal-h.minVal)*(this.height-2*this.cPadding);return i&&i.leftCoordinate&&i.rightCoordinate&&(e=i.leftCoordinate),{x:e,y:n}},t.prototype.patchMarker=function(t){this.markContainer||(this.markContainer=s("div"),this.markContainer.id="markContainer",this.container.appendChild(this.markContainer)),l(t.el,{left:t.x/2+"px",top:t.y/2+"px"}),this.markContainer.appendChild(t.el)},t.prototype.flushMarker=function(){this.markContainer&&(this.markContainer.innerHTML=""),this.markerList=[]},t}(),v=function(){var t=function(i,e){return(t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,i){t.__proto__=i}||function(t,i){for(var e in i)Object.prototype.hasOwnProperty.call(i,e)&&(t[e]=i[e])})(i,e)};return function(i,e){function n(){this.constructor=i}t(i,e),i.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)}}(),b=function(t,i,e,n){return new(e||(e=Promise))((function(o,a){function r(t){try{s(n.next(t))}catch(t){a(t)}}function h(t){try{s(n.throw(t))}catch(t){a(t)}}function s(t){var i;t.done?o(t.value):(i=t.value,i instanceof e?i:new e((function(t){t(i)}))).then(r,h)}s((n=n.apply(t,i||[])).next())}))},D=function(t,i){var e,n,o,a,r={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return a={next:h(0),throw:h(1),return:h(2)},"function"==typeof Symbol&&(a[Symbol.iterator]=function(){return this}),a;function h(a){return function(h){return function(a){if(e)throw new TypeError("Generator is already executing.");for(;r;)try{if(e=1,n&&(o=2&a[0]?n.return:a[0]?n.throw||((o=n.return)&&o.call(n),0):n.next)&&!(o=o.call(n,a[1])).done)return o;switch(n=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return r.label++,{value:a[1],done:!1};case 5:r.label++,n=a[1],a=[0];continue;case 7:a=r.ops.pop(),r.trys.pop();continue;default:if(!(o=r.trys,(o=o.length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){r=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){r.label=a[1];break}if(6===a[0]&&r.label<o[1]){r.label=o[1],o=a;break}if(o&&r.label<o[2]){r.label=o[2],r.ops.push(a);break}o[2]&&r.ops.pop(),r.trys.pop();continue}a=i.call(t,r)}catch(t){a=[6,t],n=0}finally{e=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,h])}}},M=function(t){function i(i,e){var n=t.call(this,i,e)||this;return n.container=i,n.createCanvasElement(i),n.ctx=n.canvas.getContext("2d"),n.lineBgColorBegin=n.option.lineBgColorBegin||"rgba(133,171,212,0.6)",n.lineBgColorEnd=n.option.lineBgColorEnd||"rgba(133,171,212,0.1)",n.BrokenLineColor=n.option.BrokenLineColor||"#3696F3",n.yLegendNum=10,h.legendYMargin=(n.option.height-4*n.option.cPadding)/(n.yLegendNum-1),n.xLegendNum=4,n.lastClientX=0,n.rightCandleOffset=0,n.leftCandleOffset=0,n.chartRightPadding="mobile"===n.option.mode?.15*n.option.width:.3*n.option.width,n.formatData(),h.showData=h.allData.slice(-200),n.candleNum=h.showData.length,n.candleWidth=(n.option.width-n.chartRightPadding-(3*n.cPadding-h.candleMargin)-h.candleMargin*(n.candleNum-1))/n.candleNum,n.ctx.font="24px Arial",n.ctx.textAlign="end",n.optionPanel=new w(n.container,n.originX,n.option.width,n.option.height,n.cPadding,n.chartRightPadding,n.BrokenLineColor,n.option.optionConf,n.option),n.drawChart(),n}return v(i,t),i.prototype.createCanvasElement=function(t){this.canvas=s("canvas"),this.canvas.height=this.option.height,this.canvas.width=this.option.width,this.canvas.style.width=this.option.originalWidth+"px",this.canvas.style.height=this.option.originalHeight+"px",t.appendChild(this.canvas)},i.prototype.formatData=function(){var t=this;h.allData.forEach((function(i,e,n){n[e].formatedTime=t.dateFormat("mm-dd HH:MM:SS",new Date(Number(i.time)))}))},i.prototype.drawChart=function(){this.clearCanvas(),this.getYlegend(),this.drawCandles(),this.drawAxis(),this.optionPanel.update()},i.prototype.getYlegend=function(){h.maxVal=0,h.minVal=9999999,h.showData.forEach((function(t){t.high>h.maxVal&&(h.maxVal=Number(t.high)),t.low<h.minVal&&(h.minVal=Number(t.low))}));var t=h.maxVal-h.minVal;h.maxVal+=.15*t,h.minVal-=.05*t,h.yAxisLegendTextLength=12*h.maxVal.toFixed(this.option.priceDigitnumber).length},i.prototype.drawAxis=function(){this.drawLine(this.originX,this.originY,this.option.width-this.option.cPadding,this.originY,{color:this.option.axisColor}),this.drawLine(this.originX,this.originY,this.originX,this.option.cPadding,{color:this.option.axisColor}),this.drawYAxis(),this.drawXAxis()},i.prototype.drawYAxis=function(){this.ctx.beginPath();var t=(h.maxVal-h.minVal)/(this.yLegendNum-1);this.ctx.fillStyle=this.option.legendColor;for(var i=0;i<this.yLegendNum;i++){var e=this.originY-h.tHeight-h.legendYMargin*i,n=(h.minVal+i*t).toFixed(this.option.priceDigitnumber);this.ctx.font="20px Arial","left"!==this.option.yAxisDirection&&this.option.yAxisDirection?"right"===this.option.yAxisDirection&&(this.ctx.textBaseline="top",this.ctx.textAlign="right",this.ctx.fillText(n,this.option.width-this.option.cPadding,e)):this.ctx.fillText(n,this.originX,e),this.ctx.textBaseline="alphabetic"}},i.prototype.drawXAxis=function(){var t=Math.round(h.showData.length/this.xLegendNum)+1;this.ctx.textAlign="left";for(var i=0;i<h.showData.length;i+=t){var e=h.showData[i];e.formatedTime&&this.ctx.fillText(e.formatedTime,e.leftCoordinate+(e.rightCoordinate-e.leftCoordinate)/2,this.option.height-this.option.cPadding)}},i.prototype.drawCandlestick=function(t,i){this.ctx.beginPath(),this.ctx.lineWidth=3;var e=this.originX+this.option.cPadding+i*this.candleWidth+(i-1)*h.candleMargin+this.candleWidth/2,n=(h.maxVal-t.high)/(h.maxVal-h.minVal)*(this.option.height-this.option.cPadding),o=(h.maxVal-t.low)/(h.maxVal-h.minVal)*(this.option.height-this.option.cPadding);t.open>t.close?this.drawLine(e,n,e,o,{color:this.option.downColor,width:3}):this.drawLine(e,n,e,o,{color:this.option.upColor,width:3}),this.ctx.stroke()},i.prototype.drawCandle=function(t,i){var e,n,o=this.originX+this.option.cPadding+i*this.candleWidth+(i-1)*h.candleMargin;t.open>t.close?(n=(t.open-t.close)/(h.maxVal-h.minVal)*(this.option.height-this.option.cPadding),e=(h.maxVal-t.open)/(h.maxVal-h.minVal)*(this.option.height-this.option.cPadding),this.drawRect(o,e,this.candleWidth,n,{fillStyle:this.option.downColor})):(n=(t.close-t.open)/(h.maxVal-h.minVal)*(this.option.height-this.option.cPadding),e=(h.maxVal-t.close)/(h.maxVal-h.minVal)*(this.option.height-this.option.cPadding),this.drawRect(o,e,this.candleWidth,n,{fillStyle:this.option.upColor}))},i.prototype.drawBrokenLine=function(t,i,e){void 0===e&&(e={});var n=this.originX+this.option.cPadding+i*this.candleWidth+(i-1)*h.candleMargin+this.candleWidth/2,o=(h.maxVal-t.close)/(h.maxVal-h.minVal)*(this.option.height-this.cPadding);0===i?this.ctx.moveTo(n,o):this.ctx.lineTo(n,o),this.ctx.strokeStyle=e.color||this.BrokenLineColor,e.width&&(this.ctx.lineWidth=e.width)},i.prototype.drawCandles=function(){var t=this;if(this.ctx.beginPath(),this.ctx.setLineDash([]),h.showData.forEach((function(i,e,n){"line"===h.chartType?(t.addCandleCoordinate(i,e,n),t.drawBrokenLine(i,e,{width:3})):(t.addCandleCoordinate(i,e,n),t.drawCandle(i,e),t.drawCandlestick(i,e))})),this.ctx.stroke(),"line"===h.chartType){var i=this.originX+this.option.cPadding-Number(h.candleMargin)+this.candleWidth/2,e=this.originX+this.option.cPadding+(h.showData.length-1)*this.candleWidth+(h.showData.length-2)*h.candleMargin+this.candleWidth/2;this.ctx.lineTo(e,this.originY),this.ctx.lineTo(i,this.originY);var n=this.ctx.createLinearGradient(0,0,0,300);n.addColorStop(0,this.lineBgColorBegin),n.addColorStop(1,this.lineBgColorEnd),this.ctx.fillStyle=n,this.ctx.fill(),this.ctx.closePath()}},i.prototype.addCandleCoordinate=function(t,i,e){var n=this.originX+this.option.cPadding+i*this.candleWidth+(i-1)*h.candleMargin;e[i].leftCoordinate=Number(n.toFixed(2)),e[i].leftCoordinate=Number(e[i].leftCoordinate),e[i].rightCoordinate=Number((n+this.candleWidth).toFixed(2)),e[i].rightCoordinate=Number(e[i].rightCoordinate)},i.prototype.canvasMouseDown=function(){},i.prototype.canvasMouseWheel=function(){},i.prototype.canvasMouseMove=function(){},i.prototype.updateLastCandle=function(t,i){var e=h.allData[h.allData.length-1].close,n={open:e,low:e<i?e:i,close:i,high:e>i?e:i,time:t,formatedTime:this.dateFormat("mm-dd HH:MM:SS",new Date(Date.now()))};h.allData.push(n),0===this.rightCandleOffset?h.showData=h.allData.slice(-this.candleNum):this.rightCandleOffset++},i.prototype.timeCheck=function(t,i){if(this.option.timeCheckErrorHandler){var e=Math.abs(new Date(i).getMinutes()-new Date(t).getMinutes());switch(this.option.interval){case"1m":e>1&&this.option.timeCheckErrorHandler(e-1);break;case"5m":e>5&&this.option.timeCheckErrorHandler(e-5);break;case"15m":e>15&&this.option.timeCheckErrorHandler(e-15);break;case"30m":e>30&&this.option.timeCheckErrorHandler(e-30);break;case"60m":e>60&&this.option.timeCheckErrorHandler(e-60);break;case"1d":e>1440&&this.option.timeCheckErrorHandler(e-1440)}}},i.prototype.subscribeBars=function(t,i){return b(this,void 0,void 0,(function(){var e,n;return D(this,(function(o){return t=Number(t),e=h.allData[h.allData.length-1],n=new Date(Number(e.time)),this.timeCheck(n.getTime(),t),this.updateLastCandle(t,i),this.drawChart(),[2]}))}))},i.prototype.mark=function(t){this.optionPanel.mark(t)},i}(h),A=function(){var t=function(i,e){return(t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,i){t.__proto__=i}||function(t,i){for(var e in i)Object.prototype.hasOwnProperty.call(i,e)&&(t[e]=i[e])})(i,e)};return function(i,e){function n(){this.constructor=i}t(i,e),i.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)}}(),L=function(t){function i(i,e){var n=t.call(this,i,e)||this;return n.option=e,n.createCanvasElement(i),n.ctx=n.canvas.getContext("2d"),n.quotePanel=new p(n.container,e),n}return A(i,t),i.prototype.createCanvasElement=function(t){this.canvas=s("canvas"),this.canvas.height=this.option.height,this.canvas.width=this.option.width,this.canvas.style.width=this.option.originalWidth+"px",this.canvas.style.height=this.option.originalHeight+"px",this.canvas.style.position="absolute",this.canvas.style.top="0",this.canvas.style.left="0",this.canvas.style.zIndex="10",t.appendChild(this.canvas)},i.prototype.canvasMouseMove=function(t,i){void 0===i&&(i=!0),this.clearCanvas();var e,n,o=0,a=0;t.offsetX?(e=t.offsetX,n=t.offsetY):(e=t.touches[0].clientX,n=t.touches[0].clientY-this.container.getBoundingClientRect().y);for(var r=0;r<h.showData.length;r++){var s=h.showData[r];2*e<s.rightCoordinate&&2*e>=s.leftCoordinate-h.candleMargin&&(o=(s.rightCoordinate/2-s.leftCoordinate/2)/2+s.leftCoordinate/2,a=n)}a>=5&&a<=this.container.clientHeight-10&&this.drawCrossAxis(2*o,2*a)},i.prototype.canvasMouseDown=function(t){this.clearCanvas();for(var i=0,e=0,n=0;n<h.showData.length;n++){var o=h.showData[n],a=void 0,r=void 0;a="touches"in t?t.touches[0].clientX:t.offsetX,r="touches"in t?t.touches[0].clientY-this.container.getBoundingClientRect().y:t.offsetY,2*a<o.rightCoordinate&&2*a>=o.leftCoordinate-h.candleMargin&&(i=(o.rightCoordinate/2-o.leftCoordinate/2)/2+o.leftCoordinate/2,e=r)}this.findCurCandle(2*i),e>=5&&e<=this.container.clientHeight-10&&this.drawCrossAxis(2*i,2*e),this.drawCurCandleBg(null!=document.getElementById("curCandleOHLCInfoContainer"))},i.prototype.drawCrossAxis=function(t,i){"pc"===this.option.mode&&(this.clearCanvas(),this.findCurCandle(t),this.drawCurCandleBg(null!=document.getElementById("curCandleOHLCInfoContainer"))),this.drawLine(0,i,this.option.width,i,{dottal:{x:5,y:5},color:"#fff",width:1}),"line"===h.chartType&&this.drawLine(t,0,t,this.option.height,{dottal:{x:5,y:5},color:"#fff",width:1}),this.ctx.stroke(),this.drawXLegend(t),this.drawYLegend(i)},i.prototype.drawXLegend=function(t){if(h.curCandle){var i=this.dateFormat("dd-mm-YYYY HH:MM",new Date(Number(h.curCandle.time))),e=12*i.length,n=this.option.height-this.cPadding-h.TimeHorizonHeight;this.drawRect(t-e/2,n,e,h.TimeHorizonHeight,{fillStyle:"#5e606d"}),this.ctx.font="20px Arial",this.ctx.fillStyle="#fff",this.ctx.textAlign="center",this.ctx.textBaseline="middle",this.ctx.fillText(i,t,this.option.height-this.cPadding-h.TimeHorizonHeight/2)}},i.prototype.drawYLegend=function(t){var i=this.originX+this.option.width,e=h.maxVal-h.minVal,n=this.option.height-2*this.cPadding,o=(h.maxVal-t*e/n).toFixed(this.option.priceDigitnumber);this.drawRect(i-h.yAxisLegendTextLength,t-h.TimeHorizonHeight/2,h.yAxisLegendTextLength,h.TimeHorizonHeight,{fillStyle:"#5e606d"}),this.ctx.font="20px Arial",this.ctx.fillStyle="#fff",this.ctx.textAlign="center",this.ctx.textBaseline="middle",this.ctx.fillText(o,i-h.yAxisLegendTextLength/2,t)},i.prototype.drawCurCandleBg=function(t){if("candle"===h.chartType&&t&&h.curCandle.leftCoordinate){var i=this.ctx.createLinearGradient(h.curCandle.leftCoordinate,0,h.curCandle.leftCoordinate,this.option.height-this.cPadding);i.addColorStop(0,"rgba(0,0,0,0.2)"),i.addColorStop(.5,"rgba(255,255,255,0.2)"),i.addColorStop(1,"rgba(0,0,0,0.2)"),this.drawRect(h.curCandle.leftCoordinate,0,h.curCandle.rightCoordinate-h.curCandle.leftCoordinate,this.option.height-this.cPadding,{fillStyle:i})}},i.prototype.findCurCandle=function(t){h.isTimeToUpdateCurCandle=!0;for(var i=0;i<h.showData.length;i++){var e=h.showData[i];if(t<e.rightCoordinate&&t>=e.leftCoordinate-h.candleMargin){i!==h.showData.length-1&&(h.isTimeToUpdateCurCandle=!1),i<h.showData.length/2?h.infoContainerPosition=a.right:h.infoContainerPosition=a.left,("pc"===this.option.mode&&h.curCandle&&h.curCandle.time!==e.time||"mobile"===this.option.mode)&&(h.curCandle=e,"candle"===h.chartType&&(this.quotePanel.drawCurCandleOHLCInfo(),this.quotePanel.drawCurCandleMAInfo()));break}}this.quotePanel.updateCurCandleInfo()},i}(h);!function(t){t.quote="quote",t.option="option"}(d||(d={}));var P=d,k=function(){return(k=Object.assign||function(t){for(var i,e=1,n=arguments.length;e<n;e++)for(var o in i=arguments[e])Object.prototype.hasOwnProperty.call(i,o)&&(t[o]=i[o]);return t}).apply(this,arguments)},T=function(t,i,e,n){return new(e||(e=Promise))((function(o,a){function r(t){try{s(n.next(t))}catch(t){a(t)}}function h(t){try{s(n.throw(t))}catch(t){a(t)}}function s(t){var i;t.done?o(t.value):(i=t.value,i instanceof e?i:new e((function(t){t(i)}))).then(r,h)}s((n=n.apply(t,i||[])).next())}))},O=function(t,i){var e,n,o,a,r={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return a={next:h(0),throw:h(1),return:h(2)},"function"==typeof Symbol&&(a[Symbol.iterator]=function(){return this}),a;function h(a){return function(h){return function(a){if(e)throw new TypeError("Generator is already executing.");for(;r;)try{if(e=1,n&&(o=2&a[0]?n.return:a[0]?n.throw||((o=n.return)&&o.call(n),0):n.next)&&!(o=o.call(n,a[1])).done)return o;switch(n=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return r.label++,{value:a[1],done:!1};case 5:r.label++,n=a[1],a=[0];continue;case 7:a=r.ops.pop(),r.trys.pop();continue;default:if(!(o=r.trys,(o=o.length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){r=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){r.label=a[1];break}if(6===a[0]&&r.label<o[1]){r.label=o[1],o=a;break}if(o&&r.label<o[2]){r.label=o[2],r.ops.push(a);break}o[2]&&r.ops.pop(),r.trys.pop();continue}a=i.call(t,r)}catch(t){a=[6,t],n=0}finally{e=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,h])}}},N=function(){function t(t){this.initOption(t),this.addStatus(this.option.data),this.patchChart()}return t.prototype.initOption=function(t){this.mergeOption(t),this.initOptionFun(t)},t.prototype.mergeOption=function(t){var i=JSON.parse(JSON.stringify(t)),e=k({width:2*i.originalWidth,height:2*i.originalHeight},i);this.option=e},t.prototype.initOptionFun=function(t){for(var i=Object.keys(t),e=0;e<i.length;e++){var n=i[e],o=t[n];"function"==typeof o&&(this.option[n]=o)}},t.prototype.patchChart=function(){if(null===document.getElementById(this.option.container))throw new Error("container not found");switch(this.container=document.getElementById(this.option.container),this.container.className="__tcContainer__",this.container.style.position="relative",this.container.style.cursor="crosshair",this.container.innerHTML="",this.cursorChart=new L(this.container,this.option),this.option.chartSeries){case P.quote:this.mainChart=new x(this.container,this.option);break;case P.option:this.mainChart=new M(this.container,this.option);break;default:this.mainChart=new x(this.container,this.option)}this.bindEvents(),this.cursorChart.drawLogo()},t.prototype.subscribeBars=function(t,i){return T(this,void 0,void 0,(function(){return O(this,(function(e){switch(e.label){case 0:return[4,this.mainChart.subscribeBars(t,i)];case 1:return e.sent(),[2]}}))}))},t.prototype.addStatus=function(t){t.forEach((function(t,i,e){t.open>t.close?e[i].status=r.down:e[i].status=r.up}))},t.prototype.bindEvents=function(){"mobile"===this.option.mode?this.container.ontouchstart=this.canvasMouseDown.bind(this):this.container.onmousedown=this.canvasMouseDown.bind(this),this.container.onmousewheel=this.canvasMouseWheel.bind(this),this.container.addEventListener("DOMMouseScroll",this.canvasMouseWheel.bind(this),!1),"pc"===this.option.mode&&(this.container.onmousemove=this.cursorChart.canvasMouseMove.bind(this.cursorChart))},t.prototype.canvasMouseDown=function(t){this.container.style.cursor="move",this.cursorChart.canvasMouseDown(t),this.mainChart.canvasMouseDown(t),"pc"===this.option.mode?(this.container.onmousemove=this.canvasMouseMove.bind(this),this.container.onmouseup=this.canvasMouseUp.bind(this)):(this.container.ontouchmove=this.canvasMouseMove.bind(this),this.container.ontouchend=this.canvasMouseUp.bind(this))},t.prototype.canvasMouseMove=function(t){return T(this,void 0,void 0,(function(){return O(this,(function(i){switch(i.label){case 0:return t.touches&&t.touches.length>1&&this.canvasMouseWheel(t),t.touches&&1===t.touches.length?(this.cursorChart.canvasMouseMove(t),[4,this.mainChart.canvasMouseMove(t)]):[3,2];case 1:i.sent(),i.label=2;case 2:return"pc"!==this.option.mode?[3,4]:(this.cursorChart.canvasMouseMove(t),[4,this.mainChart.canvasMouseMove(t)]);case 3:i.sent(),i.label=4;case 4:return[2]}}))}))},t.prototype.canvasMouseWheel=function(t){this.mainChart.canvasMouseWheel(t),this.cursorChart.canvasMouseWheel(t)},t.prototype.canvasMouseUp=function(t){this.mainChart.canvasMouseUp(t),this.cursorChart.canvasMouseUp(t),this.container.onmousemove=null,this.container.ontouchmove=null,this.container.onmouseup=null,this.container.ontouchend=null,"pc"===this.option.mode&&(this.container.onmousemove=this.cursorChart.canvasMouseMove.bind(this.cursorChart)),this.container.style.cursor="crosshair"},t.prototype.mark=function(t){this.mainChart instanceof M&&this.mainChart.mark(t)},t}();i.default=N}])})); |
{ | ||
"name": "trade-chart.js", | ||
"version": "1.0.4", | ||
"version": "1.0.5", | ||
"description": "一个交易图表插件,支持分时图,蜡烛图,二元期权", | ||
"main": "dist/index.js", | ||
"scripts": { | ||
"build": "webpack --mode production" | ||
}, | ||
"keywords": [ | ||
@@ -10,0 +7,0 @@ "chart", |
@@ -1,20 +0,15 @@ | ||
# TradeChart 文档 | ||
# trade-chart.js 文档 | ||
一个轻量级的交易图表,基于 canvas 搭建,支持基础 K 线:分时图,蜡烛图,支持二元期权图表 | ||
## 引入 | ||
``` | ||
```javascript | ||
import TradeChart from 'trade-chart.js'; | ||
import 'trade-chart.js/dist/built.css' | ||
import 'trade-chart.js/dist/built.css'; | ||
``` | ||
或者 | ||
``` | ||
<script src="trade-chart.js"></script> | ||
<link href="trade-chart.js/dist/built.css" rel="stylesheet" /> | ||
``` | ||
## 使用 | ||
``` | ||
```javascript | ||
const chart = new TradeChart(option); | ||
@@ -21,0 +16,0 @@ ``` |
@@ -6,2 +6,3 @@ import Candle from './interface/Candle'; | ||
import CandleStatus from './enum/CandleStatus'; | ||
/** | ||
@@ -8,0 +9,0 @@ * @description 图表基类 |
@@ -6,4 +6,5 @@ /** | ||
export default interface OptionConf { | ||
purchaseTime: number; //购买时间 | ||
deliveryTime: number; //交割时间 | ||
purchaseTime: number; //购买时间 单位为秒 | ||
deliveryTime: number; //交割时间 单位为秒 | ||
startMin: number; //第一盘开始的时间 单位为分钟 | ||
} |
@@ -33,4 +33,6 @@ import ChartMode from '../enum/ChartMode'; | ||
timeCheckErrorHandler?: (diffTime: number) => {}; | ||
markFailHandler?: () => {}; | ||
deliveringCallback?: (remaining: number) => {}; | ||
} | ||
export default UserOption; |
@@ -10,8 +10,7 @@ import BaseChart from '../BaseChart'; | ||
/** | ||
* @description 主要图表类 | ||
* @description 二元期权图表类 | ||
* @author 抓住一股仙气 <1013697816@qq.com> HtwoO <1549914423@qq.com> | ||
* @Date 2020/11/09 | ||
* @version 3.1 | ||
* @Date 2021/03/01 | ||
* @version 1.0 | ||
*/ | ||
class OptionChart extends BaseChart implements Chart { | ||
@@ -42,2 +41,3 @@ // 线性背景开始颜色 | ||
optionPanel: OptionPanel; | ||
lastDiff = 0; | ||
@@ -51,4 +51,4 @@ constructor(container: HTMLElement, option: _Option) { | ||
this.lineBgColorBegin = | ||
this.option.lineBgColorBegin || 'rgba(133,171,212,0.6)'; | ||
this.lineBgColorEnd = this.option.lineBgColorEnd || 'rgba(133,171,212,0.1)'; | ||
this.option.lineBgColorBegin || 'rgba(36,145,227,0.6)'; | ||
this.lineBgColorEnd = this.option.lineBgColorEnd || 'rgba(36,145,227,0.2)'; | ||
this.BrokenLineColor = this.option.BrokenLineColor || '#3696F3'; | ||
@@ -59,3 +59,3 @@ | ||
(this.option.height - 4 * this.option.cPadding) / (this.yLegendNum - 1); //每个间距 | ||
this.xLegendNum = 4; | ||
this.xLegendNum = 7; | ||
this.lastClientX = 0; | ||
@@ -86,8 +86,5 @@ this.rightCandleOffset = 0; | ||
this.originX, | ||
this.option.width, | ||
this.option.height, | ||
this.cPadding, | ||
this.chartRightPadding, | ||
this.BrokenLineColor, | ||
this.option.optionConf, | ||
this.option | ||
@@ -114,3 +111,3 @@ ); | ||
arr[index].formatedTime = this.dateFormat( | ||
'mm-dd HH:MM:SS', | ||
'MM:SS', | ||
new Date(Number(item.time)) | ||
@@ -308,2 +305,3 @@ ); | ||
(this.option.height - this.cPadding); | ||
if (index === 0) { | ||
@@ -324,12 +322,14 @@ this.ctx.moveTo(x, y); | ||
this.ctx.setLineDash([]); | ||
BaseChart.showData.forEach((item, index, arr) => { | ||
for (let index = 0; index < BaseChart.showData.length; index++) { | ||
const item = BaseChart.showData[index]; | ||
if (BaseChart.chartType === 'line') { | ||
this.addCandleCoordinate(item, index, arr); | ||
this.addCandleCoordinate(item, index, BaseChart.showData); | ||
this.drawBrokenLine(item, index, { width: 3 }); | ||
} else { | ||
this.addCandleCoordinate(item, index, arr); | ||
this.addCandleCoordinate(item, index, BaseChart.showData); | ||
this.drawCandle(item, index); | ||
this.drawCandlestick(item, index); | ||
} | ||
}); | ||
} | ||
@@ -352,3 +352,2 @@ this.ctx.stroke(); | ||
this.ctx.lineTo(firstCandleX, this.originY); | ||
//背景渐变色 | ||
@@ -380,11 +379,126 @@ let gradient = this.ctx.createLinearGradient(0, 0, 0, 300); | ||
//点击 | ||
canvasMouseDown() {} | ||
//监听拖拽 | ||
canvasMouseDown(e: MouseEvent | TouchEvent) { | ||
if ('offsetX' in e && this.lastClientX === 0) { | ||
this.lastClientX = e.offsetX; | ||
} | ||
} | ||
//滚轮 | ||
canvasMouseWheel() {} | ||
canvasMouseWheel(event: any) { | ||
let delta = 0; | ||
if (!event.touches) { | ||
if (event.wheelDelta) { | ||
//IE、chrome浏览器使用的是wheelDelta,并且值为“正负120” | ||
delta = event.wheelDelta / 120; | ||
if (window.opera) delta = -delta; //因为IE、chrome等向下滚动是负值,FF是正值,为了处理一致性,在此取反处理 | ||
} else if (event.detail) { | ||
//FF浏览器使用的是detail,其值为“正负3” | ||
delta = -event.detail / 3; | ||
} | ||
} else { | ||
if (this.lastDiff === 0) { | ||
this.lastDiff = this.Pythagorean(event.touches[0], event.touches[1]); | ||
} | ||
delta = | ||
this.Pythagorean(event.touches[0], event.touches[1]) / this.lastDiff > 1 | ||
? 1 | ||
: -1; | ||
this.lastDiff = this.Pythagorean(event.touches[0], event.touches[1]); | ||
} | ||
if (delta) this.chartZoom(delta); | ||
} | ||
//缩放 | ||
chartZoom(delta: number) { | ||
let speed = Math.round(BaseChart.showDataNum / 25); | ||
if (speed < 3) { | ||
speed = 3; | ||
} | ||
if (delta < 0) { | ||
//向下滚动 | ||
// 显示的数量 | ||
if (BaseChart.showDataNum >= BaseChart.allData.length) return; | ||
BaseChart.showDataNum += speed; //显示数量 | ||
if (this.rightCandleOffset === 0) { | ||
BaseChart.showData = BaseChart.allData.slice(-BaseChart.showDataNum); | ||
} else { | ||
BaseChart.showData = BaseChart.allData.slice( | ||
-BaseChart.showDataNum - this.rightCandleOffset, | ||
BaseChart.allData.length - this.rightCandleOffset | ||
); | ||
} | ||
this.candleNum = BaseChart.showData.length; | ||
this.candleWidth = | ||
(this.option.width - | ||
this.chartRightPadding - | ||
(3 * this.cPadding - BaseChart.candleMargin) - | ||
BaseChart.candleMargin * (this.candleNum - 1)) / | ||
this.candleNum; | ||
this.drawChart(); | ||
} else { | ||
//向上滚动 | ||
if (BaseChart.showDataNum <= 13) return; | ||
BaseChart.showDataNum -= speed; | ||
BaseChart.showData = BaseChart.allData.slice( | ||
-BaseChart.showDataNum - this.rightCandleOffset, | ||
BaseChart.allData.length - this.rightCandleOffset | ||
); | ||
if (this.rightCandleOffset === 0) { | ||
BaseChart.showData = BaseChart.allData.slice(-BaseChart.showDataNum); | ||
} | ||
this.candleNum = BaseChart.showData.length; | ||
this.candleWidth = | ||
(this.option.width - | ||
this.chartRightPadding - | ||
(3 * this.cPadding - BaseChart.candleMargin) - | ||
BaseChart.candleMargin * (this.candleNum - 1)) / | ||
this.candleNum; | ||
this.drawChart(); | ||
} | ||
} | ||
//移动 | ||
canvasMouseMove() {} | ||
canvasMouseMove(e: any) { | ||
//这一次鼠标所在x坐标 | ||
let offsetX; | ||
//移动的蜡烛数量 | ||
let candleMoveNum = parseInt(String(BaseChart.showData.length / 50)); | ||
if (candleMoveNum < 1) { | ||
candleMoveNum = 1; | ||
} | ||
if (e.touches) { | ||
offsetX = e.touches[0].clientX; | ||
} else { | ||
offsetX = e.clientX; | ||
} | ||
if (this.lastClientX < offsetX) { | ||
this.rightCandleOffset += candleMoveNum; | ||
if (this.rightCandleOffset >= BaseChart.allData.length - this.candleNum) { | ||
this.rightCandleOffset = BaseChart.allData.length - this.candleNum; | ||
} | ||
} else if (this.lastClientX > offsetX) { | ||
this.rightCandleOffset -= candleMoveNum; | ||
if (this.rightCandleOffset <= 0) { | ||
this.rightCandleOffset = 0; | ||
} | ||
} | ||
BaseChart.showData = BaseChart.allData.slice( | ||
-this.candleNum - this.rightCandleOffset, | ||
BaseChart.allData.length - this.rightCandleOffset | ||
); | ||
this.lastClientX = offsetX; | ||
this.leftCandleOffset = | ||
BaseChart.allData.length - this.rightCandleOffset - this.candleNum; | ||
this.drawChart(); | ||
} | ||
/** | ||
@@ -404,3 +518,3 @@ * 更新最后一根蜡烛 | ||
time: timeStamp, | ||
formatedTime: this.dateFormat('mm-dd HH:MM:SS', new Date(Date.now())) | ||
formatedTime: this.dateFormat('MM:SS', new Date(Date.now())) | ||
}; | ||
@@ -418,2 +532,3 @@ //@ts-ignore | ||
//时间检查 | ||
private timeCheck(lastCandleTime: number, nowTime: number) { | ||
@@ -474,7 +589,13 @@ if (!this.option.timeCheckErrorHandler) return; | ||
//标记 | ||
mark(type: CandleStatus) { | ||
this.optionPanel.mark(type); | ||
} | ||
//跳过交割期 | ||
skipDelivery() { | ||
this.optionPanel.skipDelivery(); | ||
} | ||
} | ||
export default OptionChart; |
@@ -1,8 +0,13 @@ | ||
import { createElm, setStyle } from '../utils'; | ||
import { createElm, setStyle, genJudgeOptionStatusFn } from '../utils'; | ||
import BaseChart from '../BaseChart'; | ||
import OptionConf from '../interface/OptionConf'; | ||
import _Option from '../interface/_Option'; | ||
import CandleStatus from '../enum/CandleStatus'; | ||
let id = 0; | ||
/** | ||
* @description 二元期权面板类 | ||
* @author 抓住一股仙气 <1013697816@qq.com> HtwoO <1549914423@qq.com> | ||
* @Date 2021/03/16 | ||
* @version 1.0 | ||
*/ | ||
let uid = 1; | ||
@@ -12,8 +17,16 @@ export default class OptionPanel { | ||
private originX: number; | ||
private width: number; | ||
private height: number; | ||
private cPadding: number; | ||
private chartRightPadding: number; | ||
private brokenLineColor: string; | ||
private interval!: number; | ||
private judgeOptionStatus!: Function; | ||
private tradingStatus!: { | ||
prev: number; | ||
status: string; | ||
now: number; | ||
next: number; | ||
}; | ||
private remainingElement!: HTMLElement; | ||
private quoteLine!: HTMLElement; | ||
@@ -24,7 +37,14 @@ private quoteRect!: HTMLElement; | ||
private settlementArea!: HTMLElement; | ||
private settlementOverlay!: HTMLElement; | ||
private markContainer!: HTMLElement; | ||
private markerList: any[]; | ||
//可购买时间 | ||
private purchaseTime: number; | ||
//交割时间 | ||
private deliveryTime: number; | ||
//上一把剩余多久交割,单位为秒 | ||
private remainingDeliveryTime: number = 0; | ||
@@ -36,8 +56,5 @@ private option: _Option; | ||
originX: number, | ||
width: number, | ||
height: number, | ||
cPadding: number, | ||
chartRightPadding: number, | ||
brokenLineColor: string, | ||
conf: OptionConf, | ||
option: _Option | ||
@@ -47,4 +64,2 @@ ) { | ||
this.originX = originX; | ||
this.width = width; | ||
this.height = height; | ||
this.cPadding = cPadding; | ||
@@ -56,11 +71,12 @@ this.chartRightPadding = chartRightPadding; | ||
this.purchaseTime = conf.purchaseTime; | ||
this.deliveryTime = conf.deliveryTime; | ||
this.option = option; | ||
this.purchaseTime = this.option.optionConf.purchaseTime; | ||
this.deliveryTime = this.option.optionConf.deliveryTime; | ||
this.createInfoElement(this.container); | ||
this.createSettlementElement(this.container); | ||
} | ||
//创建 行情线,时间线,呼吸灯,头像等 | ||
//创建 行情线,时间线,呼吸灯等 | ||
createInfoElement(container: HTMLElement) { | ||
@@ -73,24 +89,43 @@ let infoContainer = document.getElementById('infoContainer'); | ||
this.drawQuoteLine(infoContainer); | ||
this.drawRemainingElement(infoContainer); | ||
//创建遮罩层 | ||
this.createSettlementOverlay(infoContainer); | ||
container.appendChild(infoContainer); | ||
} | ||
//获取行情线坐标 | ||
getQuoteLineCoordinate() { | ||
const length = BaseChart.allData.length; | ||
const lastIndex = length - 1; | ||
const lastCandle = BaseChart.allData[lastIndex]; | ||
const x = this.originX + this.width - this.chartRightPadding; | ||
const y = | ||
((BaseChart.maxVal - lastCandle.close) / | ||
(BaseChart.maxVal - BaseChart.minVal)) * | ||
(this.height - 2 * this.cPadding); | ||
//创建结算区域 | ||
createSettlementElement(container: HTMLElement) { | ||
if (!this.settlementArea) { | ||
this.settlementArea = createElm('div', { id: 'settlementArea' }); | ||
} | ||
//判断当前交易状态 | ||
this.interval = | ||
(this.option.optionConf.deliveryTime + | ||
this.option.optionConf.purchaseTime) / | ||
60; | ||
this.judgeOptionStatus = genJudgeOptionStatusFn( | ||
this.option.optionConf.startMin, | ||
this.interval, | ||
this.purchaseTime | ||
); | ||
let now = new Date(); | ||
let nowMinWithSec = now.getMinutes() + now.getSeconds() / 60; | ||
this.updateTradingStatus(nowMinWithSec); | ||
return { x, y, time: lastCandle.time }; | ||
this.calcSettlementPosition(nowMinWithSec); | ||
container.append(this.settlementArea); | ||
} | ||
getPrice(): number { | ||
const length = BaseChart.allData.length; | ||
const lastIndex = length - 1; | ||
const lastCandle = BaseChart.allData[lastIndex]; | ||
return lastCandle.close; | ||
//创建遮罩层 | ||
createSettlementOverlay(container: HTMLElement) { | ||
if (!this.settlementOverlay) { | ||
this.settlementOverlay = createElm('div'); | ||
this.settlementOverlay.id = 'settlementOverlay'; | ||
} | ||
setStyle(this.settlementOverlay, { | ||
width: (this.option.width - this.chartRightPadding) / 2 + 'px', | ||
height: this.option.height / 2 + 'px' | ||
}); | ||
container.appendChild(this.settlementOverlay); | ||
} | ||
@@ -105,3 +140,3 @@ | ||
const { x, y } = this.getQuoteLineCoordinate(); | ||
const { y } = this.getCoordinateByPrice(); | ||
const close = this.getPrice(); | ||
@@ -111,11 +146,4 @@ | ||
setStyle(this.quoteLine, { | ||
width: this.chartRightPadding / 2 + 'px', | ||
top: y / 2 + 'px', | ||
left: x / 2 + 'px', | ||
backgroundImage: `linear-gradient( | ||
to right, | ||
${this.brokenLineColor} 0%, | ||
${this.brokenLineColor} 50%, | ||
transparent 50% | ||
)` | ||
width: this.option.width / 2 + 'px', | ||
top: y / 2 + 'px' | ||
}); | ||
@@ -126,3 +154,3 @@ | ||
top: y / 2 + 'px', | ||
left: x / 2 - 10 + 'px', | ||
left: (this.option.width - this.chartRightPadding) / 2 + 'px', | ||
backgroundColor: this.brokenLineColor | ||
@@ -133,13 +161,4 @@ }); | ||
setStyle(this.quoteRect, { | ||
width: BaseChart.yAxisLegendTextLength / 2 + 'px', | ||
height: BaseChart.TimeHorizonHeight / 2 + 'px', | ||
top: (y - BaseChart.TimeHorizonHeight / 2) / 2 + 'px', | ||
left: (this.width - BaseChart.yAxisLegendTextLength) / 2 + 'px', | ||
backgroundColor: this.brokenLineColor | ||
}); | ||
//当前行情文字 | ||
setStyle(this.quoteSpan, { | ||
top: y / 2 + 'px', | ||
left: (this.width - BaseChart.yAxisLegendTextLength / 2) / 2 + 'px' | ||
left: (100 + BaseChart.yAxisLegendTextLength) / 2 + 'px' | ||
}); | ||
@@ -152,54 +171,58 @@ | ||
infoContainer.appendChild(this.quoteRect); | ||
infoContainer.appendChild(this.quoteSpan); | ||
this.quoteRect.appendChild(this.quoteSpan); | ||
} | ||
//更新 | ||
update() { | ||
this.updateQuoteLine(); | ||
this.updateMarkers(); | ||
//绘制剩余时间 | ||
drawRemainingElement(infoContainer: HTMLElement) { | ||
this.remainingElement = createElm('div', { id: 'remainingElement' }); | ||
let icon = createElm('i'); | ||
let text = createElm('span'); | ||
text.innerHTML = '0'; | ||
this.remainingElement.appendChild(icon); | ||
this.remainingElement.appendChild(text); | ||
infoContainer.appendChild(this.remainingElement); | ||
} | ||
//更新行情线 | ||
updateQuoteLine() { | ||
const { x, y } = this.getQuoteLineCoordinate(); | ||
const close = this.getPrice(); | ||
setStyle(this.quoteLine, { | ||
width: this.chartRightPadding / 2 + 'px', | ||
top: y / 2 + 'px', | ||
left: x / 2 + 'px' | ||
}); | ||
setStyle(this.quoteDot, { | ||
top: y / 2 + 'px', | ||
left: x / 2 - 5 + 'px' | ||
}); | ||
setStyle(this.quoteRect, { | ||
width: BaseChart.yAxisLegendTextLength / 2 + 'px', | ||
height: BaseChart.TimeHorizonHeight / 2 + 'px', | ||
top: (y - BaseChart.TimeHorizonHeight / 2) / 2 + 'px', | ||
left: (this.width - BaseChart.yAxisLegendTextLength) / 2 + 'px' | ||
}); | ||
this.quoteSpan.innerHTML = close.toString(); | ||
setStyle(this.quoteSpan, { | ||
top: y / 2 + 'px', | ||
left: (this.width - BaseChart.yAxisLegendTextLength / 2) / 2 + 'px' | ||
}); | ||
//获取行情线坐标 | ||
getCoordinateByPrice(close?: number) { | ||
const length = BaseChart.allData.length; | ||
const lastIndex = length - 1; | ||
const lastCandle = BaseChart.allData[lastIndex]; | ||
const x = this.originX + this.option.width - this.chartRightPadding; | ||
const y = | ||
((BaseChart.maxVal - (close || lastCandle.close)) / | ||
(BaseChart.maxVal - BaseChart.minVal)) * | ||
(this.option.height - 2 * this.cPadding); | ||
return { x, y, time: lastCandle.time }; | ||
} | ||
getPrice(): number { | ||
const length = BaseChart.allData.length; | ||
const lastIndex = length - 1; | ||
const lastCandle = BaseChart.allData[lastIndex]; | ||
return lastCandle.close; | ||
} | ||
//标记 | ||
mark(type: CandleStatus) { | ||
const { x, y, time } = this.getQuoteLineCoordinate(); //和当前的行情线坐标一致 | ||
//交割中无法标记 | ||
if ( | ||
this.tradingStatus.status === 'delivering' && | ||
this.option.markFailHandler | ||
) { | ||
this.option.markFailHandler(); | ||
return; | ||
} | ||
const { x, y, time } = this.getCoordinateByPrice(); //和当前的行情线坐标一致 | ||
let markerEl = createElm('mark'); | ||
let round = createElm('div', { className: 'round' }); | ||
let rect = createElm('div', { className: 'rect' }); | ||
let markPriceLine = createElm('div', { className: 'markPriceLine' }); | ||
let markPriceSpan = createElm('span', { className: 'markPriceSpan' }); | ||
markerEl.appendChild(round); | ||
markerEl.appendChild(rect); | ||
markerEl.appendChild(markPriceLine); | ||
markerEl.appendChild(markPriceSpan); | ||
let marker = { | ||
id: id++, | ||
uid: uid++, | ||
width: 68, | ||
height: 40, | ||
price: this.getPrice(), | ||
@@ -211,4 +234,2 @@ x: x, | ||
children: { | ||
round, | ||
rect, | ||
markPriceLine, | ||
@@ -236,11 +257,10 @@ markPriceSpan | ||
left: marker.x / 2 + 'px', | ||
top: marker.y / 2 + 'px' | ||
top: marker.y / 2 + 'px', | ||
backgroundImage: `url(${ | ||
marker.type === CandleStatus.down | ||
? require('../mark_down.png') | ||
: require('../mark_up.png') | ||
})`, | ||
opacity: marker.x ? '1' : '0' | ||
}); | ||
//大头针 | ||
setStyle(marker.children.round, { | ||
backgroundColor: bgColor | ||
}); | ||
setStyle(marker.children.rect, { | ||
backgroundColor: bgColor | ||
}); | ||
@@ -252,3 +272,5 @@ //行情文字 | ||
height: BaseChart.TimeHorizonHeight / 2 + 'px', | ||
left: (this.option.width - marker.x) / 2 + 'px' | ||
left: (this.option.width - BaseChart.yAxisLegendTextLength) / 2 + 'px', | ||
top: marker.y / 2 + 'px', | ||
opacity: marker.x ? '1' : '0' | ||
}); | ||
@@ -258,12 +280,17 @@ marker.children.markPriceSpan.innerHTML = marker.price.toString(); | ||
setStyle(marker.children.markPriceLine, { | ||
width: (this.option.width - marker.x) / 2 + 'px', | ||
backgroundImage: `linear-gradient( | ||
to right, | ||
${bgColor} 0%, | ||
${bgColor} 50%, | ||
transparent 50% | ||
)` | ||
width: this.option.width / 2 + 'px', | ||
left: 0 + 'px', | ||
top: marker.y / 2 + 'px', | ||
backgroundColor: bgColor, | ||
opacity: marker.x ? '1' : '0' | ||
}); | ||
} | ||
//更新 | ||
update() { | ||
this.updateQuoteLine(); | ||
this.updateMarkers(); | ||
this.updateSettlementArea(); | ||
} | ||
//更新所有的标记 | ||
@@ -279,2 +306,3 @@ updateMarkers() { | ||
list[index].y = y; | ||
this.setMarkerStyle(list[index]); | ||
@@ -284,2 +312,98 @@ }); | ||
//更新行情线 | ||
updateQuoteLine() { | ||
const { y } = this.getCoordinateByPrice(); | ||
const close = this.getPrice(); | ||
setStyle(this.quoteLine, { | ||
top: y / 2 + 'px' | ||
}); | ||
setStyle(this.quoteDot, { | ||
top: y / 2 + 'px' | ||
}); | ||
setStyle(this.quoteRect, { | ||
top: y / 2 + 'px' | ||
}); | ||
this.quoteSpan.innerHTML = close.toString(); | ||
} | ||
//更新结算框体 | ||
updateSettlementArea() { | ||
let now = new Date(); | ||
let nowMinWithSec = now.getMinutes() + now.getSeconds() / 60; | ||
this.updateTradingStatus(nowMinWithSec); | ||
//清空 marker | ||
if ( | ||
this.tradingStatus.status === 'end' || | ||
this.tradingStatus.status === 'start' | ||
) { | ||
this.flushMarker(); | ||
} | ||
this.calcSettlementPosition(nowMinWithSec); | ||
} | ||
//更新交割遮罩层 | ||
updateSettlementOverlay(leftPosition: number) { | ||
if ( | ||
Number(leftPosition.toFixed(1)) <= | ||
this.option.width - this.chartRightPadding | ||
) { | ||
//进入交割期 | ||
setStyle(this.settlementOverlay, { | ||
opacity: '1', | ||
width: leftPosition / 2 + 'px' | ||
}); | ||
} else { | ||
setStyle(this.settlementOverlay, { | ||
opacity: '0', | ||
width: (this.option.width - this.chartRightPadding) / 2 + 'px' | ||
}); | ||
} | ||
} | ||
//更新交易状态 | ||
updateTradingStatus(nowMinWithSec: number) { | ||
let tradingStatus = (this.tradingStatus = this.judgeOptionStatus( | ||
nowMinWithSec | ||
)); | ||
this.updateRemainingElement(); | ||
//调用回调函数 | ||
if ( | ||
tradingStatus.status === 'delivering' && | ||
this.option.deliveringCallback | ||
) { | ||
let remaining; | ||
if (tradingStatus.next >= nowMinWithSec) { | ||
remaining = tradingStatus.next * 60 - nowMinWithSec * 60; | ||
} else { | ||
remaining = 3600 - nowMinWithSec * 60; | ||
} | ||
this.option.deliveringCallback(remaining); | ||
} else if (tradingStatus.status === 'end') { | ||
this.remainingDeliveryTime = 0; | ||
//重置状态生成器函数 防止跳过交割期用户的周期和没跳过交割期用户的周期对不上的问题 | ||
this.judgeOptionStatus = genJudgeOptionStatusFn( | ||
this.option.optionConf.startMin, | ||
this.interval, | ||
this.purchaseTime | ||
); | ||
} | ||
} | ||
//更新剩余时间 | ||
updateRemainingElement() { | ||
let { now, next } = this.tradingStatus; | ||
if (next < now) { | ||
next += 60; | ||
} | ||
let remaining = ((next - now) * 60).toFixed(0); | ||
let span = document.querySelector( | ||
'.__tcContainer__ #remainingElement span' | ||
); | ||
if (span instanceof HTMLElement) { | ||
span.innerHTML = remaining; | ||
} | ||
} | ||
//获取marker当前的x坐标 | ||
@@ -294,3 +418,3 @@ fetchMarkerCoordinate(marker: any) { | ||
(BaseChart.maxVal - BaseChart.minVal)) * | ||
(this.height - 2 * this.cPadding); | ||
(this.option.height - 2 * this.cPadding); | ||
@@ -324,2 +448,5 @@ if ( | ||
this.markContainer.appendChild(marker.el); | ||
this.markContainer.appendChild(marker.children.markPriceLine); | ||
this.markContainer.appendChild(marker.children.markPriceSpan); | ||
marker.el.innerHTML = marker.uid; | ||
} | ||
@@ -332,4 +459,47 @@ | ||
} | ||
uid = 1; | ||
this.markerList = []; | ||
} | ||
//计算结算框体的定位 | ||
calcSettlementPosition(nowMinWithSec: number) { | ||
let { prev } = this.tradingStatus; | ||
// if (prev > nowMinWithSec) prev -= 60; | ||
//步长 | ||
let stepLength = | ||
(this.chartRightPadding - BaseChart.yAxisLegendTextLength) / | ||
(this.deliveryTime + this.purchaseTime + this.remainingDeliveryTime); | ||
//当前步数 | ||
let step = nowMinWithSec * 60 - prev * 60; | ||
//框体宽度 | ||
let width = this.deliveryTime * stepLength; | ||
//定位 | ||
let leftPosition = | ||
this.option.width - | ||
width - | ||
BaseChart.yAxisLegendTextLength - | ||
step * stepLength; | ||
this.updateSettlementOverlay(leftPosition); | ||
setStyle(this.settlementArea, { | ||
height: this.option.height / 2 + 'px', | ||
width: width / 2 + 'px', | ||
left: leftPosition / 2 + 'px' | ||
}); | ||
} | ||
//跳过交割期,将当前的交割期并入下一周期的购买时间内 | ||
skipDelivery() { | ||
if (this.tradingStatus.status !== 'delivering') return; | ||
let { next, now } = this.tradingStatus; | ||
let remaining = next < now ? next + 60 - now : next - now; | ||
this.remainingDeliveryTime = remaining * 60; | ||
//重新生成判断函数 | ||
this.judgeOptionStatus = genJudgeOptionStatusFn( | ||
now, | ||
this.interval + remaining, | ||
this.purchaseTime + this.remainingDeliveryTime | ||
); | ||
} | ||
} |
@@ -10,3 +10,3 @@ import BaseChart from '../BaseChart'; | ||
/** | ||
* @description 主要图表类 | ||
* @description 行情图表类 | ||
* @author 抓住一股仙气 <1013697816@qq.com> HtwoO <1549914423@qq.com> | ||
@@ -13,0 +13,0 @@ * @Date 2020/11/09 |
@@ -5,2 +5,9 @@ import { createElm, setStyle } from '../utils'; | ||
/** | ||
* @description 行情面板类 | ||
* @author 抓住一股仙气 <1013697816@qq.com> HtwoO <1549914423@qq.com> | ||
* @Date 2020/11/09 | ||
* @version 3.1 | ||
*/ | ||
export default class QuotePanel { | ||
@@ -7,0 +14,0 @@ private curCandleMAContainer!: HTMLElement; |
@@ -196,4 +196,10 @@ import QuoteChart from './quoteChart/QuoteChart'; | ||
} | ||
skipDelivery() { | ||
if (this.mainChart instanceof OptionChart) { | ||
this.mainChart.skipDelivery(); | ||
} | ||
} | ||
} | ||
export default TradeChart; |
151
src/utils.ts
@@ -0,1 +1,7 @@ | ||
/** | ||
* 创建HTML元素 | ||
* @param tag 标签名 | ||
* @param attrs 初始属性 | ||
* @returns | ||
*/ | ||
export function createElm(tag: string, attrs: any = {}) { | ||
@@ -12,2 +18,7 @@ let el = document.createElement(tag); | ||
/** | ||
* 设置样式 | ||
* @param element dom | ||
* @param styles 样式 | ||
*/ | ||
export function setStyle(element: any, styles: { [key: string]: string }) { | ||
@@ -20,1 +31,141 @@ for (let key in styles) { | ||
} | ||
/** | ||
* 高仿Java线程sleep | ||
* @param duration 睡眠时间 | ||
* @returns | ||
*/ | ||
export function sleep(duration: number) { | ||
return new Promise<void>(resolve => { | ||
setTimeout(() => { | ||
resolve(); | ||
}, duration); | ||
}); | ||
} | ||
/** | ||
* 根据传入的时间判断当前的二元期权的状态,状态为:交易中,开始,结束 | ||
* @param startMin 第一盘开始的时间 分钟为单位 | ||
* @param interval 周期 多少时间一盘 分钟为单位 | ||
* @param purchaseTime 交割时间 秒为单位 | ||
*/ | ||
export function genJudgeOptionStatusFn( | ||
startMin: number, | ||
interval: number, | ||
purchaseTime: number | ||
) { | ||
/** | ||
* 生成当前的交易状态为 购买中 或者 交割中 | ||
* @param prev 本周期开始的分钟数 | ||
* @param val 当前的分钟数 带秒值 | ||
* @param next 本周期结束的分钟数 | ||
* @returns | ||
*/ | ||
function genTradingStatus(prev: number, val: number, next: number) { | ||
//已经过去的时间 | ||
let past; | ||
if (val >= prev) { | ||
past = (val - prev) * 60; | ||
} else { | ||
past = interval * 60 - (next - val) * 60; | ||
} | ||
if (past <= purchaseTime) { | ||
return 'purchasing'; | ||
} else { | ||
return 'delivering'; | ||
} | ||
} | ||
/** | ||
* @param val 当前的分钟数,需带上秒.如:当前为03分30秒,传入的val为3.5 | ||
*/ | ||
return function(val: number) { | ||
let arrTotal: any = []; | ||
let minLoop = false; | ||
/** | ||
* 生成周期枚举数组,比如:startMin=1,interval=3,生成的结果为[[1,4],[4,7],[7,10],[10,13]...] | ||
*/ | ||
function genIntervalArray(_startMin: number, interval: number) { | ||
if (_startMin >= 60) { | ||
minLoop = true; | ||
_startMin = _startMin - 60; | ||
} | ||
let end = interval + _startMin; | ||
let arr = []; | ||
if (interval + _startMin >= 60) { | ||
end = interval + _startMin - 60; | ||
arr = [_startMin, end]; | ||
arrTotal.push(arr); | ||
} | ||
if (_startMin + interval > startMin && minLoop) return; | ||
arr = [_startMin, end]; | ||
arrTotal.push(arr); | ||
genIntervalArray(interval + _startMin, interval); | ||
} | ||
genIntervalArray(startMin, interval); | ||
let res = { | ||
prev: 0, | ||
status: '', | ||
now: 0, | ||
next: 0 | ||
}; | ||
/** | ||
* 判断当前的时间处于哪个周期内,并且判断当前交易处于什么生命周期. | ||
* 生成一个res对象 | ||
*/ | ||
for (let index = 0; index < arrTotal.length; index++) { | ||
let v = arrTotal[index]; | ||
const prev = v[0]; | ||
const next = v[1]; | ||
if (prev > next) { | ||
if (val === prev) { | ||
res.prev = | ||
next - interval < 0 ? 60 - next + interval : next - interval; | ||
res.status = 'start'; | ||
res.next = | ||
prev - interval < 0 ? 60 - prev + interval : prev - interval; | ||
break; | ||
} else if (val === next) { | ||
res.prev = | ||
prev + interval >= 60 ? 60 - prev - interval : prev + interval; | ||
res.status = 'end'; | ||
res.next = | ||
next + interval >= 60 ? 60 - next - interval : next + interval; | ||
break; | ||
} else if (prev < val && next + 60 > val) { | ||
res.prev = prev; | ||
res.status = genTradingStatus(prev, val, next); | ||
res.next = next; | ||
break; | ||
} | ||
} else { | ||
if (prev < val && next > val) { | ||
res.prev = prev; | ||
res.status = genTradingStatus(prev, val, next); | ||
res.next = next; | ||
break; | ||
} else if (val === prev) { | ||
res.prev = prev; | ||
res.status = 'start'; | ||
res.next = next; | ||
break; | ||
} else if (val === next) { | ||
res.prev = | ||
prev + interval >= 60 ? 60 - prev - interval : prev + interval; | ||
res.status = 'end'; | ||
res.next = | ||
next + interval >= 60 ? 60 - next - interval : next + interval; | ||
break; | ||
} | ||
} | ||
} | ||
res.now = val; | ||
return res; | ||
}; | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
162767
27
3130
91