You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1 line
9.4 KiB
JavaScript

2 years ago
define("echarts/chart/treemap",["require","./base","zrender/tool/area","zrender/shape/Rectangle","zrender/shape/Text","zrender/shape/Line","../layout/TreeMap","../data/Tree","../config","../util/ecData","zrender/config","zrender/tool/event","zrender/tool/util","zrender/tool/color","../chart"],function(e){function t(e,t,n,a,o){i.call(this,e,t,n,a,o),this.refresh(a);var r=this;r._onclick=function(e){return r.__onclick(e)},r.zr.on(V.EVENT.CLICK,r._onclick)}var i=e("./base"),n=e("zrender/tool/area"),a=e("zrender/shape/Rectangle"),o=e("zrender/shape/Text"),r=e("zrender/shape/Line"),s=e("../layout/TreeMap"),l=e("../data/Tree"),h=e("../config");h.treemap={zlevel:0,z:1,calculable:!1,clickable:!0,center:["50%","50%"],size:["80%","80%"],root:"",itemStyle:{normal:{label:{show:!0,x:5,y:12,textStyle:{align:"left",color:"#000",fontFamily:"Arial",fontSize:13,fontStyle:"normal",fontWeight:"normal"}},breadcrumb:{show:!0,textStyle:{}},borderWidth:1,borderColor:"#ccc",childBorderWidth:1,childBorderColor:"#ccc"},emphasis:{}}};var m=e("../util/ecData"),V=e("zrender/config"),U=(e("zrender/tool/event"),e("zrender/tool/util")),d=e("zrender/tool/color");return t.prototype={type:h.CHART_TYPE_TREEMAP,refresh:function(e){this.clear(),e&&(this.option=e,this.series=this.option.series),this._treesMap={};for(var t=this.series,i=this.component.legend,n=0;n<t.length;n++)if(t[n].type===h.CHART_TYPE_TREEMAP){t[n]=this.reformOption(t[n]);var a=t[n].name||"";if(this.selectedMap[a]=i?i.isSelected(a):!0,!this.selectedMap[a])continue;this._buildSeries(t[n],n)}},_buildSeries:function(e,t){var i=l.fromOptionData(e.name,e.data);this._treesMap[t]=i;var n=e.root&&i.getNodeById(e.root)||i.root;this._buildTreemap(n,t)},_buildTreemap:function(e,t){for(var i=this.shapeList,n=0;n<i.length;){var a=i[n];m.get(a,"seriesIndex")===t?(this.zr.delShape(i[n]),i.splice(n,1)):n++}for(var o=i.length,r=this.series[t],l=r.itemStyle,h=this.parsePercent(r.size[0],this.zr.getWidth())||400,V=this.parsePercent(r.size[1],this.zr.getHeight())||500,U=this.parseCenter(this.zr,r.center),d=U[0]-.5*h,p=U[1]-.5*V,c=h*V,u=0,y=[],g=e.children,n=0;n<g.length;n++)u+=g[n].data.value;for(var b=0;b<g.length;b++)y.push(g[b].data.value*c/u);for(var f=new s({x:d,y:p,width:h,height:V}),k=f.run(y),_=0;_<k.length;_++){var x=g[_].data,L=k[_],W=[x.itemStyle,l],X=this.deepMerge(W);X.normal.color||(X.normal.color=this.zr.getColor(_)),X.emphasis.color||(X.emphasis.color=X.normal.color),this._buildItem(x,X,L,t,_),x.children&&this._buildChildrenTreemap(x.children,X,L,t)}this.query(r,"itemStyle.normal.breadcrumb.show")&&this._buildBreadcrumb(e,t,d,p+V);for(var n=o;n<i.length;n++)this.zr.addShape(i[n])},_buildItem:function(e,t,i,n,a){var o=this.series,r=this.getRectangle(e,t,i);m.pack(r,o[n],n,e,a,e.name),this.shapeList.push(r)},getRectangle:function(e,t,i){var n=t.emphasis,o=t.normal,r=this.getLabel(t,i,e.name,e.value),s=this.option.hoverable,l={zlevel:this.getZlevelBase(),z:this.getZBase(),hoverable:s,clickable:!0,style:U.merge({x:i.x,y:i.y,width:i.width,height:i.height,brushType:"both",color:o.color,lineWidth:o.borderWidth,strokeColor:o.borderColor},r.style,!0),highlightStyle:U.merge({color:n.color,lineWidth:n.borderWidth,strokeColor:n.borderColor},r.highlightStyle,!0)};return new a(l)},getLabel:function(e,t,i,a){var o=e.normal.label.textStyle,r=[e.emphasis.label.textStyle,o],s=this.deepMerge(r),l=e.normal.label.formatter,h=this.getLabelText(i,a,l),m=this.getFont(o),V=n.getTextWidth(h,m),U=n.getTextHeight(h,m),d=this.deepQuery([e.emphasis,e.normal],"label.formatter"),p=this.getLabelText(i,a,d),c=this.getFont(s),u=n.getTextWidth(h,c),y=n.getTextHeight(h,c);e.normal.label.show?(e.normal.label.x+V>t.width||e.normal.label.y+U>t.height)&&(h=""):h="",e.emphasis.label.show?(s.x+u>t.width||s.y+y>t.height)&&(p=""):p="";var g={style:{textX:t.x+e.normal.label.x,textY:t.y+e.normal.label.y,text:h,textPosition:"specific",textColor:o.color,textFont:m},highlightStyle:{textX:t.x+e.emphasis.label.x,textY:t.y+e.emphasis.label.y,text:p,textColor:s.color,textPosition:"specific"}};return g},getLabelText:function(e,t,i){return i?"functi