aboutsummaryrefslogtreecommitdiff
path: root/includes/js/dojox/charting/plot2d/Grid.js
blob: 52cb34850641d25b7f1c4f96d52193785d10b16c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
if(!dojo._hasResource["dojox.charting.plot2d.Grid"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
dojo._hasResource["dojox.charting.plot2d.Grid"] = true;
dojo.provide("dojox.charting.plot2d.Grid");

dojo.require("dojox.charting.Element");
dojo.require("dojox.charting.plot2d.common");
dojo.require("dojox.lang.functional");

(function(){
	var du = dojox.lang.utils;

	dojo.declare("dojox.charting.plot2d.Grid", dojox.charting.Element, {
		defaultParams: {
			hAxis: "x",			// use a horizontal axis named "x"
			vAxis: "y",			// use a vertical axis named "y"
			hMajorLines: true,	// draw horizontal major lines
			hMinorLines: false,	// draw horizontal minor lines
			vMajorLines: true,	// draw vertical major lines
			vMinorLines: false,	// draw vertical minor lines
			hStripes: "none",	// TBD
			vStripes: "none"	// TBD
		},
		optionalParams: {},	// no optional parameters
		
		constructor: function(chart, kwArgs){
			this.opt = dojo.clone(this.defaultParams);
			du.updateWithObject(this.opt, kwArgs);
			this.hAxis = this.opt.hAxis;
			this.vAxis = this.opt.vAxis;
		},
		clear: function(){
			this._hAxis = null;
			this._vAxis = null;
			this.dirty = true;
			return this;
		},
		setAxis: function(axis){
			if(axis){
				this[axis.vertical ? "_vAxis" : "_hAxis"] = axis;
			}
			return this;
		},
		addSeries: function(run){
			// nothing
			return this;
		},
		calculateAxes: function(dim){
			// nothing
			return this;
		},
		getRequiredColors: function(){
			return 0;
		},
		render: function(dim, offsets){
			// draw horizontal stripes and lines
			if(!this.dirty){ return this; }
			this.cleanGroup();
			var s = this.group, ta = this.chart.theme.axis,
				scaler = this._vAxis.getScaler();
			if(this.opt.hMinorLines && scaler.minor.tick){
				for(var i = 0; i < scaler.minor.count; ++i){
					var y = dim.height - offsets.b - scaler.scale * 
							(scaler.minor.start - scaler.bounds.lower + i * scaler.minor.tick);
					s.createLine({
						x1: offsets.l,
						y1: y,
						x2: dim.width - offsets.r,
						y2: y
					}).setStroke(ta.minorTick);
				}
			}
			if(this.opt.hMajorLines && scaler.major.tick){
				for(var i = 0; i < scaler.major.count; ++i){
					var y = dim.height - offsets.b - scaler.scale * 
							(scaler.major.start - scaler.bounds.lower + i * scaler.major.tick);
					s.createLine({
						x1: offsets.l,
						y1: y,
						x2: dim.width - offsets.r,
						y2: y
					}).setStroke(ta.majorTick);
				}
			}
			// draw vertical stripes and lines
			scaler = this._hAxis.getScaler();
			if(this.opt.vMinorLines && scaler.minor.tick){
				for(var i = 0; i < scaler.minor.count; ++i){
					var x = offsets.l + scaler.scale * 
							(scaler.minor.start - scaler.bounds.lower + i * scaler.minor.tick);
					s.createLine({
						x1: x,
						y1: offsets.t,
						x2: x,
						y2: dim.height - offsets.b
					}).setStroke(ta.minorTick);
				}
			}
			if(this.opt.vMajorLines && scaler.major.tick){
				for(var i = 0; i < scaler.major.count; ++i){
					var x = offsets.l + scaler.scale * 
							(scaler.major.start - scaler.bounds.lower + i * scaler.major.tick);
					s.createLine({
						x1: x,
						y1: offsets.t,
						x2: x,
						y2: dim.height - offsets.b
					}).setStroke(ta.majorTick);
				}
			}
			this.dirty = false;
			return this;
		}
	});
})();

}