2150 |
mathias |
1 |
if(!dojo._hasResource["dojox.charting.plot2d.StackedBars"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
|
|
|
2 |
dojo._hasResource["dojox.charting.plot2d.StackedBars"] = true;
|
|
|
3 |
dojo.provide("dojox.charting.plot2d.StackedBars");
|
|
|
4 |
|
|
|
5 |
dojo.require("dojox.charting.plot2d.common");
|
|
|
6 |
dojo.require("dojox.charting.plot2d.Bars");
|
|
|
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.StackedBars", dojox.charting.plot2d.Bars, {
|
|
|
15 |
calculateAxes: function(dim){
|
|
|
16 |
var stats = dc.collectStackedStats(this.series), t;
|
|
|
17 |
this._maxRunLength = stats.hmax;
|
|
|
18 |
stats.hmin -= 0.5;
|
|
|
19 |
stats.hmax += 0.5;
|
|
|
20 |
t = stats.hmin, stats.hmin = stats.vmin, stats.vmin = t;
|
|
|
21 |
t = stats.hmax, stats.hmax = stats.vmax, stats.vmax = t;
|
|
|
22 |
this._calc(dim, stats);
|
|
|
23 |
return this;
|
|
|
24 |
},
|
|
|
25 |
render: function(dim, offsets){
|
|
|
26 |
// stack all values
|
|
|
27 |
var acc = df.repeat(this._maxRunLength, "-> 0", 0);
|
|
|
28 |
for(var i = 0; i < this.series.length; ++i){
|
|
|
29 |
var run = this.series[i];
|
|
|
30 |
for(var j = 0; j < run.data.length; ++j){
|
|
|
31 |
var v = run.data[j];
|
|
|
32 |
if(isNaN(v)){ v = 0; }
|
|
|
33 |
acc[j] += v;
|
|
|
34 |
}
|
|
|
35 |
}
|
|
|
36 |
// draw runs in backwards
|
|
|
37 |
if(this.dirty){
|
|
|
38 |
dojo.forEach(this.series, purgeGroup);
|
|
|
39 |
this.cleanGroup();
|
|
|
40 |
var s = this.group;
|
|
|
41 |
df.forEachReversed(this.series, function(item){ item.cleanGroup(s); });
|
|
|
42 |
}
|
|
|
43 |
var t = this.chart.theme, color, stroke, fill, f,
|
|
|
44 |
gap = this.opt.gap < this._vScaler.scale / 3 ? this.opt.gap : 0;
|
|
|
45 |
for(var i = this.series.length - 1; i >= 0; --i){
|
|
|
46 |
var run = this.series[i];
|
|
|
47 |
if(!this.dirty && !run.dirty){ continue; }
|
|
|
48 |
run.cleanGroup();
|
|
|
49 |
var s = run.group;
|
|
|
50 |
if(!run.fill || !run.stroke){
|
|
|
51 |
// need autogenerated color
|
|
|
52 |
color = run.dyn.color = new dojo.Color(t.next("color"));
|
|
|
53 |
}
|
|
|
54 |
stroke = run.stroke ? run.stroke : dc.augmentStroke(t.series.stroke, color);
|
|
|
55 |
fill = run.fill ? run.fill : dc.augmentFill(t.series.fill, color);
|
|
|
56 |
for(var j = 0; j < acc.length; ++j){
|
|
|
57 |
var v = acc[j],
|
|
|
58 |
width = this._hScaler.scale * (v - this._hScaler.bounds.lower),
|
|
|
59 |
height = this._vScaler.scale - 2 * gap;
|
|
|
60 |
if(width >= 1 && height >= 1){
|
|
|
61 |
var shape = s.createRect({
|
|
|
62 |
x: offsets.l,
|
|
|
63 |
y: dim.height - offsets.b - this._vScaler.scale * (j + 1.5 - this._vScaler.bounds.lower) + gap,
|
|
|
64 |
width: width, height: height
|
|
|
65 |
}).setFill(fill).setStroke(stroke);
|
|
|
66 |
run.dyn.fill = shape.getFill();
|
|
|
67 |
run.dyn.stroke = shape.getStroke();
|
|
|
68 |
}
|
|
|
69 |
}
|
|
|
70 |
run.dirty = false;
|
|
|
71 |
// update the accumulator
|
|
|
72 |
for(var j = 0; j < run.data.length; ++j){
|
|
|
73 |
var v = run.data[j];
|
|
|
74 |
if(isNaN(v)){ v = 0; }
|
|
|
75 |
acc[j] -= v;
|
|
|
76 |
}
|
|
|
77 |
}
|
|
|
78 |
this.dirty = false;
|
|
|
79 |
return this;
|
|
|
80 |
}
|
|
|
81 |
});
|
|
|
82 |
})();
|
|
|
83 |
|
|
|
84 |
}
|