root / trunk / web / dojo / dojox / charting / Element.js
History | View | Annotate | Download (3.73 KB)
| 1 | 9 | andrej.cim | /*
|
|---|---|---|---|
| 2 | Copyright (c) 2004-2010, The Dojo Foundation All Rights Reserved.
|
||
| 3 | Available via Academic Free License >= 2.1 OR the modified BSD license.
|
||
| 4 | see: http://dojotoolkit.org/license for details
|
||
| 5 | */
|
||
| 6 | |||
| 7 | |||
| 8 | if(!dojo._hasResource["dojox.charting.Element"]){ |
||
| 9 | dojo._hasResource["dojox.charting.Element"]=true; |
||
| 10 | dojo.provide("dojox.charting.Element");
|
||
| 11 | dojo.require("dojox.gfx");
|
||
| 12 | dojo.declare("dojox.charting.Element",null,{chart:null,group:null,htmlElements:null,dirty:true,constructor:function(_1){ |
||
| 13 | this.chart=_1;
|
||
| 14 | this.group=null; |
||
| 15 | this.htmlElements=[];
|
||
| 16 | this.dirty=true; |
||
| 17 | },createGroup:function(_2){ |
||
| 18 | if(!_2){
|
||
| 19 | _2=this.chart.surface;
|
||
| 20 | } |
||
| 21 | if(!this.group){ |
||
| 22 | this.group=_2.createGroup();
|
||
| 23 | } |
||
| 24 | return this; |
||
| 25 | },purgeGroup:function(){ |
||
| 26 | this.destroyHtmlElements();
|
||
| 27 | if(this.group){ |
||
| 28 | this.group.clear();
|
||
| 29 | this.group.removeShape();
|
||
| 30 | this.group=null; |
||
| 31 | } |
||
| 32 | this.dirty=true; |
||
| 33 | return this; |
||
| 34 | },cleanGroup:function(_3){ |
||
| 35 | this.destroyHtmlElements();
|
||
| 36 | if(!_3){
|
||
| 37 | _3=this.chart.surface;
|
||
| 38 | } |
||
| 39 | if(this.group){ |
||
| 40 | this.group.clear();
|
||
| 41 | }else{
|
||
| 42 | this.group=_3.createGroup();
|
||
| 43 | } |
||
| 44 | this.dirty=true; |
||
| 45 | return this; |
||
| 46 | },destroyHtmlElements:function(){ |
||
| 47 | if(this.htmlElements.length){ |
||
| 48 | dojo.forEach(this.htmlElements,dojo.destroy);
|
||
| 49 | this.htmlElements=[];
|
||
| 50 | } |
||
| 51 | },destroy:function(){ |
||
| 52 | this.purgeGroup();
|
||
| 53 | },_plotFill:function(_4,_5,_6){ |
||
| 54 | if(!_4||!_4.type||!_4.space){
|
||
| 55 | return _4;
|
||
| 56 | } |
||
| 57 | var _7=_4.space;
|
||
| 58 | switch(_4.type){
|
||
| 59 | case "linear": |
||
| 60 | if(_7==="plot"||_7==="shapeX"||_7==="shapeY"){ |
||
| 61 | _4=dojox.gfx.makeParameters(dojox.gfx.defaultLinearGradient,_4); |
||
| 62 | _4.space=_7; |
||
| 63 | if(_7==="plot"||_7==="shapeX"){ |
||
| 64 | var _8=_5.height-_6.t-_6.b;
|
||
| 65 | _4.y1=_6.t+_8*_4.y1/100;
|
||
| 66 | _4.y2=_6.t+_8*_4.y2/100;
|
||
| 67 | } |
||
| 68 | if(_7==="plot"||_7==="shapeY"){ |
||
| 69 | var _8=_5.width-_6.l-_6.r;
|
||
| 70 | _4.x1=_6.l+_8*_4.x1/100;
|
||
| 71 | _4.x2=_6.l+_8*_4.x2/100;
|
||
| 72 | } |
||
| 73 | } |
||
| 74 | break;
|
||
| 75 | case "radial": |
||
| 76 | if(_7==="plot"){ |
||
| 77 | _4=dojox.gfx.makeParameters(dojox.gfx.defaultRadialGradient,_4); |
||
| 78 | _4.space=_7; |
||
| 79 | var _9=_5.width-_6.l-_6.r,_a=_5.height-_6.t-_6.b;
|
||
| 80 | _4.cx=_6.l+_9*_4.cx/100;
|
||
| 81 | _4.cy=_6.t+_a*_4.cy/100;
|
||
| 82 | _4.r=_4.r*Math.sqrt(_9*_9+_a*_a)/200;
|
||
| 83 | } |
||
| 84 | break;
|
||
| 85 | case "pattern": |
||
| 86 | if(_7==="plot"||_7==="shapeX"||_7==="shapeY"){ |
||
| 87 | _4=dojox.gfx.makeParameters(dojox.gfx.defaultPattern,_4); |
||
| 88 | _4.space=_7; |
||
| 89 | if(_7==="plot"||_7==="shapeX"){ |
||
| 90 | var _8=_5.height-_6.t-_6.b;
|
||
| 91 | _4.y=_6.t+_8*_4.y/100;
|
||
| 92 | _4.height=_8*_4.height/100;
|
||
| 93 | } |
||
| 94 | if(_7==="plot"||_7==="shapeY"){ |
||
| 95 | var _8=_5.width-_6.l-_6.r;
|
||
| 96 | _4.x=_6.l+_8*_4.x/100;
|
||
| 97 | _4.width=_8*_4.width/100;
|
||
| 98 | } |
||
| 99 | } |
||
| 100 | break;
|
||
| 101 | } |
||
| 102 | return _4;
|
||
| 103 | },_shapeFill:function(_b,_c){ |
||
| 104 | if(!_b||!_b.space){
|
||
| 105 | return _b;
|
||
| 106 | } |
||
| 107 | var _d=_b.space;
|
||
| 108 | switch(_b.type){
|
||
| 109 | case "linear": |
||
| 110 | if(_d==="shape"||_d==="shapeX"||_d==="shapeY"){ |
||
| 111 | _b=dojox.gfx.makeParameters(dojox.gfx.defaultLinearGradient,_b); |
||
| 112 | _b.space=_d; |
||
| 113 | if(_d==="shape"||_d==="shapeX"){ |
||
| 114 | var _e=_c.width;
|
||
| 115 | _b.x1=_c.x+_e*_b.x1/100;
|
||
| 116 | _b.x2=_c.x+_e*_b.x2/100;
|
||
| 117 | } |
||
| 118 | if(_d==="shape"||_d==="shapeY"){ |
||
| 119 | var _e=_c.height;
|
||
| 120 | _b.y1=_c.y+_e*_b.y1/100;
|
||
| 121 | _b.y2=_c.y+_e*_b.y2/100;
|
||
| 122 | } |
||
| 123 | } |
||
| 124 | break;
|
||
| 125 | case "radial": |
||
| 126 | if(_d==="shape"){ |
||
| 127 | _b=dojox.gfx.makeParameters(dojox.gfx.defaultRadialGradient,_b); |
||
| 128 | _b.space=_d; |
||
| 129 | _b.cx=_c.x+_c.width/2;
|
||
| 130 | _b.cy=_c.y+_c.height/2;
|
||
| 131 | _b.r=_b.r*_c.width/200;
|
||
| 132 | } |
||
| 133 | break;
|
||
| 134 | case "pattern": |
||
| 135 | if(_d==="shape"||_d==="shapeX"||_d==="shapeY"){ |
||
| 136 | _b=dojox.gfx.makeParameters(dojox.gfx.defaultPattern,_b); |
||
| 137 | _b.space=_d; |
||
| 138 | if(_d==="shape"||_d==="shapeX"){ |
||
| 139 | var _e=_c.width;
|
||
| 140 | _b.x=_c.x+_e*_b.x/100;
|
||
| 141 | _b.width=_e*_b.width/100;
|
||
| 142 | } |
||
| 143 | if(_d==="shape"||_d==="shapeY"){ |
||
| 144 | var _e=_c.height;
|
||
| 145 | _b.y=_c.y+_e*_b.y/100;
|
||
| 146 | _b.height=_e*_b.height/100;
|
||
| 147 | } |
||
| 148 | } |
||
| 149 | break;
|
||
| 150 | } |
||
| 151 | return _b;
|
||
| 152 | },_pseudoRadialFill:function(_f,_10,_11,_12,end){ |
||
| 153 | if(!_f||_f.type!=="radial"||_f.space!=="shape"){ |
||
| 154 | return _f;
|
||
| 155 | } |
||
| 156 | var _13=_f.space;
|
||
| 157 | _f=dojox.gfx.makeParameters(dojox.gfx.defaultRadialGradient,_f); |
||
| 158 | _f.space=_13; |
||
| 159 | if(arguments.length<4){ |
||
| 160 | _f.cx=_10.x; |
||
| 161 | _f.cy=_10.y; |
||
| 162 | _f.r=_f.r*_11/100;
|
||
| 163 | return _f;
|
||
| 164 | } |
||
| 165 | var _14=arguments.length<5?_12:(end+_12)/2; |
||
| 166 | return {type:"linear",x1:_10.x,y1:_10.y,x2:_10.x+_f.r*_11*Math.cos(_14)/100,y2:_10.y+_f.r*_11*Math.sin(_14)/100,colors:_f.colors}; |
||
| 167 | return _f;
|
||
| 168 | }}); |
||
| 169 | } |