Project

General

Profile

Statistics
| Revision:

root / trunk / web / dojo / dojox / charting / axis2d / Default.js @ 12

History | View | Annotate | Download (7.19 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.axis2d.Default"]){
9
dojo._hasResource["dojox.charting.axis2d.Default"]=true;
10
dojo.provide("dojox.charting.axis2d.Default");
11
dojo.require("dojox.charting.axis2d.Invisible");
12
dojo.require("dojox.charting.scaler.linear");
13
dojo.require("dojox.charting.axis2d.common");
14
dojo.require("dojo.colors");
15
dojo.require("dojo.string");
16
dojo.require("dojox.gfx");
17
dojo.require("dojox.lang.functional");
18
dojo.require("dojox.lang.utils");
19
(function(){
20
var dc=dojox.charting,du=dojox.lang.utils,g=dojox.gfx,_1=dc.scaler.linear,_2=4,_3=45;
21
dojo.declare("dojox.charting.axis2d.Default",dojox.charting.axis2d.Invisible,{defaultParams:{vertical:false,fixUpper:"none",fixLower:"none",natural:false,leftBottom:true,includeZero:false,fixed:true,majorLabels:true,minorTicks:true,minorLabels:true,microTicks:false,rotation:0,htmlLabels:true},optionalParams:{min:0,max:1,from:0,to:1,majorTickStep:4,minorTickStep:2,microTickStep:1,labels:[],labelFunc:null,maxLabelSize:0,stroke:{},majorTick:{},minorTick:{},microTick:{},tick:{},font:"",fontColor:""},constructor:function(_4,_5){
22
this.opt=dojo.delegate(this.defaultParams,_5);
23
du.updateWithPattern(this.opt,_5,this.optionalParams);
24
},getOffsets:function(){
25
var s=this.scaler,_6={l:0,r:0,t:0,b:0};
26
if(!s){
27
return _6;
28
}
29
var o=this.opt,_7=0,a,b,c,d,gl=dc.scaler.common.getNumericLabel,_8=0,ma=s.major,mi=s.minor,ta=this.chart.theme.axis,_9=o.font||(ta.majorTick&&ta.majorTick.font)||(ta.tick&&ta.tick.font),_a=this.chart.theme.getTick("major",o),_b=this.chart.theme.getTick("minor",o),_c=_9?g.normalizedLength(g.splitFontString(_9).size):0,_d=o.rotation%360,_e=o.leftBottom,_f=Math.abs(Math.cos(_d*Math.PI/180)),_10=Math.abs(Math.sin(_d*Math.PI/180));
30
if(_d<0){
31
_d+=360;
32
}
33
if(_c){
34
if(o.maxLabelSize){
35
_7=o.maxLabelSize;
36
}else{
37
if(this.labels){
38
_7=this._groupLabelWidth(this.labels,_9);
39
}else{
40
_7=this._groupLabelWidth([gl(ma.start,ma.prec,o),gl(ma.start+ma.count*ma.tick,ma.prec,o),gl(mi.start,mi.prec,o),gl(mi.start+mi.count*mi.tick,mi.prec,o)],_9);
41
}
42
}
43
if(this.vertical){
44
var _11=_e?"l":"r";
45
switch(_d){
46
case 0:
47
case 180:
48
_6[_11]=_7;
49
_6.t=_6.b=_c/2;
50
break;
51
case 90:
52
case 270:
53
_6[_11]=_c;
54
_6.t=_6.b=_7/2;
55
break;
56
default:
57
if(_d<=_3||(180<_d&&_d<=(180+_3))){
58
_6[_11]=_c*_10/2+_7*_f;
59
_6[_e?"t":"b"]=_c*_f/2+_7*_10;
60
_6[_e?"b":"t"]=_c*_f/2;
61
}else{
62
if(_d>(360-_3)||(180>_d&&_d>(180-_3))){
63
_6[_11]=_c*_10/2+_7*_f;
64
_6[_e?"b":"t"]=_c*_f/2+_7*_10;
65
_6[_e?"t":"b"]=_c*_f/2;
66
}else{
67
if(_d<90||(180<_d&&_d<270)){
68
_6[_11]=_c*_10+_7*_f;
69
_6[_e?"t":"b"]=_c*_f+_7*_10;
70
}else{
71
_6[_11]=_c*_10+_7*_f;
72
_6[_e?"b":"t"]=_c*_f+_7*_10;
73
}
74
}
75
}
76
break;
77
}
78
_6[_11]+=_2+Math.max(_a.length,_b.length);
79
}else{
80
var _11=_e?"b":"t";
81
switch(_d){
82
case 0:
83
case 180:
84
_6[_11]=_c;
85
_6.l=_6.r=_7/2;
86
break;
87
case 90:
88
case 270:
89
_6[_11]=_7;
90
_6.l=_6.r=_c/2;
91
break;
92
default:
93
if((90-_3)<=_d&&_d<=90||(270-_3)<=_d&&_d<=270){
94
_6[_11]=_c*_10/2+_7*_f;
95
_6[_e?"r":"l"]=_c*_f/2+_7*_10;
96
_6[_e?"l":"r"]=_c*_f/2;
97
}else{
98
if(90<=_d&&_d<=(90+_3)||270<=_d&&_d<=(270+_3)){
99
_6[_11]=_c*_10/2+_7*_f;
100
_6[_e?"l":"r"]=_c*_f/2+_7*_10;
101
_6[_e?"r":"l"]=_c*_f/2;
102
}else{
103
if(_d<_3||(180<_d&&_d<(180-_3))){
104
_6[_11]=_c*_10+_7*_f;
105
_6[_e?"r":"l"]=_c*_f+_7*_10;
106
}else{
107
_6[_11]=_c*_10+_7*_f;
108
_6[_e?"l":"r"]=_c*_f+_7*_10;
109
}
110
}
111
}
112
break;
113
}
114
_6[_11]+=_2+Math.max(_a.length,_b.length);
115
}
116
}
117
if(_7){
118
this._cachedLabelWidth=_7;
119
}
120
return _6;
121
},render:function(dim,_12){
122
if(!this.dirty){
123
return this;
124
}
125
var o=this.opt,ta=this.chart.theme.axis,_13=o.leftBottom,_14=o.rotation%360,_15,_16,_17,_18,_19,_1a,_1b,_1c=o.font||(ta.majorTick&&ta.majorTick.font)||(ta.tick&&ta.tick.font),_1d=o.fontColor||(ta.majorTick&&ta.majorTick.fontColor)||(ta.tick&&ta.tick.fontColor)||"black",_1e=this.chart.theme.getTick("major",o),_1f=this.chart.theme.getTick("minor",o),_20=this.chart.theme.getTick("micro",o),_21=Math.max(_1e.length,_1f.length,_20.length),_22="stroke" in o?o.stroke:ta.stroke,_23=_1c?g.normalizedLength(g.splitFontString(_1c).size):0;
126
if(_14<0){
127
_14+=360;
128
}
129
if(this.vertical){
130
_15={y:dim.height-_12.b};
131
_16={y:_12.t};
132
_17={x:0,y:-1};
133
_1a={x:0,y:0};
134
_18={x:1,y:0};
135
_19={x:_2,y:0};
136
switch(_14){
137
case 0:
138
_1b="end";
139
_1a.y=_23*0.4;
140
break;
141
case 90:
142
_1b="middle";
143
_1a.x=-_23;
144
break;
145
case 180:
146
_1b="start";
147
_1a.y=-_23*0.4;
148
break;
149
case 270:
150
_1b="middle";
151
break;
152
default:
153
if(_14<_3){
154
_1b="end";
155
_1a.y=_23*0.4;
156
}else{
157
if(_14<90){
158
_1b="end";
159
_1a.y=_23*0.4;
160
}else{
161
if(_14<(180-_3)){
162
_1b="start";
163
}else{
164
if(_14<(180+_3)){
165
_1b="start";
166
_1a.y=-_23*0.4;
167
}else{
168
if(_14<270){
169
_1b="start";
170
_1a.x=_13?0:_23*0.4;
171
}else{
172
if(_14<(360-_3)){
173
_1b="end";
174
_1a.x=_13?0:_23*0.4;
175
}else{
176
_1b="end";
177
_1a.y=_23*0.4;
178
}
179
}
180
}
181
}
182
}
183
}
184
}
185
if(_13){
186
_15.x=_16.x=_12.l;
187
_18.x=-1;
188
_19.x=-_19.x;
189
}else{
190
_15.x=_16.x=dim.width-_12.r;
191
switch(_1b){
192
case "start":
193
_1b="end";
194
break;
195
case "end":
196
_1b="start";
197
break;
198
case "middle":
199
_1a.x+=_23;
200
break;
201
}
202
}
203
}else{
204
_15={x:_12.l};
205
_16={x:dim.width-_12.r};
206
_17={x:1,y:0};
207
_1a={x:0,y:0};
208
_18={x:0,y:1};
209
_19={x:0,y:_2};
210
switch(_14){
211
case 0:
212
_1b="middle";
213
_1a.y=_23;
214
break;
215
case 90:
216
_1b="start";
217
_1a.x=-_23*0.4;
218
break;
219
case 180:
220
_1b="middle";
221
break;
222
case 270:
223
_1b="end";
224
_1a.x=_23*0.4;
225
break;
226
default:
227
if(_14<(90-_3)){
228
_1b="start";
229
_1a.y=_13?_23:0;
230
}else{
231
if(_14<(90+_3)){
232
_1b="start";
233
_1a.x=-_23*0.4;
234
}else{
235
if(_14<180){
236
_1b="start";
237
_1a.y=_13?0:-_23;
238
}else{
239
if(_14<(270-_3)){
240
_1b="end";
241
_1a.y=_13?0:-_23;
242
}else{
243
if(_14<(270+_3)){
244
_1b="end";
245
_1a.y=_13?_23*0.4:0;
246
}else{
247
_1b="end";
248
_1a.y=_13?_23:0;
249
}
250
}
251
}
252
}
253
}
254
}
255
if(_13){
256
_15.y=_16.y=dim.height-_12.b;
257
}else{
258
_15.y=_16.y=_12.t;
259
_18.y=-1;
260
_19.y=-_19.y;
261
switch(_1b){
262
case "start":
263
_1b="end";
264
break;
265
case "end":
266
_1b="start";
267
break;
268
case "middle":
269
_1a.y-=_23;
270
break;
271
}
272
}
273
}
274
this.cleanGroup();
275
try{
276
var s=this.group,c=this.scaler,t=this.ticks,_24,f=_1.getTransformerFromModel(this.scaler),_25=(dojox.gfx.renderer=="canvas"),_26=_25||!_14&&this.opt.htmlLabels&&!dojo.isIE&&!dojo.isOpera?"html":"gfx",dx=_18.x*_1e.length,dy=_18.y*_1e.length;
277
s.createLine({x1:_15.x,y1:_15.y,x2:_16.x,y2:_16.y}).setStroke(_22);
278
dojo.forEach(t.major,function(_27){
279
var _28=f(_27.value),_29,x=_15.x+_17.x*_28,y=_15.y+_17.y*_28;
280
s.createLine({x1:x,y1:y,x2:x+dx,y2:y+dy}).setStroke(_1e);
281
if(_27.label){
282
_29=dc.axis2d.common.createText[_26](this.chart,s,x+dx+_19.x+(_14?0:_1a.x),y+dy+_19.y+(_14?0:_1a.y),_1b,_27.label,_1c,_1d);
283
if(_26=="html"){
284
this.htmlElements.push(_29);
285
}else{
286
if(_14){
287
_29.setTransform([{dx:_1a.x,dy:_1a.y},g.matrix.rotategAt(_14,x+dx+_19.x,y+dy+_19.y)]);
288
}
289
}
290
}
291
},this);
292
dx=_18.x*_1f.length;
293
dy=_18.y*_1f.length;
294
_24=c.minMinorStep<=c.minor.tick*c.bounds.scale;
295
dojo.forEach(t.minor,function(_2a){
296
var _2b=f(_2a.value),_2c,x=_15.x+_17.x*_2b,y=_15.y+_17.y*_2b;
297
s.createLine({x1:x,y1:y,x2:x+dx,y2:y+dy}).setStroke(_1f);
298
if(_24&&_2a.label){
299
_2c=dc.axis2d.common.createText[_26](this.chart,s,x+dx+_19.x+(_14?0:_1a.x),y+dy+_19.y+(_14?0:_1a.y),_1b,_2a.label,_1c,_1d);
300
if(_26=="html"){
301
this.htmlElements.push(_2c);
302
}else{
303
if(_14){
304
_2c.setTransform([{dx:_1a.x,dy:_1a.y},g.matrix.rotategAt(_14,x+dx+_19.x,y+dy+_19.y)]);
305
}
306
}
307
}
308
},this);
309
dx=_18.x*_20.length;
310
dy=_18.y*_20.length;
311
dojo.forEach(t.micro,function(_2d){
312
var _2e=f(_2d.value),_2f,x=_15.x+_17.x*_2e,y=_15.y+_17.y*_2e;
313
s.createLine({x1:x,y1:y,x2:x+dx,y2:y+dy}).setStroke(_20);
314
},this);
315
}
316
catch(e){
317
}
318
this.dirty=false;
319
return this;
320
}});
321
})();
322
}