Project

General

Profile

Statistics
| Revision:

root / trunk / web / dojo / dojox / charting / plot2d / Bars.js @ 12

History | View | Annotate | Download (3.2 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.plot2d.Bars"]){
9
dojo._hasResource["dojox.charting.plot2d.Bars"]=true;
10
dojo.provide("dojox.charting.plot2d.Bars");
11
dojo.require("dojox.charting.plot2d.common");
12
dojo.require("dojox.charting.plot2d.Base");
13
dojo.require("dojox.gfx.fx");
14
dojo.require("dojox.lang.utils");
15
dojo.require("dojox.lang.functional");
16
dojo.require("dojox.lang.functional.reversed");
17
(function(){
18
var df=dojox.lang.functional,du=dojox.lang.utils,dc=dojox.charting.plot2d.common,_1=df.lambda("item.purgeGroup()");
19
dojo.declare("dojox.charting.plot2d.Bars",dojox.charting.plot2d.Base,{defaultParams:{hAxis:"x",vAxis:"y",gap:0,animate:null},optionalParams:{minBarSize:1,maxBarSize:1,stroke:{},outline:{},shadow:{},fill:{},font:"",fontColor:""},constructor:function(_2,_3){
20
this.opt=dojo.clone(this.defaultParams);
21
du.updateWithObject(this.opt,_3);
22
du.updateWithPattern(this.opt,_3,this.optionalParams);
23
this.series=[];
24
this.hAxis=this.opt.hAxis;
25
this.vAxis=this.opt.vAxis;
26
this.animate=this.opt.animate;
27
},getSeriesStats:function(){
28
var _4=dc.collectSimpleStats(this.series),t;
29
_4.hmin-=0.5;
30
_4.hmax+=0.5;
31
t=_4.hmin,_4.hmin=_4.vmin,_4.vmin=t;
32
t=_4.hmax,_4.hmax=_4.vmax,_4.vmax=t;
33
return _4;
34
},render:function(_5,_6){
35
if(this.zoom&&!this.isDataDirty()){
36
return this.performZoom(_5,_6);
37
}
38
this.dirty=this.isDirty();
39
this.resetEvents();
40
if(this.dirty){
41
dojo.forEach(this.series,_1);
42
this._eventSeries={};
43
this.cleanGroup();
44
var s=this.group;
45
df.forEachRev(this.series,function(_7){
46
_7.cleanGroup(s);
47
});
48
}
49
var t=this.chart.theme,f,_8,_9,ht=this._hScaler.scaler.getTransformerFromModel(this._hScaler),vt=this._vScaler.scaler.getTransformerFromModel(this._vScaler),_a=Math.max(0,this._hScaler.bounds.lower),_b=ht(_a),_c=this.events();
50
f=dc.calculateBarSize(this._vScaler.bounds.scale,this.opt);
51
_8=f.gap;
52
_9=f.size;
53
for(var i=this.series.length-1;i>=0;--i){
54
var _d=this.series[i];
55
if(!this.dirty&&!_d.dirty){
56
t.skip();
57
this._reconnectEvents(_d.name);
58
continue;
59
}
60
_d.cleanGroup();
61
var _e=t.next("bar",[this.opt,_d]),s=_d.group,_f=new Array(_d.data.length);
62
for(var j=0;j<_d.data.length;++j){
63
var _10=_d.data[j];
64
if(_10!==null){
65
var v=typeof _10=="number"?_10:_10.y,hv=ht(v),_11=hv-_b,w=Math.abs(_11),_12=typeof _10!="number"?t.addMixin(_e,"bar",_10,true):t.post(_e,"bar");
66
if(w>=1&&_9>=1){
67
var _13={x:_6.l+(v<_a?hv:_b),y:_5.height-_6.b-vt(j+1.5)+_8,width:w,height:_9};
68
var _14=this._plotFill(_12.series.fill,_5,_6);
69
_14=this._shapeFill(_14,_13);
70
var _15=s.createRect(_13).setFill(_14).setStroke(_12.series.stroke);
71
_d.dyn.fill=_15.getFill();
72
_d.dyn.stroke=_15.getStroke();
73
if(_c){
74
var o={element:"bar",index:j,run:_d,shape:_15,x:v,y:j+1.5};
75
this._connectEvents(o);
76
_f[j]=o;
77
}
78
if(this.animate){
79
this._animateBar(_15,_6.l+_b,-w);
80
}
81
}
82
}
83
}
84
this._eventSeries[_d.name]=_f;
85
_d.dirty=false;
86
}
87
this.dirty=false;
88
return this;
89
},_animateBar:function(_16,_17,_18){
90
dojox.gfx.fx.animateTransform(dojo.delegate({shape:_16,duration:1200,transform:[{name:"translate",start:[_17-(_17/_18),0],end:[0,0]},{name:"scale",start:[1/_18,1],end:[1,1]},{name:"original"}]},this.animate)).play();
91
}});
92
})();
93
}