root / trunk / web / dojo / dojox / charting / DataSeries.js
History | View | Annotate | Download (2.89 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.DataSeries"]){ |
9 |
dojo._hasResource["dojox.charting.DataSeries"]=true; |
10 |
dojo.provide("dojox.charting.DataSeries");
|
11 |
dojo.require("dojox.lang.functional");
|
12 |
dojo.declare("dojox.charting.DataSeries",null,{constructor:function(_1,_2,_3){ |
13 |
this.store=_1;
|
14 |
this.kwArgs=_2;
|
15 |
if(_3){
|
16 |
if(dojo.isFunction(_3)){
|
17 |
this.value=_3;
|
18 |
}else{
|
19 |
if(dojo.isObject(_3)){
|
20 |
this.value=dojo.hitch(this,"_dictValue",dojox.lang.functional.keys(_3),_3); |
21 |
}else{
|
22 |
this.value=dojo.hitch(this,"_fieldValue",_3); |
23 |
} |
24 |
} |
25 |
}else{
|
26 |
this.value=dojo.hitch(this,"_defaultValue"); |
27 |
} |
28 |
this.data=[];
|
29 |
this._events=[];
|
30 |
if(this.store.getFeatures()["dojo.data.api.Notification"]){ |
31 |
this._events.push(dojo.connect(this.store,"onNew",this,"_onStoreNew"),dojo.connect(this.store,"onDelete",this,"_onStoreDelete"),dojo.connect(this.store,"onSet",this,"_onStoreSet")); |
32 |
} |
33 |
this.fetch();
|
34 |
},destroy:function(){ |
35 |
dojo.forEach(this._events,dojo.disconnect);
|
36 |
},setSeriesObject:function(_4){ |
37 |
this.series=_4;
|
38 |
},_dictValue:function(_5,_6,_7,_8){ |
39 |
var o={};
|
40 |
dojo.forEach(_5,function(_9){
|
41 |
o[_9]=_7.getValue(_8,_6[_9]); |
42 |
}); |
43 |
return o;
|
44 |
},_fieldValue:function(_a,_b,_c){ |
45 |
return _b.getValue(_c,_a);
|
46 |
},_defaultValue:function(_d,_e){ |
47 |
return _d.getValue(_e,"value"); |
48 |
},fetch:function(){ |
49 |
if(!this._inFlight){ |
50 |
this._inFlight=true; |
51 |
var _f=dojo.delegate(this.kwArgs); |
52 |
_f.onComplete=dojo.hitch(this,"_onFetchComplete"); |
53 |
_f.onError=dojo.hitch(this,"onFetchError"); |
54 |
this.store.fetch(_f);
|
55 |
} |
56 |
},_onFetchComplete:function(_10,_11){ |
57 |
this.items=_10;
|
58 |
this._buildItemMap();
|
59 |
this.data=dojo.map(this.items,function(_12){ |
60 |
return this.value(this.store,_12); |
61 |
},this);
|
62 |
this._pushDataChanges();
|
63 |
this._inFlight=false; |
64 |
},onFetchError:function(_13,_14){ |
65 |
this._inFlight=false; |
66 |
},_buildItemMap:function(){ |
67 |
if(this.store.getFeatures()["dojo.data.api.Identity"]){ |
68 |
var _15={};
|
69 |
dojo.forEach(this.items,function(_16,_17){ |
70 |
_15[this.store.getIdentity(_16)]=_17;
|
71 |
},this);
|
72 |
this.itemMap=_15;
|
73 |
} |
74 |
},_pushDataChanges:function(){ |
75 |
if(this.series){ |
76 |
this.series.chart.updateSeries(this.series.name,this); |
77 |
this.series.chart.delayedRender();
|
78 |
} |
79 |
},_onStoreNew:function(){ |
80 |
this.fetch();
|
81 |
},_onStoreDelete:function(_18){ |
82 |
if(this.items){ |
83 |
var _19=dojo.some(this.items,function(it,_1a){ |
84 |
if(it===_18){
|
85 |
this.items.splice(_1a,1); |
86 |
this._buildItemMap();
|
87 |
this.data.splice(_1a,1); |
88 |
return true; |
89 |
} |
90 |
return false; |
91 |
},this);
|
92 |
if(_19){
|
93 |
this._pushDataChanges();
|
94 |
} |
95 |
} |
96 |
},_onStoreSet:function(_1b){ |
97 |
if(this.itemMap){ |
98 |
var id=this.store.getIdentity(_1b),_1c=this.itemMap[id]; |
99 |
if(typeof _1c=="number"){ |
100 |
this.data[_1c]=this.value(this.store,this.items[_1c]); |
101 |
this._pushDataChanges();
|
102 |
} |
103 |
}else{
|
104 |
if(this.items){ |
105 |
var _1d=dojo.some(this.items,function(it,_1e){ |
106 |
if(it===_1b){
|
107 |
this.data[_1e]=this.value(this.store,it); |
108 |
return true; |
109 |
} |
110 |
return false; |
111 |
},this);
|
112 |
if(_1d){
|
113 |
this._pushDataChanges();
|
114 |
} |
115 |
} |
116 |
} |
117 |
}}); |
118 |
} |