root / trunk / web / dojo / dojox / charting / plot2d / Stacked.js @ 13
History | View | Annotate | Download (4.34 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.Stacked"]){ |
9 |
dojo._hasResource["dojox.charting.plot2d.Stacked"]=true; |
10 |
dojo.provide("dojox.charting.plot2d.Stacked");
|
11 |
dojo.require("dojox.charting.plot2d.common");
|
12 |
dojo.require("dojox.charting.plot2d.Default");
|
13 |
dojo.require("dojox.lang.functional");
|
14 |
dojo.require("dojox.lang.functional.sequence");
|
15 |
dojo.require("dojox.lang.functional.reversed");
|
16 |
(function(){
|
17 |
var df=dojox.lang.functional,dc=dojox.charting.plot2d.common,_1=df.lambda("item.purgeGroup()"); |
18 |
dojo.declare("dojox.charting.plot2d.Stacked",dojox.charting.plot2d.Default,{getSeriesStats:function(){ |
19 |
var _2=dc.collectStackedStats(this.series); |
20 |
this._maxRunLength=_2.hmax;
|
21 |
return _2;
|
22 |
},render:function(_3,_4){ |
23 |
if(this._maxRunLength<=0){ |
24 |
return this; |
25 |
} |
26 |
var _5=df.repeat(this._maxRunLength,"-> 0",0); |
27 |
for(var i=0;i<this.series.length;++i){ |
28 |
var _6=this.series[i]; |
29 |
for(var j=0;j<_6.data.length;++j){ |
30 |
var v=_6.data[j];
|
31 |
if(v!==null){ |
32 |
if(isNaN(v)){
|
33 |
v=0;
|
34 |
} |
35 |
_5[j]+=v; |
36 |
} |
37 |
} |
38 |
} |
39 |
if(this.zoom&&!this.isDataDirty()){ |
40 |
return this.performZoom(_3,_4); |
41 |
} |
42 |
this.resetEvents();
|
43 |
this.dirty=this.isDirty(); |
44 |
if(this.dirty){ |
45 |
dojo.forEach(this.series,_1);
|
46 |
this._eventSeries={};
|
47 |
this.cleanGroup();
|
48 |
var s=this.group; |
49 |
df.forEachRev(this.series,function(_7){ |
50 |
_7.cleanGroup(s); |
51 |
}); |
52 |
} |
53 |
var t=this.chart.theme,_8=this.events(),ht=this._hScaler.scaler.getTransformerFromModel(this._hScaler),vt=this._vScaler.scaler.getTransformerFromModel(this._vScaler); |
54 |
for(var i=this.series.length-1;i>=0;--i){ |
55 |
var _6=this.series[i]; |
56 |
if(!this.dirty&&!_6.dirty){ |
57 |
t.skip(); |
58 |
this._reconnectEvents(_6.name);
|
59 |
continue;
|
60 |
} |
61 |
_6.cleanGroup(); |
62 |
var _9=t.next(this.opt.areas?"area":"line",[this.opt,_6],true),s=_6.group,_a,_b=dojo.map(_5,function(v,i){ |
63 |
return {x:ht(i+1)+_4.l,y:_3.height-_4.b-vt(v)}; |
64 |
},this);
|
65 |
var _c=this.opt.tension?dc.curve(_b,this.opt.tension):""; |
66 |
if(this.opt.areas){ |
67 |
var _d=dojo.clone(_b);
|
68 |
if(this.opt.tension){ |
69 |
var p=dc.curve(_d,this.opt.tension); |
70 |
p+=" L"+_b[_b.length-1].x+","+(_3.height-_4.b)+" L"+_b[0].x+","+(_3.height-_4.b)+" L"+_b[0].x+","+_b[0].y; |
71 |
_6.dyn.fill=s.createPath(p).setFill(_9.series.fill).getFill(); |
72 |
}else{
|
73 |
_d.push({x:_b[_b.length-1].x,y:_3.height-_4.b}); |
74 |
_d.push({x:_b[0].x,y:_3.height-_4.b}); |
75 |
_d.push(_b[0]);
|
76 |
_6.dyn.fill=s.createPolyline(_d).setFill(_9.series.fill).getFill(); |
77 |
} |
78 |
} |
79 |
if(this.opt.lines||this.opt.markers){ |
80 |
if(_9.series.outline){
|
81 |
_a=dc.makeStroke(_9.series.outline); |
82 |
_a.width=2*_a.width+_9.series.stroke.width;
|
83 |
} |
84 |
} |
85 |
if(this.opt.markers){ |
86 |
_6.dyn.marker=_9.symbol; |
87 |
} |
88 |
var _e,_f,_10;
|
89 |
if(_9.series.shadow&&_9.series.stroke){
|
90 |
var _11=_9.series.shadow,_12=dojo.map(_b,function(c){ |
91 |
return {x:c.x+_11.dx,y:c.y+_11.dy}; |
92 |
}); |
93 |
if(this.opt.lines){ |
94 |
if(this.opt.tension){ |
95 |
_6.dyn.shadow=s.createPath(dc.curve(_12,this.opt.tension)).setStroke(_11).getStroke();
|
96 |
}else{
|
97 |
_6.dyn.shadow=s.createPolyline(_12).setStroke(_11).getStroke(); |
98 |
} |
99 |
} |
100 |
if(this.opt.markers){ |
101 |
_11=_9.marker.shadow; |
102 |
_10=dojo.map(_12,function(c){
|
103 |
return s.createPath("M"+c.x+" "+c.y+" "+_9.symbol).setStroke(_11).setFill(_11.color); |
104 |
},this);
|
105 |
} |
106 |
} |
107 |
if(this.opt.lines){ |
108 |
if(_a){
|
109 |
if(this.opt.tension){ |
110 |
_6.dyn.outline=s.createPath(_c).setStroke(_a).getStroke(); |
111 |
}else{
|
112 |
_6.dyn.outline=s.createPolyline(_b).setStroke(_a).getStroke(); |
113 |
} |
114 |
} |
115 |
if(this.opt.tension){ |
116 |
_6.dyn.stroke=s.createPath(_c).setStroke(_9.series.stroke).getStroke(); |
117 |
}else{
|
118 |
_6.dyn.stroke=s.createPolyline(_b).setStroke(_9.series.stroke).getStroke(); |
119 |
} |
120 |
} |
121 |
if(this.opt.markers){ |
122 |
_e=new Array(_b.length);
|
123 |
_f=new Array(_b.length);
|
124 |
_a=null;
|
125 |
if(_9.marker.outline){
|
126 |
_a=dc.makeStroke(_9.marker.outline); |
127 |
_a.width=2*_a.width+(_9.marker.stroke?_9.marker.stroke.width:0); |
128 |
} |
129 |
dojo.forEach(_b,function(c,i){
|
130 |
var _13="M"+c.x+" "+c.y+" "+_9.symbol; |
131 |
if(_a){
|
132 |
_f[i]=s.createPath(_13).setStroke(_a); |
133 |
} |
134 |
_e[i]=s.createPath(_13).setStroke(_9.marker.stroke).setFill(_9.marker.fill); |
135 |
},this);
|
136 |
if(_8){
|
137 |
var _14=new Array(_e.length); |
138 |
dojo.forEach(_e,function(s,i){
|
139 |
var o={element:"marker",index:i,run:_6,shape:s,outline:_f[i]||null,shadow:_10&&_10[i]||null,cx:_b[i].x,cy:_b[i].y,x:i+1,y:_6.data[i]}; |
140 |
this._connectEvents(o);
|
141 |
_14[i]=o; |
142 |
},this);
|
143 |
this._eventSeries[_6.name]=_14;
|
144 |
}else{
|
145 |
delete this._eventSeries[_6.name]; |
146 |
} |
147 |
} |
148 |
_6.dirty=false;
|
149 |
for(var j=0;j<_6.data.length;++j){ |
150 |
var v=_6.data[j];
|
151 |
if(v!==null){ |
152 |
if(isNaN(v)){
|
153 |
v=0;
|
154 |
} |
155 |
_5[j]-=v; |
156 |
} |
157 |
} |
158 |
} |
159 |
this.dirty=false; |
160 |
return this; |
161 |
}}); |
162 |
})(); |
163 |
} |