root / trunk / web / dojo / dojox / widget / DataPresentation.js @ 13
History | View | Annotate | Download (9.92 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.widget.DataPresentation"]){ |
9 |
dojo._hasResource["dojox.widget.DataPresentation"]=true; |
10 |
dojo.provide("dojox.widget.DataPresentation");
|
11 |
dojo.experimental("dojox.widget.DataPresentation");
|
12 |
dojo.require("dojox.grid.DataGrid");
|
13 |
dojo.require("dojox.charting.Chart2D");
|
14 |
dojo.require("dojox.charting.widget.Legend");
|
15 |
dojo.require("dojox.charting.action2d.Tooltip");
|
16 |
dojo.require("dojox.charting.action2d.Highlight");
|
17 |
dojo.require("dojo.colors");
|
18 |
dojo.require("dojo.data.ItemFileWriteStore");
|
19 |
(function(){
|
20 |
var _1=function(_2,_3,_4,_5){ |
21 |
var _6=[];
|
22 |
_6[0]={value:0,text:""}; |
23 |
var _7=_2.length;
|
24 |
if((_4!=="ClusteredBars")&&(_4!=="StackedBars")){ |
25 |
var _8=_5.offsetWidth;
|
26 |
var _9=(""+_2[0]).length*_2.length*7; |
27 |
if(_3==1){ |
28 |
for(var z=1;z<500;++z){ |
29 |
if((_9/z)<_8){
|
30 |
break;
|
31 |
} |
32 |
++_3; |
33 |
} |
34 |
} |
35 |
} |
36 |
for(var i=0;i<_7;i++){ |
37 |
_6.push({value:i+1,text:(!_3||i%_3)?"":_2[i]}); |
38 |
} |
39 |
_6.push({value:_7+1,text:""}); |
40 |
return _6;
|
41 |
}; |
42 |
var _a=function(_b,_c){ |
43 |
var _d={vertical:false,labels:_c,min:0,max:_c.length-1,majorTickStep:1,minorTickStep:1}; |
44 |
if((_b==="ClusteredBars")||(_b==="StackedBars")){ |
45 |
_d.vertical=true;
|
46 |
} |
47 |
if((_b==="Lines")||(_b==="Areas")||(_b==="StackedAreas")){ |
48 |
_d.min++; |
49 |
_d.max--; |
50 |
} |
51 |
return _d;
|
52 |
}; |
53 |
var _e=function(_f,_10,_11,_12){ |
54 |
var _13={vertical:true,fixLower:"major",fixUpper:"major",natural:true}; |
55 |
if(_10==="secondary"){ |
56 |
_13.leftBottom=false;
|
57 |
} |
58 |
if((_f==="ClusteredBars")||(_f==="StackedBars")){ |
59 |
_13.vertical=false;
|
60 |
} |
61 |
if(_11==_12){
|
62 |
_13.min=_11-1;
|
63 |
_13.max=_12+1;
|
64 |
} |
65 |
return _13;
|
66 |
}; |
67 |
var _14=function(_15,_16,_17){ |
68 |
var _18={type:_15,hAxis:"independent",vAxis:"dependent-"+_16,gap:4,lines:false,areas:false,markers:false}; |
69 |
if((_15==="ClusteredBars")||(_15==="StackedBars")){ |
70 |
_18.hAxis=_18.vAxis; |
71 |
_18.vAxis="independent";
|
72 |
} |
73 |
if((_15==="Lines")||(_15==="Hybrid-Lines")||(_15==="Areas")||(_15==="StackedAreas")){ |
74 |
_18.lines=true;
|
75 |
} |
76 |
if((_15==="Areas")||(_15==="StackedAreas")){ |
77 |
_18.areas=true;
|
78 |
} |
79 |
if(_15==="Lines"){ |
80 |
_18.markers=true;
|
81 |
} |
82 |
if(_15==="Hybrid-Lines"){ |
83 |
_18.shadows={dx:2,dy:2,dw:2}; |
84 |
_18.type="Lines";
|
85 |
} |
86 |
if(_15==="Hybrid-ClusteredColumns"){ |
87 |
_18.type="ClusteredColumns";
|
88 |
} |
89 |
if(_17){
|
90 |
_18.animate=_17; |
91 |
} |
92 |
return _18;
|
93 |
}; |
94 |
var _19=function(_1a,_1b,_1c,_1d,_1e,_1f,_20,_21,_22,_23,_24){ |
95 |
var _25=_1b;
|
96 |
if(!_25){
|
97 |
_1a.innerHTML="";
|
98 |
_25=new dojox.charting.Chart2D(_1a);
|
99 |
} |
100 |
if(_20){
|
101 |
_20._clone=function(){ |
102 |
var _26=new dojox.charting.Theme({chart:this.chart,plotarea:this.plotarea,axis:this.axis,series:this.series,marker:this.marker,antiAlias:this.antiAlias,assignColors:this.assignColors,assignMarkers:this.assigneMarkers,colors:dojo.delegate(this.colors)}); |
103 |
_26.markers=this.markers;
|
104 |
_26._buildMarkerArray(); |
105 |
return _26;
|
106 |
}; |
107 |
_25.setTheme(_20); |
108 |
} |
109 |
var _27=_22.series_data[0].slice(0); |
110 |
if(_1d){
|
111 |
_27.reverse(); |
112 |
} |
113 |
var _28=_1(_27,_1f,_1c,_1a);
|
114 |
var _29={};
|
115 |
var _2a=null; |
116 |
var _2b=null; |
117 |
var _2c={};
|
118 |
for(var _2d in _25.runs){ |
119 |
_2c[_2d]=true;
|
120 |
} |
121 |
var _2e=_22.series_name.length;
|
122 |
for(var i=0;i<_2e;i++){ |
123 |
if(_22.series_chart[i]&&(_22.series_data[i].length>0)){ |
124 |
var _2f=_1c;
|
125 |
var _30=_22.series_axis[i];
|
126 |
if(_2f=="Hybrid"){ |
127 |
if(_22.series_charttype[i]=="line"){ |
128 |
_2f="Hybrid-Lines";
|
129 |
}else{
|
130 |
_2f="Hybrid-ClusteredColumns";
|
131 |
} |
132 |
} |
133 |
if(!_29[_30]){
|
134 |
_29[_30]={}; |
135 |
} |
136 |
if(!_29[_30][_2f]){
|
137 |
var _31=_30+"-"+_2f; |
138 |
_25.addPlot(_31,_14(_2f,_30,_1e)); |
139 |
var _32={};
|
140 |
if(typeof _21=="string"){ |
141 |
_32.text=function(o){ |
142 |
var _33=[o.element,o.run.name,_27[o.index],((_2f==="ClusteredBars")||(_2f==="StackedBars"))?o.x:o.y]; |
143 |
return dojo.replace(_21,_33);
|
144 |
}; |
145 |
}else{
|
146 |
if(typeof _21=="function"){ |
147 |
_32.text=_21; |
148 |
} |
149 |
} |
150 |
new dojox.charting.action2d.Tooltip(_25,_31,_32);
|
151 |
if(_2f!=="Lines"&&_2f!=="Hybrid-Lines"){ |
152 |
new dojox.charting.action2d.Highlight(_25,_31);
|
153 |
} |
154 |
_29[_30][_2f]=true;
|
155 |
} |
156 |
var _34=[];
|
157 |
var _35=_22.series_data[i].length;
|
158 |
for(var j=0;j<_35;j++){ |
159 |
var val=_22.series_data[i][j];
|
160 |
_34.push(val); |
161 |
if(_2a===null||val>_2a){ |
162 |
_2a=val; |
163 |
} |
164 |
if(_2b===null||val<_2b){ |
165 |
_2b=val; |
166 |
} |
167 |
} |
168 |
if(_1d){
|
169 |
_34.reverse(); |
170 |
} |
171 |
var _36={plot:_30+"-"+_2f}; |
172 |
if(_22.series_linestyle[i]){
|
173 |
_36.stroke={style:_22.series_linestyle[i]};
|
174 |
} |
175 |
_25.addSeries(_22.series_name[i],_34,_36); |
176 |
delete _2c[_22.series_name[i]];
|
177 |
} |
178 |
} |
179 |
for(_2d in _2c){ |
180 |
_25.removeSeries(_2d); |
181 |
} |
182 |
_25.addAxis("independent",_a(_1c,_28));
|
183 |
_25.addAxis("dependent-primary",_e(_1c,"primary",_2b,_2a)); |
184 |
_25.addAxis("dependent-secondary",_e(_1c,"secondary",_2b,_2a)); |
185 |
return _25;
|
186 |
}; |
187 |
var _37=function(_38,_39,_3a,_3b){ |
188 |
var _3c=_39;
|
189 |
if(!_3c){
|
190 |
_3c=new dojox.charting.widget.Legend({chart:_3a,horizontal:_3b},_38); |
191 |
}else{
|
192 |
_3c.refresh(); |
193 |
} |
194 |
return _3c;
|
195 |
}; |
196 |
var _3d=function(_3e,_3f,_40,_41,_42){ |
197 |
var _43=_3f||new dojox.grid.DataGrid({},_3e); |
198 |
_43.startup(); |
199 |
_43.setStore(_40,_41,_42); |
200 |
var _44=[];
|
201 |
for(var ser=0;ser<_40.series_name.length;ser++){ |
202 |
if(_40.series_grid[ser]&&(_40.series_data[ser].length>0)){ |
203 |
_44.push({field:"data."+ser,name:_40.series_name[ser],width:"auto",formatter:_40.series_gridformatter[ser]}); |
204 |
} |
205 |
} |
206 |
_43.setStructure(_44); |
207 |
return _43;
|
208 |
}; |
209 |
var _45=function(_46,_47){ |
210 |
if(_47.title){
|
211 |
_46.innerHTML=_47.title; |
212 |
} |
213 |
}; |
214 |
var _48=function(_49,_4a){ |
215 |
if(_4a.footer){
|
216 |
_49.innerHTML=_4a.footer; |
217 |
} |
218 |
}; |
219 |
var _4b=function(_4c,_4d){ |
220 |
var _4e=_4c;
|
221 |
if(_4d){
|
222 |
var _4f=_4d.split(/[.\[\]]+/); |
223 |
for(var _50 in _4f){ |
224 |
if(_4e){
|
225 |
_4e=_4e[_4f[_50]]; |
226 |
} |
227 |
} |
228 |
} |
229 |
return _4e;
|
230 |
}; |
231 |
dojo.declare("dojox.widget.DataPresentation",null,{type:"chart",chartType:"clusteredBars",reverse:false,animate:null,labelMod:1,legendHorizontal:true,constructor:function(_51,_52){ |
232 |
dojo.mixin(this,_52);
|
233 |
this.domNode=dojo.byId(_51);
|
234 |
this[this.type+"Node"]=this.domNode; |
235 |
if(typeof this.theme=="string"){ |
236 |
this.theme=dojo.getObject(this.theme); |
237 |
} |
238 |
this.chartNode=dojo.byId(this.chartNode); |
239 |
this.legendNode=dojo.byId(this.legendNode); |
240 |
this.gridNode=dojo.byId(this.gridNode); |
241 |
this.titleNode=dojo.byId(this.titleNode); |
242 |
this.footerNode=dojo.byId(this.footerNode); |
243 |
if(this.legendVertical){ |
244 |
this.legendHorizontal=!this.legendVertical; |
245 |
} |
246 |
if(this.url){ |
247 |
this.setURL(null,null,this.refreshInterval); |
248 |
}else{
|
249 |
if(this.data){ |
250 |
this.setData(null,this.refreshInterval); |
251 |
}else{
|
252 |
this.setStore();
|
253 |
} |
254 |
} |
255 |
},setURL:function(url,_53,_54){ |
256 |
if(_54){
|
257 |
this.cancelRefresh();
|
258 |
} |
259 |
this.url=url||this.url; |
260 |
this.urlContent=_53||this.urlContent; |
261 |
this.refreshInterval=_54||this.refreshInterval; |
262 |
var me=this; |
263 |
dojo.xhrGet({url:this.url,content:this.urlContent,handleAs:"json-comment-optional",load:function(_55,_56){ |
264 |
me.setData(_55); |
265 |
},error:function(xhr,_57){ |
266 |
if(me.urlError&&(typeof me.urlError=="function")){ |
267 |
me.urlError(xhr,_57); |
268 |
} |
269 |
}}); |
270 |
if(_54&&(this.refreshInterval>0)){ |
271 |
this.refreshIntervalPending=setInterval(function(){ |
272 |
me.setURL(); |
273 |
},this.refreshInterval);
|
274 |
} |
275 |
},setData:function(_58,_59){ |
276 |
if(_59){
|
277 |
this.cancelRefresh();
|
278 |
} |
279 |
this.data=_58||this.data; |
280 |
this.refreshInterval=_59||this.refreshInterval; |
281 |
var _5a=(typeof this.series=="function")?this.series(this.data):this.series; |
282 |
var _5b=[],_5c=[],_5d=[],_5e=[],_5f=[],_60=[],_61=[],_62=[],_63=[],_64=0; |
283 |
for(var ser=0;ser<_5a.length;ser++){ |
284 |
_5b[ser]=_4b(this.data,_5a[ser].datapoints);
|
285 |
if(_5b[ser]&&(_5b[ser].length>_64)){
|
286 |
_64=_5b[ser].length; |
287 |
} |
288 |
_5c[ser]=[]; |
289 |
_5d[ser]=_5a[ser].name||(_5a[ser].namefield?_4b(this.data,_5a[ser].namefield):null)||("series "+ser); |
290 |
_5e[ser]=(_5a[ser].chart!==false);
|
291 |
_5f[ser]=_5a[ser].charttype||"bar";
|
292 |
_60[ser]=_5a[ser].linestyle; |
293 |
_61[ser]=_5a[ser].axis||"primary";
|
294 |
_62[ser]=(_5a[ser].grid!==false);
|
295 |
_63[ser]=_5a[ser].gridformatter; |
296 |
} |
297 |
var _65,_66,_67,_68;
|
298 |
var _69=[];
|
299 |
for(_65=0;_65<_64;_65++){ |
300 |
_66={index:_65};
|
301 |
for(ser=0;ser<_5a.length;ser++){ |
302 |
if(_5b[ser]&&(_5b[ser].length>_65)){
|
303 |
_67=_4b(_5b[ser][_65],_5a[ser].field); |
304 |
if(_5e[ser]){
|
305 |
_68=parseFloat(_67); |
306 |
if(!isNaN(_68)){
|
307 |
_67=_68; |
308 |
} |
309 |
} |
310 |
_66["data."+ser]=_67;
|
311 |
_5c[ser].push(_67); |
312 |
} |
313 |
} |
314 |
_69.push(_66); |
315 |
} |
316 |
if(_64<=0){ |
317 |
_69.push({index:0}); |
318 |
} |
319 |
var _6a=new dojo.data.ItemFileWriteStore({data:{identifier:"index",items:_69}}); |
320 |
if(this.data.title){ |
321 |
_6a.title=this.data.title;
|
322 |
} |
323 |
if(this.data.footer){ |
324 |
_6a.footer=this.data.footer;
|
325 |
} |
326 |
_6a.series_data=_5c; |
327 |
_6a.series_name=_5d; |
328 |
_6a.series_chart=_5e; |
329 |
_6a.series_charttype=_5f; |
330 |
_6a.series_linestyle=_60; |
331 |
_6a.series_axis=_61; |
332 |
_6a.series_grid=_62; |
333 |
_6a.series_gridformatter=_63; |
334 |
this.setPreparedStore(_6a);
|
335 |
if(_59&&(this.refreshInterval>0)){ |
336 |
var me=this; |
337 |
this.refreshIntervalPending=setInterval(function(){ |
338 |
me.setData(); |
339 |
},this.refreshInterval);
|
340 |
} |
341 |
},refresh:function(){ |
342 |
if(this.url){ |
343 |
this.setURL(this.url,this.urlContent,this.refreshInterval); |
344 |
}else{
|
345 |
if(this.data){ |
346 |
this.setData(this.data,this.refreshInterval); |
347 |
} |
348 |
} |
349 |
},cancelRefresh:function(){ |
350 |
if(this.refreshIntervalPending){ |
351 |
clearInterval(this.refreshIntervalPending);
|
352 |
this.refreshIntervalPending=undefined; |
353 |
} |
354 |
},setStore:function(_6b,_6c,_6d){ |
355 |
this.setPreparedStore(_6b,_6c,_6d);
|
356 |
},setPreparedStore:function(_6e,_6f,_70){ |
357 |
this.preparedstore=_6e||this.store; |
358 |
this.query=_6f||this.query; |
359 |
this.queryOptions=_70||this.queryOptions; |
360 |
if(this.preparedstore){ |
361 |
if(this.chartNode){ |
362 |
this.chartWidget=_19(this.chartNode,this.chartWidget,this.chartType,this.reverse,this.animate,this.labelMod,this.theme,this.tooltip,this.preparedstore,this.query,this,_70); |
363 |
this.renderChartWidget();
|
364 |
} |
365 |
if(this.legendNode){ |
366 |
this.legendWidget=_37(this.legendNode,this.legendWidget,this.chartWidget,this.legendHorizontal); |
367 |
} |
368 |
if(this.gridNode){ |
369 |
this.gridWidget=_3d(this.gridNode,this.gridWidget,this.preparedstore,this.query,this.queryOptions); |
370 |
this.renderGridWidget();
|
371 |
} |
372 |
if(this.titleNode){ |
373 |
_45(this.titleNode,this.preparedstore); |
374 |
} |
375 |
if(this.footerNode){ |
376 |
_48(this.footerNode,this.preparedstore); |
377 |
} |
378 |
} |
379 |
},renderChartWidget:function(){ |
380 |
if(this.chartWidget){ |
381 |
this.chartWidget.render();
|
382 |
} |
383 |
},renderGridWidget:function(){ |
384 |
if(this.gridWidget){ |
385 |
this.gridWidget.render();
|
386 |
} |
387 |
},getChartWidget:function(){ |
388 |
return this.chartWidget; |
389 |
},getGridWidget:function(){ |
390 |
return this.gridWidget; |
391 |
},destroy:function(){ |
392 |
this.cancelRefresh();
|
393 |
if(this.chartWidget){ |
394 |
this.chartWidget.destroy();
|
395 |
delete this.chartWidget; |
396 |
} |
397 |
if(this.legendWidget){ |
398 |
delete this.legendWidget; |
399 |
} |
400 |
if(this.gridWidget){ |
401 |
delete this.gridWidget; |
402 |
} |
403 |
if(this.chartNode){ |
404 |
this.chartNode.innerHTML=""; |
405 |
} |
406 |
if(this.legendNode){ |
407 |
this.legendNode.innerHTML=""; |
408 |
} |
409 |
if(this.gridNode){ |
410 |
this.gridNode.innerHTML=""; |
411 |
} |
412 |
if(this.titleNode){ |
413 |
this.titleNode.innerHTML=""; |
414 |
} |
415 |
if(this.footerNode){ |
416 |
this.footerNode.innerHTML=""; |
417 |
} |
418 |
}}); |
419 |
})(); |
420 |
} |