Subversion Repositories Applications.papyrus

Rev

Details | Last modification | View Log | RSS feed

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