"use strict";function _interopDefault(e){return e&&"object"==typeof e&&"default"in e?e.default:e}var constants=require('./constants'),utils=require('./utils'),utilsLite=require("utils-lite");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");var Core=_interopDefault(require('./core')),DEFAULT_MA=[5,10,20,30],DEFAULT_K_NAME="日K",DEFAULT_DOWN_COLOR="#ec0000",DEFAULT_UP_COLOR="#00da3c",DEFAULT_START=50,DEFAULT_END=100,SHOW_FALSE={show:!1};function getCandleLegend(e){var t=e.showMA,a=e.MA,i=e.legendName,n=e.labelMap,o=[DEFAULT_K_NAME];return t&&(o=o.concat(a.map(function(e){return"MA"+e}))),n&&(o=o.map(function(e){return null==n[e]?e:n[e]})),{data:o,formatter:function(e){return null!=i[e]?i[e]:e}}}function getCandleTooltip(e){var t=e.metrics,a=e.dataType,i=e.digit,n=e.labelMap;return{trigger:"axis",axisPointer:{type:"cross"},position:function(e,t,a,i,n){var o={top:10};return o[e[0]"),e.forEach(function(e){var r=e.data,l=e.seriesName,s=e.componentSubType,u=e.color,d=null==n[l]?l:n[l];if(o.push(constants.itemPoint(u)+" "+d+": "),"candlestick"===s)o.push("
"),t.slice(0,4).forEach(function(e,t){var l=null!=n[e]?n[e]:e,s=utils.getFormated(r[t+1],a,i);o.push("- "+l+": "+s+"
")});else if("line"===s){var c=utils.getFormated(r,a,i);o.push(c+"
")}else if("bar"===s){var p=utils.getFormated(r[1],a,i);o.push(p+"
")}}),o.join("")}}}function getCandleVisualMap(e){var t=e.downColor,a=e.upColor,i=e.MA;return{show:!1,seriesIndex:e.showMA?1+i.length:1,dimension:2,pieces:[{value:1,color:t},{value:-1,color:a}]}}function getCandleGrid(e){return[{left:"10%",right:"8%",top:"10%",height:e.showVol?"50%":"65%",containLabel:!1},{left:"10%",right:"8%",top:"65%",height:"16%",containLabel:!1}]}function getCandleXAxis(e){var t=e.dims,a={onZero:!1};return[{type:"category",data:t,scale:!0,boundaryGap:!1,axisLine:a,splitLine:SHOW_FALSE,min:"dataMin",max:"dataMax"},{type:"category",gridIndex:1,data:t,scale:!0,boundaryGap:!1,axisLine:a,axisTick:SHOW_FALSE,splitLine:SHOW_FALSE,axisLabel:SHOW_FALSE,min:"dataMin",max:"dataMax"}]}function getCandleYAxis(e){var t=e.dataType,a=e.digit;return[{scale:!0,axisTick:SHOW_FALSE,axisLabel:{formatter:function(e){return utils.getFormated(e,t,a)}}},{scale:!0,gridIndex:1,splitNumber:2,axisLine:SHOW_FALSE,axisTick:SHOW_FALSE,splitLine:SHOW_FALSE,axisLabel:SHOW_FALSE}]}function getCandleDataZoom(e){var t=e.start,a=e.end;return[{type:"inside",xAxisIndex:[0,1],start:t,end:a},{show:!0,xAxisIndex:[0,1],type:"slider",top:"85%",start:t,end:a}]}function getCandleSeries(e){var t=e.values,a=e.volumes,i=e.upColor,n=e.downColor,o=e.showMA,r=e.MA,l=e.showVol,s=e.labelMap,u=e.digit,d=e.itemStyle||{normal:{color:i,color0:n,borderColor:null,borderColor0:null}},c={normal:{opacity:.5}},p=[{name:null==s[DEFAULT_K_NAME]?DEFAULT_K_NAME:s[DEFAULT_K_NAME],type:"candlestick",data:t,itemStyle:d}];return o&&r.forEach(function(e){var a="MA"+e;p.push({name:null==s[a]?a:s[a],data:calculateMA(e,t,u),type:"line",lineStyle:c,smooth:!0})}),l&&p.push({name:"Volume",type:"bar",xAxisIndex:1,yAxisIndex:1,data:a}),p}function calculateMA(e,t,a){var i=[];return t.forEach(function(n,o){if(oe[l[1]]?1:-1;H.push([t,e[I],i])}});var k=U&&getCandleLegend({showMA:m,MA:x,legendName:h,labelMap:p}),K=w&&getCandleTooltip({metrics:l,dataType:D,digit:u,labelMap:p}),P=L&&getCandleVisualMap({downColor:b,upColor:S,MA:x,showMA:m}),R=M&&getCandleDataZoom({start:F,end:O});return{legend:k,tooltip:K,visualMap:P,grid:getCandleGrid({showVol:L}),xAxis:getCandleXAxis({dims:V}),yAxis:getCandleYAxis({dataType:D,digit:u}),dataZoom:R,series:getCandleSeries({values:W,volumes:H,upColor:S,downColor:b,showMA:m,MA:x,showVol:L,labelMap:p,digit:u,itemStyle:d}),axisPointer:{link:{xAxisIndex:"all"}}}},_extends=Object.assign||function(e){for(var t=1;t