Project

General

Profile

Statistics
| Revision:

root / trunk / web / dojo / dojox / charting / scaler / linear.js

History | View | Annotate | Download (5.3 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.scaler.linear"]){
9
dojo._hasResource["dojox.charting.scaler.linear"]=true;
10
dojo.provide("dojox.charting.scaler.linear");
11
dojo.require("dojox.charting.scaler.common");
12
(function(){
13
var _1=3,dc=dojox.charting,_2=dc.scaler,_3=_2.common,_4=_3.findString,_5=_3.getNumericLabel;
14
var _6=function(_7,_8,_9,_a,_b,_c,_d){
15
_9=dojo.delegate(_9);
16
if(!_a){
17
if(_9.fixUpper=="major"){
18
_9.fixUpper="minor";
19
}
20
if(_9.fixLower=="major"){
21
_9.fixLower="minor";
22
}
23
}
24
if(!_b){
25
if(_9.fixUpper=="minor"){
26
_9.fixUpper="micro";
27
}
28
if(_9.fixLower=="minor"){
29
_9.fixLower="micro";
30
}
31
}
32
if(!_c){
33
if(_9.fixUpper=="micro"){
34
_9.fixUpper="none";
35
}
36
if(_9.fixLower=="micro"){
37
_9.fixLower="none";
38
}
39
}
40
var _e=_4(_9.fixLower,["major"])?Math.floor(_9.min/_a)*_a:_4(_9.fixLower,["minor"])?Math.floor(_9.min/_b)*_b:_4(_9.fixLower,["micro"])?Math.floor(_9.min/_c)*_c:_9.min,_f=_4(_9.fixUpper,["major"])?Math.ceil(_9.max/_a)*_a:_4(_9.fixUpper,["minor"])?Math.ceil(_9.max/_b)*_b:_4(_9.fixUpper,["micro"])?Math.ceil(_9.max/_c)*_c:_9.max;
41
if(_9.useMin){
42
_7=_e;
43
}
44
if(_9.useMax){
45
_8=_f;
46
}
47
var _10=(!_a||_9.useMin&&_4(_9.fixLower,["major"]))?_7:Math.ceil(_7/_a)*_a,_11=(!_b||_9.useMin&&_4(_9.fixLower,["major","minor"]))?_7:Math.ceil(_7/_b)*_b,_12=(!_c||_9.useMin&&_4(_9.fixLower,["major","minor","micro"]))?_7:Math.ceil(_7/_c)*_c,_13=!_a?0:(_9.useMax&&_4(_9.fixUpper,["major"])?Math.round((_8-_10)/_a):Math.floor((_8-_10)/_a))+1,_14=!_b?0:(_9.useMax&&_4(_9.fixUpper,["major","minor"])?Math.round((_8-_11)/_b):Math.floor((_8-_11)/_b))+1,_15=!_c?0:(_9.useMax&&_4(_9.fixUpper,["major","minor","micro"])?Math.round((_8-_12)/_c):Math.floor((_8-_12)/_c))+1,_16=_b?Math.round(_a/_b):0,_17=_c?Math.round(_b/_c):0,_18=_a?Math.floor(Math.log(_a)/Math.LN10):0,_19=_b?Math.floor(Math.log(_b)/Math.LN10):0,_1a=_d/(_8-_7);
48
if(!isFinite(_1a)){
49
_1a=1;
50
}
51
return {bounds:{lower:_e,upper:_f,from:_7,to:_8,scale:_1a,span:_d},major:{tick:_a,start:_10,count:_13,prec:_18},minor:{tick:_b,start:_11,count:_14,prec:_19},micro:{tick:_c,start:_12,count:_15,prec:0},minorPerMajor:_16,microPerMinor:_17,scaler:_2.linear};
52
};
53
dojo.mixin(dojox.charting.scaler.linear,{buildScaler:function(min,max,_1b,_1c){
54
var h={fixUpper:"none",fixLower:"none",natural:false};
55
if(_1c){
56
if("fixUpper" in _1c){
57
h.fixUpper=String(_1c.fixUpper);
58
}
59
if("fixLower" in _1c){
60
h.fixLower=String(_1c.fixLower);
61
}
62
if("natural" in _1c){
63
h.natural=Boolean(_1c.natural);
64
}
65
}
66
if("min" in _1c){
67
min=_1c.min;
68
}
69
if("max" in _1c){
70
max=_1c.max;
71
}
72
if(_1c.includeZero){
73
if(min>0){
74
min=0;
75
}
76
if(max<0){
77
max=0;
78
}
79
}
80
h.min=min;
81
h.useMin=true;
82
h.max=max;
83
h.useMax=true;
84
if("from" in _1c){
85
min=_1c.from;
86
h.useMin=false;
87
}
88
if("to" in _1c){
89
max=_1c.to;
90
h.useMax=false;
91
}
92
if(max<=min){
93
return _6(min,max,h,0,0,0,_1b);
94
}
95
var mag=Math.floor(Math.log(max-min)/Math.LN10),_1d=_1c&&("majorTickStep" in _1c)?_1c.majorTickStep:Math.pow(10,mag),_1e=0,_1f=0,_20;
96
if(_1c&&("minorTickStep" in _1c)){
97
_1e=_1c.minorTickStep;
98
}else{
99
do{
100
_1e=_1d/10;
101
if(!h.natural||_1e>0.9){
102
_20=_6(min,max,h,_1d,_1e,0,_1b);
103
if(_20.bounds.scale*_20.minor.tick>_1){
104
break;
105
}
106
}
107
_1e=_1d/5;
108
if(!h.natural||_1e>0.9){
109
_20=_6(min,max,h,_1d,_1e,0,_1b);
110
if(_20.bounds.scale*_20.minor.tick>_1){
111
break;
112
}
113
}
114
_1e=_1d/2;
115
if(!h.natural||_1e>0.9){
116
_20=_6(min,max,h,_1d,_1e,0,_1b);
117
if(_20.bounds.scale*_20.minor.tick>_1){
118
break;
119
}
120
}
121
return _6(min,max,h,_1d,0,0,_1b);
122
}while(false);
123
}
124
if(_1c&&("microTickStep" in _1c)){
125
_1f=_1c.microTickStep;
126
_20=_6(min,max,h,_1d,_1e,_1f,_1b);
127
}else{
128
do{
129
_1f=_1e/10;
130
if(!h.natural||_1f>0.9){
131
_20=_6(min,max,h,_1d,_1e,_1f,_1b);
132
if(_20.bounds.scale*_20.micro.tick>_1){
133
break;
134
}
135
}
136
_1f=_1e/5;
137
if(!h.natural||_1f>0.9){
138
_20=_6(min,max,h,_1d,_1e,_1f,_1b);
139
if(_20.bounds.scale*_20.micro.tick>_1){
140
break;
141
}
142
}
143
_1f=_1e/2;
144
if(!h.natural||_1f>0.9){
145
_20=_6(min,max,h,_1d,_1e,_1f,_1b);
146
if(_20.bounds.scale*_20.micro.tick>_1){
147
break;
148
}
149
}
150
_1f=0;
151
}while(false);
152
}
153
return _1f?_20:_6(min,max,h,_1d,_1e,0,_1b);
154
},buildTicks:function(_21,_22){
155
var _23,_24,_25,_26=_21.major.start,_27=_21.minor.start,_28=_21.micro.start;
156
if(_22.microTicks&&_21.micro.tick){
157
_23=_21.micro.tick,_24=_28;
158
}else{
159
if(_22.minorTicks&&_21.minor.tick){
160
_23=_21.minor.tick,_24=_27;
161
}else{
162
if(_21.major.tick){
163
_23=_21.major.tick,_24=_26;
164
}else{
165
return null;
166
}
167
}
168
}
169
var _29=1/_21.bounds.scale;
170
if(_21.bounds.to<=_21.bounds.from||isNaN(_29)||!isFinite(_29)||_23<=0||isNaN(_23)||!isFinite(_23)){
171
return null;
172
}
173
var _2a=[],_2b=[],_2c=[];
174
while(_24<=_21.bounds.to+_29){
175
if(Math.abs(_26-_24)<_23/2){
176
_25={value:_26};
177
if(_22.majorLabels){
178
_25.label=_5(_26,_21.major.prec,_22);
179
}
180
_2a.push(_25);
181
_26+=_21.major.tick;
182
_27+=_21.minor.tick;
183
_28+=_21.micro.tick;
184
}else{
185
if(Math.abs(_27-_24)<_23/2){
186
if(_22.minorTicks){
187
_25={value:_27};
188
if(_22.minorLabels&&(_21.minMinorStep<=_21.minor.tick*_21.bounds.scale)){
189
_25.label=_5(_27,_21.minor.prec,_22);
190
}
191
_2b.push(_25);
192
}
193
_27+=_21.minor.tick;
194
_28+=_21.micro.tick;
195
}else{
196
if(_22.microTicks){
197
_2c.push({value:_28});
198
}
199
_28+=_21.micro.tick;
200
}
201
}
202
_24+=_23;
203
}
204
return {major:_2a,minor:_2b,micro:_2c};
205
},getTransformerFromModel:function(_2d){
206
var _2e=_2d.bounds.from,_2f=_2d.bounds.scale;
207
return function(x){
208
return (x-_2e)*_2f;
209
};
210
},getTransformerFromPlot:function(_30){
211
var _31=_30.bounds.from,_32=_30.bounds.scale;
212
return function(x){
213
return x/_32+_31;
214
};
215
}});
216
})();
217
}