2150 |
mathias |
1 |
if(!dojo._hasResource["dojox.charting.plot2d.Stacked"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
|
|
|
2 |
dojo._hasResource["dojox.charting.plot2d.Stacked"] = true;
|
|
|
3 |
dojo.provide("dojox.charting.plot2d.Stacked");
|
|
|
4 |
|
|
|
5 |
dojo.require("dojox.charting.plot2d.common");
|
|
|
6 |
dojo.require("dojox.charting.plot2d.Default");
|
|
|
7 |
|
|
|
8 |
dojo.require("dojox.lang.functional");
|
|
|
9 |
|
|
|
10 |
(function(){
|
|
|
11 |
var df = dojox.lang.functional, dc = dojox.charting.plot2d.common,
|
|
|
12 |
purgeGroup = df.lambda("item.purgeGroup()");
|
|
|
13 |
|
|
|
14 |
dojo.declare("dojox.charting.plot2d.Stacked", dojox.charting.plot2d.Default, {
|
|
|
15 |
calculateAxes: function(dim){
|
|
|
16 |
var stats = dc.collectStackedStats(this.series);
|
|
|
17 |
this._maxRunLength = stats.hmax;
|
|
|
18 |
this._calc(dim, stats);
|
|
|
19 |
return this;
|
|
|
20 |
},
|
|
|
21 |
render: function(dim, offsets){
|
|
|
22 |
// stack all values
|
|
|
23 |
var acc = df.repeat(this._maxRunLength, "-> 0", 0);
|
|
|
24 |
for(var i = 0; i < this.series.length; ++i){
|
|
|
25 |
var run = this.series[i];
|
|
|
26 |
for(var j = 0; j < run.data.length; ++j){
|
|
|
27 |
var v = run.data[j];
|
|
|
28 |
if(isNaN(v)){ v = 0; }
|
|
|
29 |
acc[j] += v;
|
|
|
30 |
}
|
|
|
31 |
}
|
|
|
32 |
// draw runs in backwards
|
|
|
33 |
if(this.dirty){
|
|
|
34 |
dojo.forEach(this.series, purgeGroup);
|
|
|
35 |
this.cleanGroup();
|
|
|
36 |
var s = this.group;
|
|
|
37 |
df.forEachReversed(this.series, function(item){ item.cleanGroup(s); });
|
|
|
38 |
}
|
|
|
39 |
var t = this.chart.theme, stroke, outline, color, marker;
|
|
|
40 |
for(var i = this.series.length - 1; i >= 0; --i){
|
|
|
41 |
var run = this.series[i];
|
|
|
42 |
if(!this.dirty && !run.dirty){ continue; }
|
|
|
43 |
run.cleanGroup();
|
|
|
44 |
var s = run.group,
|
|
|
45 |
lpoly = dojo.map(acc, function(v, i){
|
|
|
46 |
return {
|
|
|
47 |
x: this._hScaler.scale * (i + 1 - this._hScaler.bounds.lower) + offsets.l,
|
|
|
48 |
y: dim.height - offsets.b - this._vScaler.scale * (v - this._vScaler.bounds.lower)
|
|
|
49 |
};
|
|
|
50 |
}, this);
|
|
|
51 |
if(!run.fill || !run.stroke){
|
|
|
52 |
// need autogenerated color
|
|
|
53 |
color = new dojo.Color(t.next("color"));
|
|
|
54 |
}
|
|
|
55 |
if(this.opt.areas){
|
|
|
56 |
var apoly = dojo.clone(lpoly);
|
|
|
57 |
apoly.push({x: lpoly[lpoly.length - 1].x, y: dim.height - offsets.b});
|
|
|
58 |
apoly.push({x: lpoly[0].x, y: dim.height - offsets.b});
|
|
|
59 |
apoly.push(lpoly[0]);
|
|
|
60 |
var fill = run.fill ? run.fill : dc.augmentFill(t.series.fill, color);
|
|
|
61 |
s.createPolyline(apoly).setFill(fill);
|
|
|
62 |
}
|
|
|
63 |
if(this.opt.lines || this.opt.markers){
|
|
|
64 |
// need a stroke
|
|
|
65 |
stroke = run.stroke ? dc.makeStroke(run.stroke) : dc.augmentStroke(t.series.stroke, color);
|
|
|
66 |
if(run.outline || t.series.outline){
|
|
|
67 |
outline = dc.makeStroke(run.outline ? run.outline : t.series.outline);
|
|
|
68 |
outline.width = 2 * outline.width + stroke.width;
|
|
|
69 |
}
|
|
|
70 |
}
|
|
|
71 |
if(this.opt.markers){
|
|
|
72 |
// need a marker
|
|
|
73 |
marker = run.marker ? run.marker : t.next("marker");
|
|
|
74 |
}
|
|
|
75 |
if(this.opt.shadows && stroke){
|
|
|
76 |
var sh = this.opt.shadows, shadowColor = new dojo.Color([0, 0, 0, 0.3]),
|
|
|
77 |
spoly = dojo.map(lpoly, function(c){
|
|
|
78 |
return {x: c.x + sh.dx, y: c.y + sh.dy};
|
|
|
79 |
}),
|
|
|
80 |
shadowStroke = dojo.clone(outline ? outline : stroke);
|
|
|
81 |
shadowStroke.color = shadowColor;
|
|
|
82 |
shadowStroke.width += sh.dw ? sh.dw : 0;
|
|
|
83 |
if(this.opt.lines){
|
|
|
84 |
s.createPolyline(spoly).setStroke(shadowStroke);
|
|
|
85 |
}
|
|
|
86 |
if(this.opt.markers){
|
|
|
87 |
dojo.forEach(spoly, function(c){
|
|
|
88 |
s.createPath("M" + c.x + " " + c.y + " " + marker).setStroke(shadowStroke).setFill(shadowColor);
|
|
|
89 |
}, this);
|
|
|
90 |
}
|
|
|
91 |
}
|
|
|
92 |
if(this.opt.lines){
|
|
|
93 |
if(outline){
|
|
|
94 |
s.createPolyline(lpoly).setStroke(outline);
|
|
|
95 |
}
|
|
|
96 |
s.createPolyline(lpoly).setStroke(stroke);
|
|
|
97 |
}
|
|
|
98 |
if(this.opt.markers){
|
|
|
99 |
dojo.forEach(lpoly, function(c){
|
|
|
100 |
var path = "M" + c.x + " " + c.y + " " + marker;
|
|
|
101 |
if(outline){
|
|
|
102 |
s.createPath(path).setStroke(outline);
|
|
|
103 |
}
|
|
|
104 |
s.createPath(path).setStroke(stroke).setFill(stroke.color);
|
|
|
105 |
}, this);
|
|
|
106 |
}
|
|
|
107 |
run.dirty = false;
|
|
|
108 |
// update the accumulator
|
|
|
109 |
for(var j = 0; j < run.data.length; ++j){
|
|
|
110 |
var v = run.data[j];
|
|
|
111 |
if(isNaN(v)){ v = 0; }
|
|
|
112 |
acc[j] -= v;
|
|
|
113 |
}
|
|
|
114 |
}
|
|
|
115 |
this.dirty = false;
|
|
|
116 |
return this;
|
|
|
117 |
}
|
|
|
118 |
});
|
|
|
119 |
})();
|
|
|
120 |
|
|
|
121 |
}
|