Project

General

Profile

Statistics
| Revision:

root / trunk / web / dojo / dojox / charting / DataChart.js @ 12

History | View | Annotate | Download (6.13 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.DataChart"]){
9
dojo._hasResource["dojox.charting.DataChart"]=true;
10
dojo.provide("dojox.charting.DataChart");
11
dojo.require("dojox.charting.Chart2D");
12
dojo.require("dojox.charting.themes.PlotKit.blue");
13
dojo.experimental("dojox.charting.DataChart");
14
(function(){
15
var _1={vertical:true,min:0,max:10,majorTickStep:5,minorTickStep:1,natural:false,stroke:"black",majorTick:{stroke:"black",length:8},minorTick:{stroke:"gray",length:2},majorLabels:true};
16
var _2={natural:true,majorLabels:true,includeZero:false,majorTickStep:1,majorTick:{stroke:"black",length:8},fixUpper:"major",stroke:"black",htmlLabels:true,from:1};
17
var _3={markers:true,tension:2,gap:2};
18
dojo.declare("dojox.charting.DataChart",[dojox.charting.Chart2D],{scroll:true,comparative:false,query:"*",queryOptions:"",fieldName:"value",chartTheme:dojox.charting.themes.PlotKit.blue,displayRange:0,stretchToFit:true,minWidth:200,minHeight:100,showing:true,label:"name",constructor:function(_4,_5){
19
this.domNode=dojo.byId(_4);
20
dojo.mixin(this,_5);
21
this.xaxis=dojo.mixin(dojo.mixin({},_2),_5.xaxis);
22
if(this.xaxis.labelFunc=="seriesLabels"){
23
this.xaxis.labelFunc=dojo.hitch(this,"seriesLabels");
24
}
25
this.yaxis=dojo.mixin(dojo.mixin({},_1),_5.yaxis);
26
if(this.yaxis.labelFunc=="seriesLabels"){
27
this.yaxis.labelFunc=dojo.hitch(this,"seriesLabels");
28
}
29
this._events=[];
30
this.convertLabels(this.yaxis);
31
this.convertLabels(this.xaxis);
32
this.onSetItems={};
33
this.onSetInterval=0;
34
this.dataLength=0;
35
this.seriesData={};
36
this.seriesDataBk={};
37
this.firstRun=true;
38
this.dataOffset=0;
39
this.chartTheme.plotarea.stroke={color:"gray",width:3};
40
this.setTheme(this.chartTheme);
41
if(this.displayRange){
42
this.stretchToFit=false;
43
}
44
if(!this.stretchToFit){
45
this.xaxis.to=this.displayRange;
46
}
47
this.addAxis("x",this.xaxis);
48
this.addAxis("y",this.yaxis);
49
_3.type=_5.type||"Markers";
50
this.addPlot("default",dojo.mixin(_3,_5.chartPlot));
51
this.addPlot("grid",dojo.mixin(_5.grid||{},{type:"Grid",hMinorLines:true}));
52
if(this.showing){
53
this.render();
54
}
55
if(_5.store){
56
this.setStore(_5.store,_5.query,_5.fieldName,_5.queryOptions);
57
}
58
},destroy:function(){
59
dojo.forEach(this._events,dojo.disconnect);
60
this.inherited(arguments);
61
},setStore:function(_6,_7,_8,_9){
62
this.firstRun=true;
63
this.store=_6||this.store;
64
this.query=_7||this.query;
65
this.fieldName=_8||this.fieldName;
66
this.label=this.store.getLabelAttributes();
67
this.queryOptions=_9||_9;
68
dojo.forEach(this._events,dojo.disconnect);
69
this._events=[dojo.connect(this.store,"onSet",this,"onSet"),dojo.connect(this.store,"onError",this,"onError")];
70
this.fetch();
71
},show:function(){
72
if(!this.showing){
73
dojo.style(this.domNode,"display","");
74
this.showing=true;
75
this.render();
76
}
77
},hide:function(){
78
if(this.showing){
79
dojo.style(this.domNode,"display","none");
80
this.showing=false;
81
}
82
},onSet:function(_a){
83
var nm=this.getProperty(_a,this.label);
84
if(nm in this.runs||this.comparative){
85
clearTimeout(this.onSetInterval);
86
if(!this.onSetItems[nm]){
87
this.onSetItems[nm]=_a;
88
}
89
this.onSetInterval=setTimeout(dojo.hitch(this,function(){
90
clearTimeout(this.onSetInterval);
91
var _b=[];
92
for(var nm in this.onSetItems){
93
_b.push(this.onSetItems[nm]);
94
}
95
this.onData(_b);
96
this.onSetItems={};
97
}),200);
98
}
99
},onError:function(_c){
100
console.error("DataChart Error:",_c);
101
},onDataReceived:function(_d){
102
},getProperty:function(_e,_f){
103
if(_f==this.label){
104
return this.store.getLabel(_e);
105
}
106
if(_f=="id"){
107
return this.store.getIdentity(_e);
108
}
109
var _10=this.store.getValues(_e,_f);
110
if(_10.length<2){
111
_10=this.store.getValue(_e,_f);
112
}
113
return _10;
114
},onData:function(_11){
115
if(!_11||!_11.length){
116
return;
117
}
118
if(this.items&&this.items.length!=_11.length){
119
dojo.forEach(_11,function(m){
120
var id=this.getProperty(m,"id");
121
dojo.forEach(this.items,function(m2,i){
122
if(this.getProperty(m2,"id")==id){
123
this.items[i]=m2;
124
}
125
},this);
126
},this);
127
_11=this.items;
128
}
129
if(this.stretchToFit){
130
this.displayRange=_11.length;
131
}
132
this.onDataReceived(_11);
133
this.items=_11;
134
if(this.comparative){
135
var nm="default";
136
this.seriesData[nm]=[];
137
this.seriesDataBk[nm]=[];
138
dojo.forEach(_11,function(m,i){
139
var _12=this.getProperty(m,this.fieldName);
140
this.seriesData[nm].push(_12);
141
},this);
142
}else{
143
dojo.forEach(_11,function(m,i){
144
var nm=this.store.getLabel(m);
145
if(!this.seriesData[nm]){
146
this.seriesData[nm]=[];
147
this.seriesDataBk[nm]=[];
148
}
149
var _13=this.getProperty(m,this.fieldName);
150
if(dojo.isArray(_13)){
151
this.seriesData[nm]=_13;
152
}else{
153
if(!this.scroll){
154
var ar=dojo.map(new Array(i+1),function(){
155
return 0;
156
});
157
ar.push(Number(_13));
158
this.seriesData[nm]=ar;
159
}else{
160
if(this.seriesDataBk[nm].length>this.seriesData[nm].length){
161
this.seriesData[nm]=this.seriesDataBk[nm];
162
}
163
this.seriesData[nm].push(Number(_13));
164
}
165
this.seriesDataBk[nm].push(Number(_13));
166
}
167
},this);
168
}
169
var _14;
170
if(this.firstRun){
171
this.firstRun=false;
172
for(nm in this.seriesData){
173
this.addSeries(nm,this.seriesData[nm]);
174
_14=this.seriesData[nm];
175
}
176
}else{
177
for(nm in this.seriesData){
178
_14=this.seriesData[nm];
179
if(this.scroll&&_14.length>this.displayRange){
180
this.dataOffset=_14.length-this.displayRange-1;
181
_14=_14.slice(_14.length-this.displayRange,_14.length);
182
}
183
this.updateSeries(nm,_14);
184
}
185
}
186
this.dataLength=_14.length;
187
if(this.showing){
188
this.render();
189
}
190
},fetch:function(){
191
if(!this.store){
192
return;
193
}
194
this.store.fetch({query:this.query,queryOptions:this.queryOptions,start:this.start,count:this.count,sort:this.sort,onComplete:dojo.hitch(this,function(_15){
195
setTimeout(dojo.hitch(this,function(){
196
this.onData(_15);
197
}),0);
198
}),onError:dojo.hitch(this,"onError")});
199
},convertLabels:function(_16){
200
if(!_16.labels||dojo.isObject(_16.labels[0])){
201
return null;
202
}
203
_16.labels=dojo.map(_16.labels,function(ele,i){
204
return {value:i,text:ele};
205
});
206
return null;
207
},seriesLabels:function(val){
208
val--;
209
if(this.series.length<1||(!this.comparative&&val>this.series.length)){
210
return "-";
211
}
212
if(this.comparative){
213
return this.store.getLabel(this.items[val]);
214
}else{
215
for(var i=0;i<this.series.length;i++){
216
if(this.series[i].data[val]>0){
217
return this.series[i].name;
218
}
219
}
220
}
221
return "-";
222
},resizeChart:function(dim){
223
var w=Math.max(dim.w,this.minWidth);
224
var h=Math.max(dim.h,this.minHeight);
225
this.resize(w,h);
226
}});
227
})();
228
}