1 |
- define("echarts/chart/funnel","require ./base zrender/shape/Text zrender/shape/Line zrender/shape/Polygon ../config ../util/ecData ../util/number zrender/tool/util zrender/tool/color zrender/tool/area ../chart".split(" "),function(q){function z(b,c,a,d,e){D.call(this,b,c,a,d,e);this.refresh(d)}var D=q("./base"),H=q("zrender/shape/Text"),I=q("zrender/shape/Line"),E=q("zrender/shape/Polygon"),A=q("../config");A.funnel={zlevel:0,z:2,clickable:!0,legendHoverLink:!0,x:10,y:80,x2:10,y2:60,min:0,max:100,minSize:"0%",maxSize:"100%",sort:"descending",gap:0,funnelAlign:"center",itemStyle:{normal:{borderColor:"#fff",borderWidth:1,label:{show:!0,position:"outer"},labelLine:{show:!0,length:10,lineStyle:{width:1,type:"solid"}}},emphasis:{borderColor:"rgba(0,0,0,0)",borderWidth:1,label:{show:!0},labelLine:{show:!0}}}};var B=q("../util/ecData"),v=q("../util/number"),y=q("zrender/tool/util"),C=q("zrender/tool/color"),F=q("zrender/tool/area");return z.prototype={type:A.CHART_TYPE_FUNNEL,_buildShape:function(){var b=this.series,c=this.component.legend;this._paramsMap={};this._selected={};this.selectedMap={};for(var a,d=0,e=b.length;e>d;d++)b[d].type===A.CHART_TYPE_FUNNEL&&(b[d]=this.reformOption(b[d]),this.legendHoverLink=b[d].legendHoverLink||this.legendHoverLink,a=b[d].name||"",this.selectedMap[a]=c?c.isSelected(a):!0,this.selectedMap[a])&&(this._buildSingleFunnel(d),this.buildMark(d));this.addShapeList()},_buildSingleFunnel:function(b){var c=this.component.legend,a=this.series[b],d=this._mapData(b),e=this._getLocation(b);this._paramsMap[b]={location:e,data:d};for(var h,n=0,t=[],k=0,l=d.length;l>k;k++)h=d[k].name,this.selectedMap[h]=c?c.isSelected(h):!0,this.selectedMap[h]&&!isNaN(d[k].value)&&(t.push(d[k]),n++);if(0!==n){for(var f,r,d=this._buildFunnelCase(b),m=a.funnelAlign,g=a.gap,G=1<n?(e.height-(n-1)*g)/n:e.height,q=e.y,u="descending"===a.sort?this._getItemWidth(b,t[0].value):v.parsePercent(a.minSize,e.width),w="descending"===a.sort?1:0,x=e.centerX,p=[],k=0,l=t.length;l>k;k++)if(h=t[k].name,this.selectedMap[h]&&!isNaN(t[k].value)){switch(n=l-2>=k?this._getItemWidth(b,t[k+w].value):"descending"===a.sort?v.parsePercent(a.minSize,e.width):v.parsePercent(a.maxSize,e.width),m){case "left":f=e.x;break;case "right":f=e.x+e.width-u;break;default:f=x-u/2}r=this._buildItem(b,t[k]._index,c?c.getColor(h):this.zr.getColor(t[k]._index),f,q,u,n,G,m);q+=G+g;f=r.style.pointList;p.unshift([f[0][0]-10,f[0][1]]);p.push([f[1][0]+10,f[1][1]]);0===k&&(0===u?(f=p.pop(),"center"==m&&(p[0][0]+=10),"right"==m&&(p[0][0]=f[0]),p[0][1]-="center"==m?10:15,1==l&&(f=r.style.pointList)):(p[p.length-1][1]-=5,p[0][1]-=5));u=n}d&&(p.unshift([f[3][0]-10,f[3][1]]),p.push([f[2][0]+10,f[2][1]]),0===u?(f=p.pop(),"center"==m&&(p[0][0]+=10),"right"==m&&(p[0][0]=f[0]),p[0][1]+="center"==m?10:15):(p[p.length-1][1]+=5,p[0][1]+=5),d.style.pointList=p)}},_buildFunnelCase:function(b){var c=this.series[b];if(this.deepQuery([c,this.option],"calculable")){var a=this._paramsMap[b].location,a={hoverable:!1,style:{pointListd:[[a.x-10,a.y-10],[a.x+a.width+10,a.y-10],[a.x+a.width+10,a.y+a.height+10],[a.x-10,a.y+a.height+10]],brushType:"stroke",lineWidth:1,strokeColor:c.calculableHolderColor||this.ecTheme.calculableHolderColor||A.calculableHolderColor}};return B.pack(a,c,b,void 0,-1),this.setCalculable(a),a=new E(a),this.shapeList.push(a),a}},_getLocation:function(b){b=this.series[b];var c=this.zr.getWidth(),a=this.zr.getHeight(),d=this.parsePercent(b.x,c),e=this.parsePercent(b.y,a),c=null==b.width?c-d-this.parsePercent(b.x2,c):this.parsePercent(b.width,c);return{x:d,y:e,width:c,height:null==b.height?a-e-this.parsePercent(b.y2,a):this.parsePercent(b.height,a),centerX:d+c/2}},_mapData:function(b){function c(a,b){return"-"===a.value?1:"-"===b.value?-1:b.value-a.value}function a(a,b){return-c(a,b)}b=this.series[b];for(var d=y.clone(b.data),e=0,h=d.length;h>e;e++)d[e]._index=e;return"none"!=b.sort&&d.sort("descending"===b.sort?c:a),d},_buildItem:function(b,c,a,d,e,h,n,t,k){var l=this.series,f=l[b],r=f.data[c],m=this.getPolygon(b,c,a,d,e,h,n,t,k);B.pack(m,l[b],b,l[b].data[c],c,l[b].data[c].name);this.shapeList.push(m);var g=this.getLabel(b,c,a,d,e,h,n,t,k);B.pack(g,l[b],b,l[b].data[c],c,l[b].data[c].name);this.shapeList.push(g);this._needLabel(f,r,!1)||(g.invisible=!0);b=this.getLabelLine(b,c,a,d,e,h,n,t,k);this.shapeList.push(b);this._needLabelLine(f,r,!1)||(b.invisible=!0);c=[];a=[];return this._needLabelLine(f,r,!0)&&(c.push(b.id),a.push(b.id)),this._needLabel(f,r,!0)&&(c.push(g.id),a.push(m.id)),m.hoverConnect=c,g.hoverConnect=a,m},_getItemWidth:function(b,c){var a=this.series[b],d=this._paramsMap[b].location,e=a.min,h=a.max,n=v.parsePercent(a.minSize,d.width),a=v.parsePercent(a.maxSize,d.width);return c*(a-n)/(h-e)},getPolygon:function(b,c,a,d,e,h,n,t,k){var l=this.series[b],f=l.data[c],r=[f,l],m=this.deepMerge(r,"itemStyle.normal")||{},g=this.deepMerge(r,"itemStyle.emphasis")||{};a=this.getItemStyleColor(m.color,b,c,f)||a;b=this.getItemStyleColor(g.color,b,c,f)||("string"==typeof a?C.lift(a,-.2):a);switch(k){case "left":k=d;break;case "right":k=d+(h-n);break;default:k=d+(h-n)/2}d={zlevel:this.getZlevelBase(),z:this.getZBase(),clickable:this.deepQuery(r,"clickable"),style:{pointList:[[d,e],[d+h,e],[k+n,e+t],[k,e+t]],brushType:"both",color:a,lineWidth:m.borderWidth,strokeColor:m.borderColor},highlightStyle:{color:b,lineWidth:g.borderWidth,strokeColor:g.borderColor}};return this.deepQuery([f,l,this.option],"calculable")&&(this.setCalculable(d),d.draggable=!0),new E(d)},getLabel:function(b,c,a,d,e,h,n,t,k){var l,f=this.series[b],r=this._paramsMap[b].location,f=y.merge(y.clone(f.data[c].itemStyle)||{},f.itemStyle),m="normal",g=f[m].label,q=g.textStyle||{},v=f[m].labelLine.length,u=this.getLabelText(b,c,m),w=this.getFont(q),x=a;g.position=g.position||f.normal.label.position;"inner"===g.position||"inside"===g.position||"center"===g.position?(l=k,x=Math.max(h,n)/2>F.getTextWidth(u,w)?"#fff":C.reverse(a)):l="left"===g.position?"right":"left";e={zlevel:this.getZlevelBase(),z:this.getZBase()+1,style:{x:this._getLabelPoint(g.position,d,r,h,n,v,k),y:e+t/2,color:q.color||x,text:u,textAlign:q.align||l,textBaseline:q.baseline||"middle",textFont:w}};return m="emphasis",g=f[m].label||g,q=g.textStyle||q,v=f[m].labelLine.length||v,g.position=g.position||f.normal.label.position,u=this.getLabelText(b,c,m),w=this.getFont(q),x=a,"inner"===g.position||"inside"===g.position||"center"===g.position?(l=k,x=Math.max(h,n)/2>F.getTextWidth(u,w)?"#fff":C.reverse(a)):l="left"===g.position?"right":"left",e.highlightStyle={x:this._getLabelPoint(g.position,d,r,h,n,v,k),color:q.color||x,text:u,textAlign:q.align||l,textFont:w,brushType:"fill"},new H(e)},getLabelText:function(b,c,a){var d=this.series[b],e=d.data[c];return(a=this.deepQuery([e,d],"itemStyle."+a+".label.formatter"))?"function"==typeof a?a.call(this.myChart,{seriesIndex:b,seriesName:d.name||"",series:d,dataIndex:c,data:e,name:e.name,value:e.value}):"string"==typeof a?a.replace("{a}","{a0}").replace("{b}","{b0}").replace("{c}","{c0}").replace("{a0}",d.name).replace("{b0}",e.name).replace("{c0}",e.value):void 0:e.name},getLabelLine:function(b,c,a,d,e,h,n,q,k){var l=this.series[b];b=this._paramsMap[b].location;c=y.merge(y.clone(l.data[c].itemStyle)||{},l.itemStyle);var l="normal",f=c[l].labelLine,r=c[l].labelLine.length,m=f.lineStyle||{},g=c[l].label;g.position=g.position||c.normal.label.position;e={zlevel:this.getZlevelBase(),z:this.getZBase()+1,hoverable:!1,style:{xStart:this._getLabelLineStartPoint(d,b,h,n,k),yStart:e+q/2,xEnd:this._getLabelPoint(g.position,d,b,h,n,r,k),yEnd:e+q/2,strokeColor:m.color||a,lineType:m.type,lineWidth:m.width}};return l="emphasis",f=c[l].labelLine||f,r=c[l].labelLine.length||r,m=f.lineStyle||m,g=c[l].label||g,g.position=g.position,e.highlightStyle={xEnd:this._getLabelPoint(g.position,d,b,h,n,r,k),strokeColor:m.color||a,lineType:m.type,lineWidth:m.width},new I(e)},_getLabelPoint:function(b,c,a,d,e,h,n){switch("inner"===b||"inside"===b?"center":b){case "center":return"center"==n?c+d/2:"left"==n?c+10:c+d-10;case "left":return"auto"===h?a.x-10:"center"==n?a.centerX-Math.max(d,e)/2-h:"right"==n?c-(e>d?e-d:0)-h:a.x-h;default:return"auto"===h?a.x+a.width+10:"center"==n?a.centerX+Math.max(d,e)/2+h:"right"==n?a.x+a.width+h:c+Math.max(d,e)+h}},_getLabelLineStartPoint:function(b,c,a,d,e){return"center"==e?c.centerX:d>a?b+Math.min(a,d)/2:b+Math.max(a,d)/2},_needLabel:function(b,c,a){return this.deepQuery([c,b],"itemStyle."+(a?"emphasis":"normal")+".label.show")},_needLabelLine:function(b,c,a){return this.deepQuery([c,b],"itemStyle."+(a?"emphasis":"normal")+".labelLine.show")},refresh:function(b){b&&(this.option=b,this.series=b.series);this.backupShapeList();this._buildShape()}},y.inherits(z,D),q("../chart").define("funnel",z),z});
|