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.Default"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
2
dojo._hasResource["dojox.charting.plot2d.Default"] = true;
3
dojo.provide("dojox.charting.plot2d.Default");
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.Default", 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
			lines:   true,	// draw lines
21
			areas:   false,	// draw areas
22
			markers: false,	// draw markers
23
			shadows: 0		// draw shadows
24
		},
25
		optionalParams: {},	// no optional parameters
26
 
27
		constructor: function(chart, kwArgs){
28
			this.opt = dojo.clone(this.defaultParams);
29
			du.updateWithObject(this.opt, kwArgs);
30
			this.series = [];
31
			this.hAxis = this.opt.hAxis;
32
			this.vAxis = this.opt.vAxis;
33
		},
34
 
35
		calculateAxes: function(dim){
36
			this._calc(dim, dc.collectSimpleStats(this.series));
37
			return this;
38
		},
39
		render: function(dim, offsets){
40
			if(this.dirty){
41
				dojo.forEach(this.series, purgeGroup);
42
				this.cleanGroup();
43
				var s = this.group;
44
				df.forEachReversed(this.series, function(item){ item.cleanGroup(s); });
45
			}
46
			var t = this.chart.theme, stroke, outline, color, marker;
47
			for(var i = this.series.length - 1; i >= 0; --i){
48
				var run = this.series[i];
49
				if(!this.dirty && !run.dirty){ continue; }
50
				run.cleanGroup();
51
				if(!run.data.length){
52
					run.dirty = false;
53
					continue;
54
				}
55
				var s = run.group, lpoly;
56
				if(typeof run.data[0] == "number"){
57
					lpoly = dojo.map(run.data, function(v, i){
58
						return {
59
							x: this._hScaler.scale * (i + 1 - this._hScaler.bounds.lower) + offsets.l,
60
							y: dim.height - offsets.b - this._vScaler.scale * (v - this._vScaler.bounds.lower)
61
						};
62
					}, this);
63
				}else{
64
					lpoly = dojo.map(run.data, function(v, i){
65
						return {
66
							x: this._hScaler.scale * (v.x - this._hScaler.bounds.lower) + offsets.l,
67
							y: dim.height - offsets.b - this._vScaler.scale * (v.y - this._vScaler.bounds.lower)
68
						};
69
					}, this);
70
				}
71
				if(!run.fill || !run.stroke){
72
					// need autogenerated color
73
					color = run.dyn.color = new dojo.Color(t.next("color"));
74
				}
75
				if(this.opt.areas){
76
					var apoly = dojo.clone(lpoly);
77
					apoly.push({x: lpoly[lpoly.length - 1].x, y: dim.height - offsets.b});
78
					apoly.push({x: lpoly[0].x, y: dim.height - offsets.b});
79
					apoly.push(lpoly[0]);
80
					var fill = run.fill ? run.fill : dc.augmentFill(t.series.fill, color);
81
					run.dyn.fill = s.createPolyline(apoly).setFill(fill).getFill();
82
				}
83
				if(this.opt.lines || this.opt.markers){
84
					// need a stroke
85
					stroke = run.stroke ? dc.makeStroke(run.stroke) : dc.augmentStroke(t.series.stroke, color);
86
					if(run.outline || t.series.outline){
87
						outline = dc.makeStroke(run.outline ? run.outline : t.series.outline);
88
						outline.width = 2 * outline.width + stroke.width;
89
					}
90
				}
91
				if(this.opt.markers){
92
					// need a marker
93
					marker = run.dyn.marker = run.marker ? run.marker : t.next("marker");
94
				}
95
				if(this.opt.shadows && stroke){
96
					var sh = this.opt.shadows, shadowColor = new dojo.Color([0, 0, 0, 0.3]),
97
						spoly = dojo.map(lpoly, function(c){
98
							return {x: c.x + sh.dx, y: c.y + sh.dy};
99
						}),
100
						shadowStroke = dojo.clone(outline ? outline : stroke);
101
					shadowStroke.color = shadowColor;
102
					shadowStroke.width += sh.dw ? sh.dw : 0;
103
					if(this.opt.lines){
104
						s.createPolyline(spoly).setStroke(shadowStroke);
105
					}
106
					if(this.opt.markers){
107
						dojo.forEach(spoly, function(c){
108
							s.createPath("M" + c.x + " " + c.y + " " + marker).setStroke(shadowStroke).setFill(shadowColor);
109
						}, this);
110
					}
111
				}
112
				if(this.opt.lines){
113
					if(outline){
114
						run.dyn.outline = s.createPolyline(lpoly).setStroke(outline).getStroke();
115
					}
116
					run.dyn.stroke = s.createPolyline(lpoly).setStroke(stroke).getStroke();
117
				}
118
				if(this.opt.markers){
119
					dojo.forEach(lpoly, function(c){
120
						var path = "M" + c.x + " " + c.y + " " + marker;
121
						if(outline){
122
							s.createPath(path).setStroke(outline);
123
						}
124
						s.createPath(path).setStroke(stroke).setFill(stroke.color);
125
					}, this);
126
				}
127
				run.dirty = false;
128
			}
129
			this.dirty = false;
130
			return this;
131
		}
132
	});
133
})();
134
 
135
}