2 lines
17 KiB
JavaScript
2 lines
17 KiB
JavaScript
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t(require("echarts/lib/echarts"),require("echarts/lib/component/tooltip"),require("echarts/lib/component/legend"),require("echarts/lib/chart/bar"),require("echarts/lib/chart/line"),require("echarts/lib/chart/candlestick"),require("echarts/lib/component/visualMap"),require("echarts/lib/component/dataZoom")):"function"==typeof define&&define.amd?define(["echarts/lib/echarts","echarts/lib/component/tooltip","echarts/lib/component/legend","echarts/lib/chart/bar","echarts/lib/chart/line","echarts/lib/chart/candlestick","echarts/lib/component/visualMap","echarts/lib/component/dataZoom"],t):e.VeCandle=t(e.echarts)}(this,function(e){"use strict";e=e&&e.hasOwnProperty("default")?e.default:e;var t={categoryAxis:{axisLine:{show:!1},axisTick:{show:!1},splitLine:{show:!1}},valueAxis:{axisLine:{show:!1}},line:{smooth:!0},grid:{containLabel:!0,left:10,right:10}},i=["#19d4ae","#5ab1ef","#fa6e86","#ffb980","#0067a6","#c4b4e4","#d87a80","#9cbbff","#d9d0c7","#87a997","#d49ea2","#5b4947","#7ba3a8"],n=function(e){return['<span style="',"background-color:"+e+";","display: inline-block;","width: 10px;","height: 10px;","border-radius: 50%;","margin-right:2px;",'"></span>'].join("")},r=["initOptions","loading","dataEmpty","judgeWidth","widthChangeDelay"],a=["grid","dataZoom","visualMap","toolbox","title","legend","xAxis","yAxis","radar","tooltip","axisPointer","brush","geo","timeline","graphic","series","backgroundColor","textStyle"],o={th:3,mi:6,bi:9,tr:12},s={zeroFormat:null,nullFormat:null,defaultFormat:"0,0",scalePercentBy100:!0,abbrLabel:{th:"k",mi:"m",bi:"b",tr:"t"}},l=1e12,c=1e9,h=1e6,d=1e3;function u(e,t,i,n){var r=e.toString().split("."),a=t-(n||0),o=2===r.length?Math.min(Math.max(r[1].length,a),t):a,s=Math.pow(10,o),l=(i(e+"e+"+o)/s).toFixed(o);if(n>t-o){var c=new RegExp("\\.?0{1,"+(n-(t-o))+"}$");l=l.replace(c,"")}return l}function f(e,t,i,n){var r=Math.abs(t),a=!1,s=!1,f="",p="",b=!1,m=void 0,y=void 0;i=i||"",t=t||0,~i.indexOf("(")?(a=!0,i=i.replace(/[(|)]/g,"")):(~i.indexOf("+")||~i.indexOf("-"))&&(y=~i.indexOf("+")?i.indexOf("+"):t<0?i.indexOf("-"):-1,i=i.replace(/[+|-]/g,"")),~i.indexOf("a")&&(m=!!(m=i.match(/a(k|m|b|t)?/))&&m[1],~i.indexOf(" a")&&(f=" "),i=i.replace(new RegExp(f+"a[kmbt]?"),""),r>=l&&!m||"t"===m?(f+=e.abbrLabel.tr,t/=l):r<l&&r>=c&&!m||"b"===m?(f+=e.abbrLabel.bi,t/=c):r<c&&r>=h&&!m||"m"===m?(f+=e.abbrLabel.mi,t/=h):(r<h&&r>=d&&!m||"k"===m)&&(f+=e.abbrLabel.th,t/=d)),~i.indexOf("[.]")&&(s=!0,i=i.replace("[.]","."));var g=t.toString().split(".")[0],v=i.split(".")[1],x=i.indexOf(","),O=(i.split(".")[0].split(",")[0].match(/0/g)||[]).length;if(v?(g=(p=~v.indexOf("[")?u(t,(v=(v=v.replace("]","")).split("["))[0].length+v[1].length,n,v[1].length):u(t,v.length,n)).split(".")[0],p=~p.indexOf(".")?"."+p.split(".")[1]:"",s&&0==+p.slice(1)&&(p="")):g=u(t,0,n),f&&!m&&+g>=1e3&&f!==o.trillion&&(g=""+ +g/1e3,f=o.million),~g.indexOf("-")&&(g=g.slice(1),b=!0),g.length<O)for(var j=O-g.length;j>0;j--)g="0"+g;x>-1&&(g=g.toString().replace(/(\d)(?=(\d{3})+(?!\d))/g,"$1,")),i.indexOf(".")||(g="");var A=g+p+(f||"");return a?A=(a&&b?"(":"")+A+(a&&b?")":""):y>=0?A=0===y?(b?"-":"+")+A:A+(b?"-":"+"):b&&(A="-"+A),A}function p(e,t){Object.keys(t).forEach(function(i){e[i]=t[i]})}var b={},m={};function y(e,t,i){return function(e,t,i){t=t||b.defaultFormat,i=i||Math.round;var n=void 0,r=void 0;if(0===e&&null!==b.zeroFormat)n=b.zeroFormat;else if(null===e&&null!==b.nullFormat)n=b.nullFormat;else{for(var a in m)if(m[a]&&t.match(m[a].regexp)){r=m[a].format;break}n=(r=r||f.bind(null,b))(e,t,i,y)}return n}(0===e||void 0===e?0:null===e||function(e){return"number"==typeof e&&isNaN(e)}(e)?null:"string"==typeof e?b.zeroFormat&&e===b.zeroFormat?0:b.nullFormat&&e===b.nullFormat||!e.replace(/[^0-9]+/g,"").length?null:+e:+e||null,t,i)}p(b,s),y.options=b,y._numberToFormat=f.bind(null,b),y.register=function(e,t){m[e]=t},y.unregister=function(e){m[e]=null},y.setOptions=function(e){p(b,e)},y.reset=function(){p(b,s)},y.register("percentage",{regexp:/%/,format:function(e,t,i,n){var r=~t.indexOf(" %")?" ":"",a=void 0;return n.options.scalePercentBy100&&(e*=100),t=t.replace(/\s?%/,""),~(a=n._numberToFormat(e,t,i)).indexOf(")")?((a=a.split("")).splice(-1,0,r+"%"),a=a.join("")):a=a+r+"%",a}});var g="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},v=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var i=arguments[t];for(var n in i)Object.prototype.hasOwnProperty.call(i,n)&&(e[n]=i[n])}return e};function x(e,t){var i=null;return function(){var n=this,r=arguments;clearTimeout(i),i=setTimeout(function(){e.apply(n,r)},t)}}var O="function"==typeof Symbol&&"symbol"===g(Symbol.iterator)?function(e){return void 0===e?"undefined":g(e)}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":void 0===e?"undefined":g(e)};function j(e){return Object.prototype.toString.call(e)}function A(e){return void 0===e?"undefined":O(e)}function w(e){return"[object Object]"===j(e)}function k(e){return"[object Array]"===j(e)}function S(e,t){return Object.prototype.hasOwnProperty.call(e,t)}var z=function(e,t,i){var n=arguments.length>3&&void 0!==arguments[3]?arguments[3]:"-";if(isNaN(e))return n;if(!t)return e;if("[object Function]"===j(t))return t(e,y);i=isNaN(i)?0:++i;var r=".["+new Array(i).join(0)+"]",a=t;switch(t){case"KMB":a=i?"0,0"+r+"a":"0,0a";break;case"normal":a=i?"0,0"+r:"0,0";break;case"percent":a=i?"0,0"+r+"%":"0,0.[00]%"}return y(e,a)},C=[5,10,20,30],M="日K",E={show:!1};var L=function(e,t,i,r){var a=i.dimension,o=void 0===a?e[0]:a,s=i.metrics,l=void 0===s?e.slice(1,6):s,c=i.digit,h=void 0===c?2:c,d=i.itemStyle,u=i.labelMap,f=void 0===u?{}:u,p=i.legendName,b=void 0===p?{}:p,m=i.MA,y=void 0===m?C:m,g=i.showMA,v=void 0!==g&&g,x=i.showVol,O=void 0!==x&&x,j=i.showDataZoom,A=void 0!==j&&j,w=i.downColor,S=void 0===w?"#ec0000":w,L=i.upColor,F=void 0===L?"#00da3c":L,$=i.start,H=void 0===$?50:$,_=i.end,T=void 0===_?100:_,P=i.dataType,N=r.tooltipVisible,R=r.legendVisible,V=k(t[0]),B=[],W=[],D=[],q=l.slice(0,4),I=l[4];V?t.forEach(function(t){var i=[];B.push(t[e.indexOf(o)]),q.forEach(function(n){i.push(t[e.indexOf(n)])}),W.push(i),I&&D.push(t[e.indexOf(I)])}):t.forEach(function(e,t){var i=[];if(B.push(e[o]),q.forEach(function(t){i.push(e[t])}),W.push(i),I){var n=e[l[0]]>e[l[1]]?1:-1;D.push([t,e[I],n])}});var Z=R&&function(e){var t=e.showMA,i=e.MA,n=e.legendName,r=e.labelMap,a=[M];return t&&(a=a.concat(i.map(function(e){return"MA"+e}))),r&&(a=a.map(function(e){return null==r[e]?e:r[e]})),{data:a,formatter:function(e){return null!=n[e]?n[e]:e}}}({showMA:v,MA:y,legendName:b,labelMap:f}),U=N&&function(e){var t=e.metrics,i=e.dataType,r=e.digit,a=e.labelMap;return{trigger:"axis",axisPointer:{type:"cross"},position:function(e,t,i,n,r){var a={top:10};return a[e[0]<r.viewSize[0]/2?"right":"left"]=60,a},formatter:function(e){var o=[];return o.push(e[0].axisValue+"<br>"),e.forEach(function(e){var s=e.data,l=e.seriesName,c=e.componentSubType,h=e.color,d=null==a[l]?l:a[l];if(o.push(n(h)+" "+d+": "),"candlestick"===c)o.push("<br>"),t.slice(0,4).forEach(function(e,t){var n=null!=a[e]?a[e]:e,l=z(s[t+1],i,r);o.push("- "+n+": "+l+"<br>")});else if("line"===c){var u=z(s,i,r);o.push(u+"<br>")}else if("bar"===c){var f=z(s[1],i,r);o.push(f+"<br>")}}),o.join("")}}}({metrics:l,dataType:P,digit:h,labelMap:f}),G=O&&function(e){var t=e.downColor,i=e.upColor,n=e.MA;return{show:!1,seriesIndex:e.showMA?1+n.length:1,dimension:2,pieces:[{value:1,color:t},{value:-1,color:i}]}}({downColor:S,upColor:F,MA:y,showMA:v}),J=A&&function(e){var t=e.start,i=e.end;return[{type:"inside",xAxisIndex:[0,1],start:t,end:i},{show:!0,xAxisIndex:[0,1],type:"slider",top:"85%",start:t,end:i}]}({start:H,end:T});return{legend:Z,tooltip:U,visualMap:G,grid:[{left:"10%",right:"8%",top:"10%",height:{showVol:O}.showVol?"50%":"65%",containLabel:!1},{left:"10%",right:"8%",top:"65%",height:"16%",containLabel:!1}],xAxis:function(e){var t=e.dims,i={onZero:!1};return[{type:"category",data:t,scale:!0,boundaryGap:!1,axisLine:i,splitLine:E,min:"dataMin",max:"dataMax"},{type:"category",gridIndex:1,data:t,scale:!0,boundaryGap:!1,axisLine:i,axisTick:E,splitLine:E,axisLabel:E,min:"dataMin",max:"dataMax"}]}({dims:B}),yAxis:function(e){var t=e.dataType,i=e.digit;return[{scale:!0,axisTick:E,axisLabel:{formatter:function(e){return z(e,t,i)}}},{scale:!0,gridIndex:1,splitNumber:2,axisLine:E,axisTick:E,splitLine:E,axisLabel:E}]}({dataType:P,digit:h}),dataZoom:J,series:function(e){var t=e.values,i=e.volumes,n=e.upColor,r=e.downColor,a=e.showMA,o=e.MA,s=e.showVol,l=e.labelMap,c=e.digit,h=e.itemStyle||{normal:{color:n,color0:r,borderColor:null,borderColor0:null}},d={normal:{opacity:.5}},u=[{name:null==l[M]?M:l[M],type:"candlestick",data:t,itemStyle:h}];return a&&o.forEach(function(e){var i="MA"+e;u.push({name:null==l[i]?i:l[i],data:function(e,t,i){var n=[];return t.forEach(function(r,a){if(a<e)n.push("-");else{for(var o=0,s=0;s<e;s++)o+=t[a-s][1];n.push(+(o/e).toFixed(i))}}),n}(e,t,c),type:"line",lineStyle:d,smooth:!0})}),s&&u.push({name:"Volume",type:"bar",xAxisIndex:1,yAxisIndex:1,data:i}),u}({values:W,volumes:D,upColor:F,downColor:S,showMA:v,MA:y,showVol:O,labelMap:f,digit:h,itemStyle:d}),axisPointer:{link:{xAxisIndex:"all"}}}},F={render:function(){var e=this.$createElement,t=this._self._c||e;return t("div",{staticClass:"v-charts-component-loading"},[t("div",{staticClass:"loader"},[t("div",{staticClass:"loading-spinner"},[t("svg",{staticClass:"circular",attrs:{viewBox:"25 25 50 50"}},[t("circle",{staticClass:"path",attrs:{cx:"50",cy:"50",r:"20",fill:"none"}})])])])])},staticRenderFns:[]},$={render:function(){var e=this.$createElement;return(this._self._c||e)("div",{staticClass:"v-charts-data-empty"},[this._v(" 暂无数据 ")])},staticRenderFns:[]};function H(e,t){Object.keys(t).forEach(function(i){t[i]&&(e[i]=t[i])})}var _={render:function(e){return e("div",{class:[(t=this.$options.name||this.$options._componentTag,t.replace(/([a-z])([A-Z])/g,"$1-$2").toLowerCase())],style:this.canvasStyle},[e("div",{style:this.canvasStyle,class:{"v-charts-mask-status":this.dataEmpty||this.loading},ref:"canvas"}),e($,{style:{display:this.dataEmpty?"":"none"}}),e(F,{style:{display:this.loading?"":"none"}}),this.$slots.default]);var t},props:{data:{type:[Object,Array],default:function(){return{}}},settings:{type:Object,default:function(){return{}}},width:{type:String,default:"auto"},height:{type:String,default:"400px"},beforeConfig:{type:Function},afterConfig:{type:Function},afterSetOption:{type:Function},afterSetOptionOnce:{type:Function},events:{type:Object},grid:{type:[Object,Array]},colors:{type:Array},tooltipVisible:{type:Boolean,default:!0},legendVisible:{type:Boolean,default:!0},legendPosition:{type:String},markLine:{type:Object},markArea:{type:Object},markPoint:{type:Object},visualMap:{type:[Object,Array]},dataZoom:{type:[Object,Array]},toolbox:{type:[Object,Array]},initOptions:{type:Object,default:function(){return{}}},title:[Object,Array],legend:[Object,Array],xAxis:[Object,Array],yAxis:[Object,Array],radar:Object,tooltip:Object,axisPointer:[Object,Array],brush:[Object,Array],geo:[Object,Array],timeline:[Object,Array],graphic:[Object,Array],series:[Object,Array],backgroundColor:[Object,String],textStyle:[Object,Array],animation:Object,theme:Object,themeName:String,loading:Boolean,dataEmpty:Boolean,extend:Object,judgeWidth:{type:Boolean,default:!1},widthChangeDelay:{type:Number,default:300},tooltipFormatter:{type:Function},resizeable:{type:Boolean,default:!0},resizeDelay:{type:Number,default:200},changeDelay:{type:Number,default:0},setOptionOpts:{type:[Boolean,Object],default:!0},cancelResizeCheck:Boolean,notSetUnchange:Array,log:Boolean},watch:{data:{deep:!0,handler:function(e){e&&this.changeHandler()}},settings:{deep:!0,handler:function(e){e.type&&this.chartLib&&(this.chartHandler=this.chartLib[e.type]),this.changeHandler()}},width:"nextTickResize",height:"nextTickResize",events:{deep:!0,handler:"createEventProxy"},theme:{deep:!0,handler:"themeChange"},themeName:"themeChange",resizeable:"resizeableHandler"},computed:{canvasStyle:function(){return{width:this.width,height:this.height,position:"relative"}},chartColor:function(){return this.colors||this.theme&&this.theme.color||i}},methods:{dataHandler:function(){if(this.chartHandler){var e=this.data,t=e,i=t.columns,n=void 0===i?[]:i,r=t.rows,a=void 0===r?[]:r,o={tooltipVisible:this.tooltipVisible,legendVisible:this.legendVisible,echarts:this.echarts,color:this.chartColor,tooltipFormatter:this.tooltipFormatter,_once:this._once};this.beforeConfig&&(e=this.beforeConfig(e));var s=this.chartHandler(n,a,this.settings,o);s&&("function"==typeof s.then?s.then(this.optionsHandler):this.optionsHandler(s))}},nextTickResize:function(){this.$nextTick(this.resize)},resize:function(){this.cancelResizeCheck?this.echartsResize():this.$el&&this.$el.clientWidth&&this.$el.clientHeight&&this.echartsResize()},echartsResize:function(){this.echarts&&this.echarts.resize()},optionsHandler:function(t){var i=this;if(this.legendPosition&&t.legend&&(t.legend[this.legendPosition]=10,~["left","right"].indexOf(this.legendPosition)&&(t.legend.top="middle",t.legend.orient="vertical")),t.color=this.chartColor,a.forEach(function(e){i[e]&&(t[e]=i[e])}),this.animation&&function(e,t){Object.keys(t).forEach(function(i){e[i]=t[i]})}(t,this.animation),this.markArea||this.markLine||this.markPoint){var n={markArea:this.markArea,markLine:this.markLine,markPoint:this.markPoint},r=t.series;k(r)?r.forEach(function(e){H(e,n)}):w(r)&&H(r,n)}this.extend&&function(e,t){Object.keys(t).forEach(function(i){var n=t[i];~i.indexOf(".")?function(e,t,i){if(t){var n=e,r=t.split(".");r.forEach(function(e,t){t===r.length-1?n[e]=i:(n[e]||(n[e]={}),n=n[e])})}}(e,i,n):"function"==typeof n?e[i]=n(e[i]):k(e[i])&&w(e[i][0])?e[i].forEach(function(t,r){e[i][r]=v({},t,n)}):w(e[i])?e[i]=v({},e[i],n):e[i]=n})}(t,this.extend),this.afterConfig&&(t=this.afterConfig(t));var o=this.setOptionOpts;!this.settings.bmap&&!this.settings.amap||w(o)||(o=!1),this.notSetUnchange&&this.notSetUnchange.length&&(this.notSetUnchange.forEach(function(e){var n,r=t[e];r&&(!function e(t,i){if(t===i)return!0;if(null===t||null===i||"object"!==A(t)||"object"!==A(i))return t===i;for(var n in t)if(S(t,n)){var r=t[n],a=i[n],o=A(r);if("undefined"===A(a))return!1;if("object"===o){if(!e(r,a))return!1}else if(r!==a)return!1}for(var s in i)if(S(i,s)&&"undefined"===A(t)[s])return!1;return!0}(r,i._store[e])?i._store[e]=(n=r,JSON.parse(JSON.stringify(n))):t[e]=void 0)}),w(o)?o.notMerge=!1:o=!1),this._isDestroyed||(this.log&&console.log(t),this.echarts.setOption(t,o),this.$emit("ready",this.echarts,t,e),this._once["ready-once"]||(this._once["ready-once"]=!0,this.$emit("ready-once",this.echarts,t,e)),this.judgeWidth&&this.judgeWidthHandler(t),this.afterSetOption&&this.afterSetOption(this.echarts,t,e),this.afterSetOptionOnce&&!this._once.afterSetOptionOnce&&(this._once.afterSetOptionOnce=!0,this.afterSetOptionOnce(this.echarts,t,e)))},judgeWidthHandler:function(e){var t=this,i=this.widthChangeDelay,n=this.resize;this.$el.clientWidth||this.$el.clientHeight?n():this.$nextTick(function(e){t.$el.clientWidth||t.$el.clientHeight?n():setTimeout(function(e){n(),t.$el.clientWidth&&t.$el.clientHeight||console.warn(" Can't get dom width or height ")},i)})},resizeableHandler:function(e){e&&!this._once.onresize&&this.addResizeListener(),!e&&this._once.onresize&&this.removeResizeListener()},init:function(){if(!this.echarts){var i=this.themeName||this.theme||t;this.echarts=e.init(this.$refs.canvas,i,this.initOptions),this.data&&this.changeHandler(),this.createEventProxy(),this.resizeable&&this.addResizeListener()}},addResizeListener:function(){window.addEventListener("resize",this.resizeHandler),this._once.onresize=!0},removeResizeListener:function(){window.removeEventListener("resize",this.resizeHandler),this._once.onresize=!1},addWatchToProps:function(){var e=this,t=this._watchers.map(function(e){return e.expression});Object.keys(this.$props).forEach(function(i){if(!~t.indexOf(i)&&!~r.indexOf(i)){var n={};~["[object Object]","[object Array]"].indexOf(j(e.$props[i]))&&(n.deep=!0),e.$watch(i,function(){e.changeHandler()},n)}})},createEventProxy:function(){var e=this,t=this,i=Object.keys(this.events||{});i.length&&i.forEach(function(i){-1===e.registeredEvents.indexOf(i)&&(e.registeredEvents.push(i),e.echarts.on(i,function(e){return function(){if(e in t.events){for(var i=arguments.length,n=Array(i),r=0;r<i;r++)n[r]=arguments[r];t.events[e].apply(null,n)}}}(i)))})},themeChange:function(e){this.clean(),this.echarts=null,this.init()},clean:function(){this.resizeable&&this.removeResizeListener(),this.echarts.dispose()}},created:function(){this.echarts=null,this.registeredEvents=[],this._once={},this._store={},this.resizeHandler=x(this.resize,this.resizeDelay),this.changeHandler=x(this.dataHandler,this.changeDelay),this.addWatchToProps()},mounted:function(){this.init()},beforeDestroy:function(){this.clean()},_numerify:y};return v({},_,{name:"VeCandle",data:function(){return this.chartHandler=L,{}}})});
|