Subversion Repositories Applications.papyrus

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
2150 mathias 1
if(!dojo._hasResource["dojox.charting.plot2d.Columns"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
2
dojo._hasResource["dojox.charting.plot2d.Columns"] = true;
3
dojo.provide("dojox.charting.plot2d.Columns");
4
 
5
dojo.require("dojox.charting.plot2d.common");
6
dojo.require("dojox.charting.plot2d.Base");
7
 
8
dojo.require("dojox.lang.utils");
9
dojo.require("dojox.lang.functional");
10
 
11
(function(){
12
	var df = dojox.lang.functional, du = dojox.lang.utils,
13
		dc = dojox.charting.plot2d.common,
14
		purgeGroup = df.lambda("item.purgeGroup()");
15
 
16
	dojo.declare("dojox.charting.plot2d.Columns", dojox.charting.plot2d.Base, {
17
		defaultParams: {
18
			hAxis: "x",		// use a horizontal axis named "x"
19
			vAxis: "y",		// use a vertical axis named "y"
20
			gap:	0,		// gap between columns in pixels
21
			shadows: null	// draw shadows
22
		},
23
		optionalParams: {},	// no optional parameters
24
 
25
		constructor: function(chart, kwArgs){
26
			this.opt = dojo.clone(this.defaultParams);
27
			du.updateWithObject(this.opt, kwArgs);
28
			this.series = [];
29
			this.hAxis = this.opt.hAxis;
30
			this.vAxis = this.opt.vAxis;
31
		},
32
 
33
		calculateAxes: function(dim){
34
			var stats = dc.collectSimpleStats(this.series);
35
			stats.hmin -= 0.5;
36
			stats.hmax += 0.5;
37
			this._calc(dim, stats);
38
			return this;
39
		},
40
		render: function(dim, offsets){
41
			if(this.dirty){
42
				dojo.forEach(this.series, purgeGroup);
43
				this.cleanGroup();
44
				var s = this.group;
45
				df.forEachReversed(this.series, function(item){ item.cleanGroup(s); });
46
			}
47
			var t = this.chart.theme, color, stroke, fill, f,
48
				gap = this.opt.gap < this._hScaler.scale / 3 ? this.opt.gap : 0;
49
			for(var i = this.series.length - 1; i >= 0; --i){
50
				var run = this.series[i];
51
				if(!this.dirty && !run.dirty){ continue; }
52
				run.cleanGroup();
53
				var s = run.group;
54
				if(!run.fill || !run.stroke){
55
					// need autogenerated color
56
					color = run.dyn.color = new dojo.Color(t.next("color"));
57
				}
58
				stroke = run.stroke ? run.stroke : dc.augmentStroke(t.series.stroke, color);
59
				fill = run.fill ? run.fill : dc.augmentFill(t.series.fill, color);
60
				var baseline = Math.max(0, this._vScaler.bounds.lower),
61
					xoff = offsets.l + this._hScaler.scale * (0.5 - this._hScaler.bounds.lower) + gap,
62
					yoff = dim.height - offsets.b - this._vScaler.scale * (baseline - this._vScaler.bounds.lower);
63
				for(var j = 0; j < run.data.length; ++j){
64
					var v = run.data[j],
65
						width  = this._hScaler.scale - 2 * gap,
66
						height = this._vScaler.scale * (v - baseline),
67
						h = Math.abs(height);
68
					if(width >= 1 && h >= 1){
69
						var rect = {
70
								x: xoff + this._hScaler.scale * j,
71
								y: yoff - (height < 0 ? 0 : height),
72
								width: width, height: h
73
							},
74
							shape = s.createRect(rect).setFill(fill).setStroke(stroke);
75
						run.dyn.fill   = shape.getFill();
76
						run.dyn.stroke = shape.getStroke();
77
					}
78
				}
79
				run.dirty = false;
80
			}
81
			this.dirty = false;
82
			return this;
83
		}
84
	});
85
})();
86
 
87
}