Subversion Repositories Applications.papyrus

Rev

Rev 1318 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1318 Rev 1422
1
/*
1
/*
2
	Copyright (c) 2004-2006, The Dojo Foundation
2
	Copyright (c) 2004-2006, The Dojo Foundation
3
	All Rights Reserved.
3
	All Rights Reserved.
4
 
4
 
5
	Licensed under the Academic Free License version 2.1 or above OR the
5
	Licensed under the Academic Free License version 2.1 or above OR the
6
	modified BSD license. For more information on Dojo licensing, see:
6
	modified BSD license. For more information on Dojo licensing, see:
7
 
7
 
8
		http://dojotoolkit.org/community/licensing.shtml
8
		http://dojotoolkit.org/community/licensing.shtml
9
*/
9
*/
-
 
10
 
-
 
11
 
10
 
12
 
11
dojo.provide("dojo.charting.svg.Axis");
13
dojo.provide("dojo.charting.svg.Axis");
12
dojo.require("dojo.lang.common");
14
dojo.require("dojo.lang.common");
13
if (dojo.render.svg.capable) {
15
if (dojo.render.svg.capable) {
14
	dojo.extend(dojo.charting.Axis, {renderLines:function (plotArea, plot, plane) {
16
	dojo.extend(dojo.charting.Axis, {renderLines:function (plotArea, plot, plane) {
15
		if (this.nodes.lines) {
17
		if (this.nodes.lines) {
16
			while (this.nodes.lines.childNodes.length > 0) {
18
			while (this.nodes.lines.childNodes.length > 0) {
17
				this.nodes.lines.removeChild(this.nodes.lines.childNodes[0]);
19
				this.nodes.lines.removeChild(this.nodes.lines.childNodes[0]);
18
			}
20
			}
19
			if (this.nodes.lines.parentNode) {
21
			if (this.nodes.lines.parentNode) {
20
				this.nodes.lines.parentNode.removeChild(this.nodes.lines);
22
				this.nodes.lines.parentNode.removeChild(this.nodes.lines);
21
				this.nodes.lines = null;
23
				this.nodes.lines = null;
22
			}
24
			}
23
		}
25
		}
24
		var area = plotArea.getArea();
26
		var area = plotArea.getArea();
25
		var g = this.nodes.lines = document.createElementNS(dojo.svg.xmlns.svg, "g");
27
		var g = this.nodes.lines = document.createElementNS(dojo.svg.xmlns.svg, "g");
26
		g.setAttribute("id", this.getId() + "-lines");
28
		g.setAttribute("id", this.getId() + "-lines");
27
		for (var i = 0; i < this._labels.length; i++) {
29
		for (var i = 0; i < this._labels.length; i++) {
28
			if (this._labels[i].value == this.origin) {
30
			if (this._labels[i].value == this.origin) {
29
				continue;
31
				continue;
30
			}
32
			}
31
			var v = this.getCoord(this._labels[i].value, plotArea, plot);
33
			var v = this.getCoord(this._labels[i].value, plotArea, plot);
32
			var l = document.createElementNS(dojo.svg.xmlns.svg, "line");
34
			var l = document.createElementNS(dojo.svg.xmlns.svg, "line");
33
			l.setAttribute("style", "stroke:#999;stroke-width:1px;stroke-dasharray:1,4;");
35
			l.setAttribute("style", "stroke:#999;stroke-width:1px;stroke-dasharray:1,4;");
34
			if (plane == "x") {
36
			if (plane == "x") {
35
				l.setAttribute("y1", area.top);
37
				l.setAttribute("y1", area.top);
36
				l.setAttribute("y2", area.bottom);
38
				l.setAttribute("y2", area.bottom);
37
				l.setAttribute("x1", v);
39
				l.setAttribute("x1", v);
38
				l.setAttribute("x2", v);
40
				l.setAttribute("x2", v);
39
			} else {
41
			} else {
40
				if (plane == "y") {
42
				if (plane == "y") {
41
					l.setAttribute("y1", v);
43
					l.setAttribute("y1", v);
42
					l.setAttribute("y2", v);
44
					l.setAttribute("y2", v);
43
					l.setAttribute("x1", area.left);
45
					l.setAttribute("x1", area.left);
44
					l.setAttribute("x2", area.right);
46
					l.setAttribute("x2", area.right);
45
				}
47
				}
46
			}
48
			}
47
			g.appendChild(l);
49
			g.appendChild(l);
48
		}
50
		}
49
		return g;
51
		return g;
50
	}, renderTicks:function (plotArea, plot, plane, coord) {
52
	}, renderTicks:function (plotArea, plot, plane, coord) {
51
		if (this.nodes.ticks) {
53
		if (this.nodes.ticks) {
52
			while (this.nodes.ticks.childNodes.length > 0) {
54
			while (this.nodes.ticks.childNodes.length > 0) {
53
				this.nodes.ticks.removeChild(this.nodes.ticks.childNodes[0]);
55
				this.nodes.ticks.removeChild(this.nodes.ticks.childNodes[0]);
54
			}
56
			}
55
			if (this.nodes.ticks.parentNode) {
57
			if (this.nodes.ticks.parentNode) {
56
				this.nodes.ticks.parentNode.removeChild(this.nodes.ticks);
58
				this.nodes.ticks.parentNode.removeChild(this.nodes.ticks);
57
				this.nodes.ticks = null;
59
				this.nodes.ticks = null;
58
			}
60
			}
59
		}
61
		}
60
		var g = this.nodes.ticks = document.createElementNS(dojo.svg.xmlns.svg, "g");
62
		var g = this.nodes.ticks = document.createElementNS(dojo.svg.xmlns.svg, "g");
61
		g.setAttribute("id", this.getId() + "-ticks");
63
		g.setAttribute("id", this.getId() + "-ticks");
62
		for (var i = 0; i < this._labels.length; i++) {
64
		for (var i = 0; i < this._labels.length; i++) {
63
			var v = this.getCoord(this._labels[i].value, plotArea, plot);
65
			var v = this.getCoord(this._labels[i].value, plotArea, plot);
64
			var l = document.createElementNS(dojo.svg.xmlns.svg, "line");
66
			var l = document.createElementNS(dojo.svg.xmlns.svg, "line");
65
			l.setAttribute("style", "stroke:#000;stroke-width:1pt;");
67
			l.setAttribute("style", "stroke:#000;stroke-width:1pt;");
66
			if (plane == "x") {
68
			if (plane == "x") {
67
				l.setAttribute("y1", coord);
69
				l.setAttribute("y1", coord);
68
				l.setAttribute("y2", coord + 3);
70
				l.setAttribute("y2", coord + 3);
69
				l.setAttribute("x1", v);
71
				l.setAttribute("x1", v);
70
				l.setAttribute("x2", v);
72
				l.setAttribute("x2", v);
71
			} else {
73
			} else {
72
				if (plane == "y") {
74
				if (plane == "y") {
73
					l.setAttribute("y1", v);
75
					l.setAttribute("y1", v);
74
					l.setAttribute("y2", v);
76
					l.setAttribute("y2", v);
75
					l.setAttribute("x1", coord - 2);
77
					l.setAttribute("x1", coord - 2);
76
					l.setAttribute("x2", coord + 2);
78
					l.setAttribute("x2", coord + 2);
77
				}
79
				}
78
			}
80
			}
79
			g.appendChild(l);
81
			g.appendChild(l);
80
		}
82
		}
81
		return g;
83
		return g;
82
	}, renderLabels:function (plotArea, plot, plane, coord, textSize, anchor) {
84
	}, renderLabels:function (plotArea, plot, plane, coord, textSize, anchor) {
83
		function createLabel(label, x, y, textSize, anchor) {
85
		function createLabel(label, x, y, textSize, anchor) {
84
			var text = document.createElementNS(dojo.svg.xmlns.svg, "text");
86
			var text = document.createElementNS(dojo.svg.xmlns.svg, "text");
85
			text.setAttribute("x", x);
87
			text.setAttribute("x", x);
86
			text.setAttribute("y", (plane == "x" ? y : y + 2));
88
			text.setAttribute("y", (plane == "x" ? y : y + 2));
87
			text.setAttribute("style", "text-anchor:" + anchor + ";font-family:sans-serif;font-size:" + textSize + "px;fill:#000;");
89
			text.setAttribute("style", "text-anchor:" + anchor + ";font-family:sans-serif;font-size:" + textSize + "px;fill:#000;");
88
			text.appendChild(document.createTextNode(label));
90
			text.appendChild(document.createTextNode(label));
89
			return text;
91
			return text;
90
		}
92
		}
91
		if (this.nodes.labels) {
93
		if (this.nodes.labels) {
92
			while (this.nodes.labels.childNodes.length > 0) {
94
			while (this.nodes.labels.childNodes.length > 0) {
93
				this.nodes.labels.removeChild(this.nodes.labels.childNodes[0]);
95
				this.nodes.labels.removeChild(this.nodes.labels.childNodes[0]);
94
			}
96
			}
95
			if (this.nodes.labels.parentNode) {
97
			if (this.nodes.labels.parentNode) {
96
				this.nodes.labels.parentNode.removeChild(this.nodes.labels);
98
				this.nodes.labels.parentNode.removeChild(this.nodes.labels);
97
				this.nodes.labels = null;
99
				this.nodes.labels = null;
98
			}
100
			}
99
		}
101
		}
100
		var g = this.nodes.labels = document.createElementNS(dojo.svg.xmlns.svg, "g");
102
		var g = this.nodes.labels = document.createElementNS(dojo.svg.xmlns.svg, "g");
101
		g.setAttribute("id", this.getId() + "-labels");
103
		g.setAttribute("id", this.getId() + "-labels");
102
		for (var i = 0; i < this._labels.length; i++) {
104
		for (var i = 0; i < this._labels.length; i++) {
103
			var v = this.getCoord(this._labels[i].value, plotArea, plot);
105
			var v = this.getCoord(this._labels[i].value, plotArea, plot);
104
			if (plane == "x") {
106
			if (plane == "x") {
105
				g.appendChild(createLabel(this._labels[i].label, v, coord, textSize, anchor));
107
				g.appendChild(createLabel(this._labels[i].label, v, coord, textSize, anchor));
106
			} else {
108
			} else {
107
				if (plane == "y") {
109
				if (plane == "y") {
108
					g.appendChild(createLabel(this._labels[i].label, coord, v, textSize, anchor));
110
					g.appendChild(createLabel(this._labels[i].label, coord, v, textSize, anchor));
109
				}
111
				}
110
			}
112
			}
111
		}
113
		}
112
		return g;
114
		return g;
113
	}, render:function (plotArea, plot, drawAgainst, plane) {
115
	}, render:function (plotArea, plot, drawAgainst, plane) {
114
		if (!this._rerender && this.nodes.main) {
116
		if (!this._rerender && this.nodes.main) {
115
			return this.nodes.main;
117
			return this.nodes.main;
116
		}
118
		}
117
		this._rerender = false;
119
		this._rerender = false;
118
		var area = plotArea.getArea();
120
		var area = plotArea.getArea();
119
		var stroke = 1;
121
		var stroke = 1;
120
		var style = "stroke:#000;stroke-width:" + stroke + "px;";
122
		var style = "stroke:#000;stroke-width:" + stroke + "px;";
121
		var textSize = 10;
123
		var textSize = 10;
122
		var coord = drawAgainst.getCoord(this.origin, plotArea, plot);
124
		var coord = drawAgainst.getCoord(this.origin, plotArea, plot);
123
		this.nodes.main = document.createElementNS(dojo.svg.xmlns.svg, "g");
125
		this.nodes.main = document.createElementNS(dojo.svg.xmlns.svg, "g");
124
		var g = this.nodes.main;
126
		var g = this.nodes.main;
125
		g.setAttribute("id", this.getId());
127
		g.setAttribute("id", this.getId());
126
		var line = this.nodes.axis = document.createElementNS(dojo.svg.xmlns.svg, "line");
128
		var line = this.nodes.axis = document.createElementNS(dojo.svg.xmlns.svg, "line");
127
		if (plane == "x") {
129
		if (plane == "x") {
128
			line.setAttribute("y1", coord);
130
			line.setAttribute("y1", coord);
129
			line.setAttribute("y2", coord);
131
			line.setAttribute("y2", coord);
130
			line.setAttribute("x1", area.left - stroke);
132
			line.setAttribute("x1", area.left - stroke);
131
			line.setAttribute("x2", area.right + stroke);
133
			line.setAttribute("x2", area.right + stroke);
132
			line.setAttribute("style", style);
134
			line.setAttribute("style", style);
133
			var y = coord + textSize + 2;
135
			var y = coord + textSize + 2;
134
			if (this.showLines) {
136
			if (this.showLines) {
135
				g.appendChild(this.renderLines(plotArea, plot, plane, y));
137
				g.appendChild(this.renderLines(plotArea, plot, plane, y));
136
			}
138
			}
137
			if (this.showTicks) {
139
			if (this.showTicks) {
138
				g.appendChild(this.renderTicks(plotArea, plot, plane, coord));
140
				g.appendChild(this.renderTicks(plotArea, plot, plane, coord));
139
			}
141
			}
140
			if (this.showLabels) {
142
			if (this.showLabels) {
141
				g.appendChild(this.renderLabels(plotArea, plot, plane, y, textSize, "middle"));
143
				g.appendChild(this.renderLabels(plotArea, plot, plane, y, textSize, "middle"));
142
			}
144
			}
143
			if (this.showLabel && this.label) {
145
			if (this.showLabel && this.label) {
144
				var x = plotArea.size.width / 2;
146
				var x = plotArea.size.width / 2;
145
				var text = document.createElementNS(dojo.svg.xmlns.svg, "text");
147
				var text = document.createElementNS(dojo.svg.xmlns.svg, "text");
146
				text.setAttribute("x", x);
148
				text.setAttribute("x", x);
147
				text.setAttribute("y", (coord + (textSize * 2) + (textSize / 2)));
149
				text.setAttribute("y", (coord + (textSize * 2) + (textSize / 2)));
148
				text.setAttribute("style", "text-anchor:middle;font-family:sans-serif;font-weight:bold;font-size:" + (textSize + 2) + "px;fill:#000;");
150
				text.setAttribute("style", "text-anchor:middle;font-family:sans-serif;font-weight:bold;font-size:" + (textSize + 2) + "px;fill:#000;");
149
				text.appendChild(document.createTextNode(this.label));
151
				text.appendChild(document.createTextNode(this.label));
150
				g.appendChild(text);
152
				g.appendChild(text);
151
			}
153
			}
152
		} else {
154
		} else {
153
			line.setAttribute("x1", coord);
155
			line.setAttribute("x1", coord);
154
			line.setAttribute("x2", coord);
156
			line.setAttribute("x2", coord);
155
			line.setAttribute("y1", area.top);
157
			line.setAttribute("y1", area.top);
156
			line.setAttribute("y2", area.bottom);
158
			line.setAttribute("y2", area.bottom);
157
			line.setAttribute("style", style);
159
			line.setAttribute("style", style);
158
			var isMax = this.origin == drawAgainst.range.upper;
160
			var isMax = this.origin == drawAgainst.range.upper;
159
			var x = coord + (isMax ? 4 : -4);
161
			var x = coord + (isMax ? 4 : -4);
160
			var anchor = isMax ? "start" : "end";
162
			var anchor = isMax ? "start" : "end";
161
			if (this.showLines) {
163
			if (this.showLines) {
162
				g.appendChild(this.renderLines(plotArea, plot, plane, x));
164
				g.appendChild(this.renderLines(plotArea, plot, plane, x));
163
			}
165
			}
164
			if (this.showTicks) {
166
			if (this.showTicks) {
165
				g.appendChild(this.renderTicks(plotArea, plot, plane, coord));
167
				g.appendChild(this.renderTicks(plotArea, plot, plane, coord));
166
			}
168
			}
167
			if (this.showLabels) {
169
			if (this.showLabels) {
168
				g.appendChild(this.renderLabels(plotArea, plot, plane, x, textSize, anchor));
170
				g.appendChild(this.renderLabels(plotArea, plot, plane, x, textSize, anchor));
169
			}
171
			}
170
			if (this.showLabel && this.label) {
172
			if (this.showLabel && this.label) {
171
				var x = isMax ? (coord + (textSize * 2) + (textSize / 2)) : (coord - (textSize * 4));
173
				var x = isMax ? (coord + (textSize * 2) + (textSize / 2)) : (coord - (textSize * 4));
172
				var y = plotArea.size.height / 2;
174
				var y = plotArea.size.height / 2;
173
				var text = document.createElementNS(dojo.svg.xmlns.svg, "text");
175
				var text = document.createElementNS(dojo.svg.xmlns.svg, "text");
174
				text.setAttribute("x", x);
176
				text.setAttribute("x", x);
175
				text.setAttribute("y", y);
177
				text.setAttribute("y", y);
176
				text.setAttribute("transform", "rotate(90, " + x + ", " + y + ")");
178
				text.setAttribute("transform", "rotate(90, " + x + ", " + y + ")");
177
				text.setAttribute("style", "text-anchor:middle;font-family:sans-serif;font-weight:bold;font-size:" + (textSize + 2) + "px;fill:#000;");
179
				text.setAttribute("style", "text-anchor:middle;font-family:sans-serif;font-weight:bold;font-size:" + (textSize + 2) + "px;fill:#000;");
178
				text.appendChild(document.createTextNode(this.label));
180
				text.appendChild(document.createTextNode(this.label));
179
				g.appendChild(text);
181
				g.appendChild(text);
180
			}
182
			}
181
		}
183
		}
182
		g.appendChild(line);
184
		g.appendChild(line);
183
		return g;
185
		return g;
184
	}});
186
	}});
185
}
187
}
186
 
188