Element.js 4.59 KB
//>>built
define(["dojo/_base/array","dojo/dom-construct","dojo/_base/declare","dojox/gfx","dojox/gfx/shape"],function(k,h,l,f,g){return l("dojox.charting.Element",null,{chart:null,group:null,htmlElements:null,dirty:!0,renderingOptions:null,constructor:function(a,c){this.chart=a;this.group=null;this.htmlElements=[];this.dirty=!0;this.trailingSymbol="...";this._events=[];c&&c.renderingOptions&&(this.renderingOptions=c.renderingOptions)},purgeGroup:function(){this.destroyHtmlElements();if(this.group){this.getGroup().removeShape();
var a=this.getGroup().children;if(g.dispose)for(var c=0;c<a.length;++c)g.dispose(a[c],!0);this.getGroup().rawNode&&h.empty(this.getGroup().rawNode);this.getGroup().clear();g.dispose&&g.dispose(this.getGroup(),!0);this.getGroup()!=this.group&&(this.group.rawNode&&h.empty(this.group.rawNode),this.group.clear(),g.dispose&&g.dispose(this.group,!0));this.group=null}this.dirty=!0;this._events.length&&(k.forEach(this._events,function(a){a.shape.disconnect(a.handle)}),this._events=[]);return this},cleanGroup:function(a){this.destroyHtmlElements();
a||(a=this.chart.surface);if(this.group){var c;a=this.getGroup().children;if(g.dispose)for(var b=0;b<a.length;++b)g.dispose(a[b],!0);this.getGroup().rawNode&&(c=this.getGroup().bgNode,h.empty(this.getGroup().rawNode));this.getGroup().clear();c&&this.getGroup().rawNode.appendChild(c)}else if(this.group=a.createGroup(),this.renderingOptions&&this.group.rawNode&&"http://www.w3.org/2000/svg"==this.group.rawNode.namespaceURI)for(b in this.renderingOptions)this.group.rawNode.setAttribute(b,this.renderingOptions[b]);
this.dirty=!0;return this},getGroup:function(){return this.group},destroyHtmlElements:function(){this.htmlElements.length&&(k.forEach(this.htmlElements,h.destroy),this.htmlElements=[])},destroy:function(){this.purgeGroup()},overrideShape:function(a,c){},getTextWidth:function(a,c){return f._base._getTextBox(a,{font:c}).w||0},getTextWithLimitLength:function(a,c,b,d){if(!a||0>=a.length)return{text:"",truncated:d||!1};if(!b||0>=b)return{text:a,truncated:d||!1};var e=a.substring(0,1)+this.trailingSymbol,
f=this.getTextWidth(e,c);if(b<=f)return{text:e,truncated:!0};if(this.getTextWidth(a,c)<=b)return{text:a,truncated:d||!1};d=0;for(e=a.length;d<e;){if(2>=e-d){for(;this.getTextWidth(a.substring(0,d)+this.trailingSymbol,c)>b;)--d;return{text:a.substring(0,d)+this.trailingSymbol,truncated:!0}}f=d+Math.round(.618*(e-d));this.getTextWidth(a.substring(0,f),c)<b?d=f:e=f}},getTextWithLimitCharCount:function(a,c,b,d){return!a||0>=a.length?{text:"",truncated:d||!1}:!b||0>=b||a.length<=b?{text:a,truncated:d||
!1}:{text:a.substring(0,b)+this.trailingSymbol,truncated:!0}},_plotFill:function(a,c,b){if(!a||!a.type||!a.space)return a;var d=a.space,e;switch(a.type){case "linear":if("plot"===d||"shapeX"===d||"shapeY"===d){a=f.makeParameters(f.defaultLinearGradient,a);a.space=d;if("plot"===d||"shapeX"===d)e=c.height-b.t-b.b,a.y1=b.t+e*a.y1/100,a.y2=b.t+e*a.y2/100;if("plot"===d||"shapeY"===d)e=c.width-b.l-b.r,a.x1=b.l+e*a.x1/100,a.x2=b.l+e*a.x2/100}break;case "radial":"plot"===d&&(a=f.makeParameters(f.defaultRadialGradient,
a),a.space=d,d=c.width-b.l-b.r,c=c.height-b.t-b.b,a.cx=b.l+d*a.cx/100,a.cy=b.t+c*a.cy/100,a.r=a.r*Math.sqrt(d*d+c*c)/200);break;case "pattern":if("plot"===d||"shapeX"===d||"shapeY"===d){a=f.makeParameters(f.defaultPattern,a);a.space=d;if("plot"===d||"shapeX"===d)e=c.height-b.t-b.b,a.y=b.t+e*a.y/100,a.height=e*a.height/100;if("plot"===d||"shapeY"===d)e=c.width-b.l-b.r,a.x=b.l+e*a.x/100,a.width=e*a.width/100}}return a},_shapeFill:function(a,c){if(!a||!a.space)return a;var b=a.space,d;switch(a.type){case "linear":if("shape"===
b||"shapeX"===b||"shapeY"===b){a=f.makeParameters(f.defaultLinearGradient,a);a.space=b;if("shape"===b||"shapeX"===b)d=c.width,a.x1=c.x+d*a.x1/100,a.x2=c.x+d*a.x2/100;if("shape"===b||"shapeY"===b)d=c.height,a.y1=c.y+d*a.y1/100,a.y2=c.y+d*a.y2/100}break;case "radial":"shape"===b&&(a=f.makeParameters(f.defaultRadialGradient,a),a.space=b,a.cx=c.x+c.width/2,a.cy=c.y+c.height/2,a.r=a.r*c.width/200);break;case "pattern":if("shape"===b||"shapeX"===b||"shapeY"===b){a=f.makeParameters(f.defaultPattern,a);a.space=
b;if("shape"===b||"shapeX"===b)d=c.width,a.x=c.x+d*a.x/100,a.width=d*a.width/100;if("shape"===b||"shapeY"===b)d=c.height,a.y=c.y+d*a.y/100,a.height=d*a.height/100}}return a},_pseudoRadialFill:function(a,c,b,d,e){if(!a||"radial"!==a.type||"shape"!==a.space)return a;var g=a.space;a=f.makeParameters(f.defaultRadialGradient,a);a.space=g;if(4>arguments.length)return a.cx=c.x,a.cy=c.y,a.r=a.r*b/100,a;g=5>arguments.length?d:(e+d)/2;return{type:"linear",x1:c.x,y1:c.y,x2:c.x+a.r*b*Math.cos(g)/100,y2:c.y+a.r*
b*Math.sin(g)/100,colors:a.colors}}})});