2 lines
57 KiB
JavaScript
2 lines
57 KiB
JavaScript
|
define("echarts/chart/k",["require","./base","../util/shape/Candle","../component/axis","../component/grid","../component/dataZoom","../config","../util/ecData","zrender/tool/util","../chart"],function(t){function e(t,e,s,o,n){i.call(this,t,e,s,o,n),this.refresh(o)}var i=t("./base"),s=t("../util/shape/Candle");t("../component/axis"),t("../component/grid"),t("../component/dataZoom");var o=t("../config");o.k={zlevel:0,z:2,clickable:!0,hoverable:!0,legendHoverLink:!1,xAxisIndex:0,yAxisIndex:0,itemStyle:{normal:{color:"#fff",color0:"#00aa11",lineStyle:{width:1,color:"#ff3200",color0:"#00aa11"}},emphasis:{}}};var n=t("../util/ecData"),a=t("zrender/tool/util");return e.prototype={type:o.CHART_TYPE_K,_buildShape:function(){var t=this.series;this.selectedMap={};for(var e,i={top:[],bottom:[]},s=0,n=t.length;n>s;s++)t[s].type===o.CHART_TYPE_K&&(t[s]=this.reformOption(t[s]),this.legendHoverLink=t[s].legendHoverLink||this.legendHoverLink,e=this.component.xAxis.getAxis(t[s].xAxisIndex),e.type===o.COMPONENT_TYPE_AXIS_CATEGORY&&i[e.getPosition()].push(s));for(var a in i)i[a].length>0&&this._buildSinglePosition(a,i[a]);this.addShapeList()},_buildSinglePosition:function(t,e){var i=this._mapData(e),s=i.locationMap,o=i.maxDataLength;if(0!==o&&0!==s.length){this._buildHorizontal(e,o,s);for(var n=0,a=e.length;a>n;n++)this.buildMark(e[n])}},_mapData:function(t){for(var e,i,s=this.series,o=this.component.legend,n=[],a=0,r=0,h=t.length;h>r;r++)e=s[t[r]],i=e.name,this.selectedMap[i]=o?o.isSelected(i):!0,this.selectedMap[i]&&n.push(t[r]),a=Math.max(a,e.data.length);return{locationMap:n,maxDataLength:a}},_buildHorizontal:function(t,e,i){for(var s,o,n,a,r,h,l,d,p,c,u=this.series,g={},m=0,f=i.length;f>m;m++){s=i[m],o=u[s],n=o.xAxisIndex||0,a=this.component.xAxis.getAxis(n),l=o.barWidth||Math.floor(a.getGap()/2),c=o.barMaxWidth,c&&l>c&&(l=c),r=o.yAxisIndex||0,h=this.component.yAxis.getAxis(r),g[s]=[];for(var y=0,_=e;_>y&&null!=a.getNameByIndex(y);y++)d=o.data[y],p=this.getDataFromOption(d,"-"),"-"!==p&&4==p.length&&g[s].push([a.getCoordByIndex(y),l,h.getCoord(p[0]),h.getCoord(p[1]),h.getCoord(p[2]),h.getCoord(p[3]),y,a.getNameByIndex(y)])}this._buildKLine(t,g)},_buildKLine:function(t,e){for(var i,s,n,a,r,h,l,d,p,c,u,g,m,f,y,_,x,v=this.series,b=0,S=t.length;S>b;b++)if(x=t[b],u=v[x],f=e[x],this._isLarge(f)&&(f=this._getLargePointList(f)),u.type===o.CHART_TYPE_K&&null!=f){g=u,i=this.query(g,"itemStyle.normal.lineStyle.width"),s=this.query(g,"itemStyle.normal.lineStyle.color"),n=this.query(g,"itemStyle.normal.lineStyle.color0"),a=this.query(g,"itemStyle.normal.color"),r=this.query(g,"itemStyle.normal.color0"),h=this.query(g,"itemStyle.emphasis.lineStyle.width"),l=this.query(g,"itemStyle.emphasis.lineStyle.color"),d=this.query(g,"itemStyle.emphasis.lineStyle.color0"),p=this.query(g,"itemStyle.emphasis.color"),c=this.query(g,"itemStyle.emphasis.color0");for(var z=0,T=f.length;T>z;z++)y=f[z],m=u.data[y[6]],g=m,_=y[3]<y[2],this.shapeList.push(this._getCandle(x,y[6],y[7],y[0],y[1],y[2],y[3],y[4],y[5],_?this.query(g,"itemStyle.normal.color")||a:this.query(g,"itemStyle.normal.color0")||r,this.query(g,"itemStyle.normal.lineStyle.width")||i,_?this.query(g,"itemStyle.normal.lineStyle.color")||s:this.query(g,"itemStyle.normal.lineStyle.color0")||n,_?this.query(g,"itemStyle.emphasis.color")||p||a:this.query(g,"itemStyle.emphasis.color0")||c||r,this.query(g,"itemStyle.emphasis.lineStyle.width")||h||i,_?this.query(g,"itemStyle.emphasis.lineStyle.color")||l||s:this.query(g,"itemStyle.emphasis.lineStyle.color0")||d||n))}},_isLarge:function(t){return t[0][1]<.5},_getLargePointList:function(t){for(var e=this.component.grid.getWidth(),i=t.length,s=[],o=0;e>o;o++)s[o]=t[Math.floor(i/e*o)];return s},_getCandle:function(t,e,i,o,a,r,h,l,d,p,c,u,g,m,f){var y=this.series,_={zlevel:this.getZlevelBase(),z:this.getZBase(),clickable:this.deepQuery([y[t].data[e],y[t]],"clickable"),hoverable:this.deepQuery([y[t].data[e],y[t]],"hoverable"),style:{x:o,y:[r,h,l,d],width:a,color:p,strokeColor:u,lineWidth:c,brushType:"both"},highlightStyle:{color:g,strokeColor:f,lineWidth:m},_seriesIndex:
|
||
|
a.categoryAxis={zlevel:0,z:0,show:!0,position:"bottom",name:"",nameLocation:"end",nameTextStyle:{},boundaryGap:!0,axisLine:{show:!0,onZero:!0,lineStyle:{color:"#48b",width:2,type:"solid"}},axisTick:{show:!0,interval:"auto",inside:!1,length:5,lineStyle:{color:"#333",width:1}},axisLabel:{show:!0,interval:"auto",rotate:0,margin:8,textStyle:{color:"#333"}},splitLine:{show:!1,lineStyle:{color:["#ccc"],width:1,type:"solid"}},splitArea:{show:!1,areaStyle:{color:["rgba(250,250,250,0.3)","rgba(200,200,200,0.3)"]}}};var r=t("zrender/tool/util"),h=t("zrender/tool/area");return e.prototype={type:a.COMPONENT_TYPE_AXIS_CATEGORY,_getReformedLabel:function(t){var e=this.getDataFromOption(this.option.data[t]),i=this.option.data[t].formatter||this.option.axisLabel.formatter;return i&&("function"==typeof i?e=i.call(this.myChart,e):"string"==typeof i&&(e=i.replace("{value}",e))),e},_getInterval:function(){var t=this.option.axisLabel.interval;if("auto"==t){var e=this.option.axisLabel.textStyle.fontSize,i=this.option.data,s=this.option.data.length;if(this.isHorizontal())if(s>3){var o,n,a=this.getGap(),l=!1,d=Math.floor(.5/a);for(d=1>d?1:d,t=Math.floor(15/a);!l&&s>t;){t+=d,l=!0,o=Math.floor(a*t);for(var p=Math.floor((s-1)/t)*t;p>=0;p-=t){if(0!==this.option.axisLabel.rotate)n=e;else if(i[p].textStyle)n=h.getTextWidth(this._getReformedLabel(p),this.getFont(r.merge(i[p].textStyle,this.option.axisLabel.textStyle)));else{var c=this._getReformedLabel(p)+"",u=(c.match(/\w/g)||"").length,g=c.length-u;n=u*e*2/3+g*e}if(n>o){l=!1;break}}}}else t=1;else if(s>3){var a=this.getGap();for(t=Math.floor(11/a);e>a*t-6&&s>t;)t++}else t=1}else t="function"==typeof t?1:t-0+1;return t},_buildShape:function(){if(this._interval=this._getInterval(),this.option.show){this.option.splitArea.show&&this._buildSplitArea(),this.option.splitLine.show&&this._buildSplitLine(),this.option.axisLine.show&&this._buildAxisLine(),this.option.axisTick.show&&this._buildAxisTick(),this.option.axisLabel.show&&this._buildAxisLabel();for(var t=0,e=this.shapeList.length;e>t;t++)this.zr.addShape(this.shapeList[t])}},_buildAxisTick:function(){var t,e=this.option.data,i=this.option.data.length,s=this.option.axisTick,n=s.length,a=s.lineStyle.color,r=s.lineStyle.width,h="function"==typeof s.interval?s.interval:"auto"==s.interval&&"function"==typeof this.option.axisLabel.interval?this.option.axisLabel.interval:!1,l=h?1:"auto"==s.interval?this._interval:s.interval-0+1,d=s.onGap,p=d?this.getGap()/2:"undefined"==typeof d&&this.option.boundaryGap?this.getGap()/2:0,c=p>0?-l:0;if(this.isHorizontal())for(var u,g="bottom"==this.option.position?s.inside?this.grid.getYend()-n-1:this.grid.getYend()+1:s.inside?this.grid.getY()+1:this.grid.getY()-n-1,m=c;i>m;m+=l)(!h||h(m,e[m]))&&(u=this.subPixelOptimize(this.getCoordByIndex(m)+(m>=0?p:0),r),t={_axisShape:"axisTick",zlevel:this.getZlevelBase(),z:this.getZBase(),hoverable:!1,style:{xStart:u,yStart:g,xEnd:u,yEnd:g+n,strokeColor:a,lineWidth:r}},this.shapeList.push(new o(t)));else for(var f,y="left"==this.option.position?s.inside?this.grid.getX()+1:this.grid.getX()-n-1:s.inside?this.grid.getXend()-n-1:this.grid.getXend()+1,m=c;i>m;m+=l)(!h||h(m,e[m]))&&(f=this.subPixelOptimize(this.getCoordByIndex(m)-(m>=0?p:0),r),t={_axisShape:"axisTick",zlevel:this.getZlevelBase(),z:this.getZBase(),hoverable:!1,style:{xStart:y,yStart:f,xEnd:y+n,yEnd:f,strokeColor:a,lineWidth:r}},this.shapeList.push(new o(t)))},_buildAxisLabel:function(){var t,e,i=this.option.data,o=this.option.data.length,n=this.option.axisLabel,a=n.rotate,h=n.margin,l=n.clickable,d=n.textStyle,p="function"==typeof n.interval?n.interval:!1;if(this.isHorizontal()){var c,u;"bottom"==this.option.position?(c=this.grid.getYend()+h,u="top"):(c=this.grid.getY()-h,u="bottom");for(var g=0;o>g;g+=this._interval)p&&!p(g,i[g])||""===this._getReformedLabel(g)||(e=r.merge(i[g].textStyle||{},d),t={zlevel:this.getZlevelBase(),z:this.getZBase()+3,hoverable:!1,style:{x:this.getCoordByIndex(g),y:c,color:e.color,text:this._getReformedLabel(g),textFont:this.getFont(e),textAlign:e.align||"center",textBaseline:e.baseline||u}},a&&(t.s
|