root / trunk / web / dojo / dojox / charting / plot2d / common.js @ 10
History | View | Annotate | Download (4.33 KB)
1 |
/*
|
---|---|
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.plot2d.common"]){ |
9 |
dojo._hasResource["dojox.charting.plot2d.common"]=true; |
10 |
dojo.provide("dojox.charting.plot2d.common");
|
11 |
dojo.require("dojo.colors");
|
12 |
dojo.require("dojox.gfx");
|
13 |
dojo.require("dojox.lang.functional");
|
14 |
(function(){
|
15 |
var df=dojox.lang.functional,dc=dojox.charting.plot2d.common;
|
16 |
dojo.mixin(dojox.charting.plot2d.common,{makeStroke:function(_1){ |
17 |
if(!_1){
|
18 |
return _1;
|
19 |
} |
20 |
if(typeof _1=="string"||_1 instanceof dojo.Color){ |
21 |
_1={color:_1};
|
22 |
} |
23 |
return dojox.gfx.makeParameters(dojox.gfx.defaultStroke,_1);
|
24 |
},augmentColor:function(_2,_3){ |
25 |
var t=new dojo.Color(_2),c=new dojo.Color(_3); |
26 |
c.a=t.a; |
27 |
return c;
|
28 |
},augmentStroke:function(_4,_5){ |
29 |
var s=dc.makeStroke(_4);
|
30 |
if(s){
|
31 |
s.color=dc.augmentColor(s.color,_5); |
32 |
} |
33 |
return s;
|
34 |
},augmentFill:function(_6,_7){ |
35 |
var fc,c=new dojo.Color(_7); |
36 |
if(typeof _6=="string"||_6 instanceof dojo.Color){ |
37 |
return dc.augmentColor(_6,_7);
|
38 |
} |
39 |
return _6;
|
40 |
},defaultStats:{hmin:Number.POSITIVE_INFINITY,hmax:Number.NEGATIVE_INFINITY,vmin:Number.POSITIVE_INFINITY,vmax:Number.NEGATIVE_INFINITY},collectSimpleStats:function(_8){ |
41 |
var _9=dojo.delegate(dc.defaultStats);
|
42 |
for(var i=0;i<_8.length;++i){ |
43 |
var _a=_8[i];
|
44 |
for(var j=0;j<_a.data.length;j++){ |
45 |
if(_a.data[j]!==null){ |
46 |
if(typeof _a.data[j]=="number"){ |
47 |
var _b=_9.vmin,_c=_9.vmax;
|
48 |
if(!("ymin" in _a)||!("ymax" in _a)){ |
49 |
dojo.forEach(_a.data,function(_d,i){
|
50 |
if(_d!==null){ |
51 |
var x=i+1,y=_d; |
52 |
if(isNaN(y)){
|
53 |
y=0;
|
54 |
} |
55 |
_9.hmin=Math.min(_9.hmin,x); |
56 |
_9.hmax=Math.max(_9.hmax,x); |
57 |
_9.vmin=Math.min(_9.vmin,y); |
58 |
_9.vmax=Math.max(_9.vmax,y); |
59 |
} |
60 |
}); |
61 |
} |
62 |
if("ymin" in _a){ |
63 |
_9.vmin=Math.min(_b,_a.ymin); |
64 |
} |
65 |
if("ymax" in _a){ |
66 |
_9.vmax=Math.max(_c,_a.ymax); |
67 |
} |
68 |
}else{
|
69 |
var _e=_9.hmin,_f=_9.hmax,_b=_9.vmin,_c=_9.vmax;
|
70 |
if(!("xmin" in _a)||!("xmax" in _a)||!("ymin" in _a)||!("ymax" in _a)){ |
71 |
dojo.forEach(_a.data,function(val,i){
|
72 |
if(val!==null){ |
73 |
var x="x" in val?val.x:i+1,y=val.y; |
74 |
if(isNaN(x)){
|
75 |
x=0;
|
76 |
} |
77 |
if(isNaN(y)){
|
78 |
y=0;
|
79 |
} |
80 |
_9.hmin=Math.min(_9.hmin,x); |
81 |
_9.hmax=Math.max(_9.hmax,x); |
82 |
_9.vmin=Math.min(_9.vmin,y); |
83 |
_9.vmax=Math.max(_9.vmax,y); |
84 |
} |
85 |
}); |
86 |
} |
87 |
if("xmin" in _a){ |
88 |
_9.hmin=Math.min(_e,_a.xmin); |
89 |
} |
90 |
if("xmax" in _a){ |
91 |
_9.hmax=Math.max(_f,_a.xmax); |
92 |
} |
93 |
if("ymin" in _a){ |
94 |
_9.vmin=Math.min(_b,_a.ymin); |
95 |
} |
96 |
if("ymax" in _a){ |
97 |
_9.vmax=Math.max(_c,_a.ymax); |
98 |
} |
99 |
} |
100 |
break;
|
101 |
} |
102 |
} |
103 |
} |
104 |
return _9;
|
105 |
},calculateBarSize:function(_10,opt,_11){ |
106 |
if(!_11){
|
107 |
_11=1;
|
108 |
} |
109 |
var gap=opt.gap,_12=(_10-2*gap)/_11; |
110 |
if("minBarSize" in opt){ |
111 |
_12=Math.max(_12,opt.minBarSize); |
112 |
} |
113 |
if("maxBarSize" in opt){ |
114 |
_12=Math.min(_12,opt.maxBarSize); |
115 |
} |
116 |
_12=Math.max(_12,1);
|
117 |
gap=(_10-_12*_11)/2;
|
118 |
return {size:_12,gap:gap}; |
119 |
},collectStackedStats:function(_13){ |
120 |
var _14=dojo.clone(dc.defaultStats);
|
121 |
if(_13.length){
|
122 |
_14.hmin=Math.min(_14.hmin,1);
|
123 |
_14.hmax=df.foldl(_13,"seed, run -> Math.max(seed, run.data.length)",_14.hmax);
|
124 |
for(var i=0;i<_14.hmax;++i){ |
125 |
var v=_13[0].data[i]; |
126 |
if(isNaN(v)){
|
127 |
v=0;
|
128 |
} |
129 |
_14.vmin=Math.min(_14.vmin,v); |
130 |
for(var j=1;j<_13.length;++j){ |
131 |
var t=_13[j].data[i];
|
132 |
if(isNaN(t)){
|
133 |
t=0;
|
134 |
} |
135 |
v+=t; |
136 |
} |
137 |
_14.vmax=Math.max(_14.vmax,v); |
138 |
} |
139 |
} |
140 |
return _14;
|
141 |
},curve:function(a,_15){ |
142 |
var arr=a.slice(0); |
143 |
if(_15=="x"){ |
144 |
arr[arr.length]=arr[0];
|
145 |
} |
146 |
var p=dojo.map(arr,function(_16,i){ |
147 |
if(i==0){ |
148 |
return "M"+_16.x+","+_16.y; |
149 |
} |
150 |
if(!isNaN(_15)){
|
151 |
var dx=_16.x-arr[i-1].x,dy=arr[i-1].y; |
152 |
return "C"+(_16.x-(_15-1)*(dx/_15))+","+dy+" "+(_16.x-(dx/_15))+","+_16.y+" "+_16.x+","+_16.y; |
153 |
}else{
|
154 |
if(_15=="X"||_15=="x"||_15=="S"){ |
155 |
var p0,p1=arr[i-1],p2=arr[i],p3; |
156 |
var _17,_18,_19,_1a;
|
157 |
var f=1/6; |
158 |
if(i==1){ |
159 |
if(_15=="x"){ |
160 |
p0=arr[arr.length-2];
|
161 |
}else{
|
162 |
p0=p1; |
163 |
} |
164 |
f=1/3; |
165 |
}else{
|
166 |
p0=arr[i-2];
|
167 |
} |
168 |
if(i==(arr.length-1)){ |
169 |
if(_15=="x"){ |
170 |
p3=arr[1];
|
171 |
}else{
|
172 |
p3=p2; |
173 |
} |
174 |
f=1/3; |
175 |
}else{
|
176 |
p3=arr[i+1];
|
177 |
} |
178 |
var _1b=Math.sqrt((p2.x-p1.x)*(p2.x-p1.x)+(p2.y-p1.y)*(p2.y-p1.y));
|
179 |
var _1c=Math.sqrt((p2.x-p0.x)*(p2.x-p0.x)+(p2.y-p0.y)*(p2.y-p0.y));
|
180 |
var _1d=Math.sqrt((p3.x-p1.x)*(p3.x-p1.x)+(p3.y-p1.y)*(p3.y-p1.y));
|
181 |
var _1e=_1c*f;
|
182 |
var _1f=_1d*f;
|
183 |
if(_1e>_1b/2&&_1f>_1b/2){ |
184 |
_1e=_1b/2;
|
185 |
_1f=_1b/2;
|
186 |
}else{
|
187 |
if(_1e>_1b/2){ |
188 |
_1e=_1b/2;
|
189 |
_1f=_1b/2*_1d/_1c;
|
190 |
}else{
|
191 |
if(_1f>_1b/2){ |
192 |
_1f=_1b/2;
|
193 |
_1e=_1b/2*_1c/_1d;
|
194 |
} |
195 |
} |
196 |
} |
197 |
if(_15=="S"){ |
198 |
if(p0==p1){
|
199 |
_1e=0;
|
200 |
} |
201 |
if(p2==p3){
|
202 |
_1f=0;
|
203 |
} |
204 |
} |
205 |
_17=p1.x+_1e*(p2.x-p0.x)/_1c; |
206 |
_18=p1.y+_1e*(p2.y-p0.y)/_1c; |
207 |
_19=p2.x-_1f*(p3.x-p1.x)/_1d; |
208 |
_1a=p2.y-_1f*(p3.y-p1.y)/_1d; |
209 |
} |
210 |
} |
211 |
return "C"+(_17+","+_18+" "+_19+","+_1a+" "+p2.x+","+p2.y); |
212 |
}); |
213 |
return p.join(" "); |
214 |
}}); |
215 |
})(); |
216 |
} |