Subversion Repositories Applications.papyrus

Rev

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

Rev Author Line No. Line
1318 alexandre_ 1
/*
2
	Copyright (c) 2004-2006, The Dojo Foundation
3
	All Rights Reserved.
4
 
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:
7
 
8
		http://dojotoolkit.org/community/licensing.shtml
9
*/
10
 
11
dojo.provide("dojo.charting.vml.Axis");
12
dojo.require("dojo.lang.common");
13
if (dojo.render.vml.capable) {
14
	dojo.extend(dojo.charting.Axis, {renderLines:function (plotArea, plot, plane) {
15
		if (this.nodes.lines) {
16
			while (this.nodes.lines.childNodes.length > 0) {
17
				this.nodes.lines.removeChild(this.nodes.lines.childNodes[0]);
18
			}
19
			if (this.nodes.lines.parentNode) {
20
				this.nodes.lines.parentNode.removeChild(this.nodes.lines);
21
				this.nodes.lines = null;
22
			}
23
		}
24
		var area = plotArea.getArea();
25
		var g = this.nodes.lines = document.createElement("div");
26
		g.setAttribute("id", this.getId() + "-lines");
27
		for (var i = 0; i < this._labels.length; i++) {
28
			if (this._labels[i].value == this.origin) {
29
				continue;
30
			}
31
			var v = this.getCoord(this._labels[i].value, plotArea, plot);
32
			var l = document.createElement("v:line");
33
			var str = document.createElement("v:stroke");
34
			str.dashstyle = "dot";
35
			l.appendChild(str);
36
			l.setAttribute("strokecolor", "#666");
37
			l.setAttribute("strokeweight", "1px");
38
			var s = l.style;
39
			s.position = "absolute";
40
			s.top = "0px";
41
			s.left = "0px";
42
			s.antialias = "false";
43
			if (plane == "x") {
44
				l.setAttribute("from", v + "px," + area.top + "px");
45
				l.setAttribute("to", v + "px," + area.bottom + "px");
46
			} else {
47
				if (plane == "y") {
48
					l.setAttribute("from", area.left + "px," + v + "px");
49
					l.setAttribute("to", area.right + "px," + v + "px");
50
				}
51
			}
52
			g.appendChild(l);
53
		}
54
		return g;
55
	}, renderTicks:function (plotArea, plot, plane, coord) {
56
		if (this.nodes.ticks) {
57
			while (this.nodes.ticks.childNodes.length > 0) {
58
				this.nodes.ticks.removeChild(this.nodes.ticks.childNodes[0]);
59
			}
60
			if (this.nodes.ticks.parentNode) {
61
				this.nodes.ticks.parentNode.removeChild(this.nodes.ticks);
62
				this.nodes.ticks = null;
63
			}
64
		}
65
		var g = this.nodes.ticks = document.createElement("div");
66
		g.setAttribute("id", this.getId() + "-ticks");
67
		for (var i = 0; i < this._labels.length; i++) {
68
			var v = this.getCoord(this._labels[i].value, plotArea, plot);
69
			var l = document.createElement("v:line");
70
			l.setAttribute("strokecolor", "#000");
71
			l.setAttribute("strokeweight", "1px");
72
			var s = l.style;
73
			s.position = "absolute";
74
			s.top = "0px";
75
			s.left = "0px";
76
			s.antialias = "false";
77
			if (plane == "x") {
78
				l.setAttribute("from", v + "px," + coord + "px");
79
				l.setAttribute("to", v + "px," + (coord + 3) + "px");
80
			} else {
81
				if (plane == "y") {
82
					l.setAttribute("from", (coord - 2) + "px," + v + "px");
83
					l.setAttribute("to", (coord + 2) + "px," + v + "px");
84
				}
85
			}
86
			g.appendChild(l);
87
		}
88
		return g;
89
	}, renderLabels:function (plotArea, plot, plane, coord, textSize, anchor) {
90
		function createLabel(label, x, y, textSize, anchor) {
91
			var text = document.createElement("div");
92
			var s = text.style;
93
			text.innerHTML = label;
94
			s.fontSize = textSize + "px";
95
			s.fontFamily = "sans-serif";
96
			s.position = "absolute";
97
			s.top = y + "px";
98
			if (anchor == "center") {
99
				s.left = x + "px";
100
				s.textAlign = "center";
101
			} else {
102
				if (anchor == "left") {
103
					s.left = x + "px";
104
					s.textAlign = "left";
105
				} else {
106
					if (anchor == "right") {
107
						s.right = x + "px";
108
						s.textAlign = "right";
109
					}
110
				}
111
			}
112
			return text;
113
		}
114
		if (this.nodes.labels) {
115
			while (this.nodes.labels.childNodes.length > 0) {
116
				this.nodes.labels.removeChild(this.nodes.labels.childNodes[0]);
117
			}
118
			if (this.nodes.labels.parentNode) {
119
				this.nodes.labels.parentNode.removeChild(this.nodes.labels);
120
				this.nodes.labels = null;
121
			}
122
		}
123
		var g = this.nodes.labels = document.createElement("div");
124
		g.setAttribute("id", this.getId() + "-labels");
125
		for (var i = 0; i < this._labels.length; i++) {
126
			var v = this.getCoord(this._labels[i].value, plotArea, plot);
127
			if (plane == "x") {
128
				var node = createLabel(this._labels[i].label, v, coord, textSize, anchor);
129
				document.body.appendChild(node);
130
				node.style.left = v - (node.offsetWidth / 2) + "px";
131
				g.appendChild(node);
132
			} else {
133
				if (plane == "y") {
134
					var node = createLabel(this._labels[i].label, coord, v, textSize, anchor);
135
					document.body.appendChild(node);
136
					node.style.top = v - (node.offsetHeight / 2) + "px";
137
					g.appendChild(node);
138
				}
139
			}
140
		}
141
		return g;
142
	}, render:function (plotArea, plot, drawAgainst, plane) {
143
		if (!this._rerender && this.nodes.main) {
144
			return this.nodes.main;
145
		}
146
		this._rerender = false;
147
		var area = plotArea.getArea();
148
		var stroke = 1;
149
		var style = "stroke:#000;stroke-width:" + stroke + "px;";
150
		var textSize = 10;
151
		var coord = drawAgainst.getCoord(this.origin, plotArea, plot);
152
		var g = this.nodes.main = document.createElement("div");
153
		g.setAttribute("id", this.getId());
154
		var line = this.nodes.axis = document.createElement("v:line");
155
		line.setAttribute("strokecolor", "#000");
156
		line.setAttribute("strokeweight", stroke + "px");
157
		var s = line.style;
158
		s.position = "absolute";
159
		s.top = "0px";
160
		s.left = "0px";
161
		s.antialias = "false";
162
		if (plane == "x") {
163
			line.setAttribute("from", area.left + "px," + coord + "px");
164
			line.setAttribute("to", area.right + "px," + coord + "px");
165
			var y = coord + Math.floor(textSize / 2);
166
			if (this.showLines) {
167
				g.appendChild(this.renderLines(plotArea, plot, plane, y));
168
			}
169
			if (this.showTicks) {
170
				g.appendChild(this.renderTicks(plotArea, plot, plane, coord));
171
			}
172
			if (this.showLabels) {
173
				g.appendChild(this.renderLabels(plotArea, plot, plane, y, textSize, "center"));
174
			}
175
			if (this.showLabel && this.label) {
176
				var x = plotArea.size.width / 2;
177
				var y = coord + Math.round(textSize * 1.5);
178
				var text = document.createElement("div");
179
				var s = text.style;
180
				text.innerHTML = this.label;
181
				s.fontSize = (textSize + 2) + "px";
182
				s.fontFamily = "sans-serif";
183
				s.fontWeight = "bold";
184
				s.position = "absolute";
185
				s.top = y + "px";
186
				s.left = x + "px";
187
				s.textAlign = "center";
188
				document.body.appendChild(text);
189
				text.style.left = x - (text.offsetWidth / 2) + "px";
190
				g.appendChild(text);
191
			}
192
		} else {
193
			line.setAttribute("from", coord + "px," + area.top + "px");
194
			line.setAttribute("to", coord + "px," + area.bottom + "px");
195
			var isMax = this.origin == drawAgainst.range.upper;
196
			var x = coord + 4;
197
			var anchor = "left";
198
			if (!isMax) {
199
				x = area.right - coord + textSize + 4;
200
				anchor = "right";
201
				if (coord == area.left) {
202
					x += (textSize * 2) - (textSize / 2);
203
				}
204
			}
205
			if (this.showLines) {
206
				g.appendChild(this.renderLines(plotArea, plot, plane, x));
207
			}
208
			if (this.showTicks) {
209
				g.appendChild(this.renderTicks(plotArea, plot, plane, coord));
210
			}
211
			if (this.showLabels) {
212
				g.appendChild(this.renderLabels(plotArea, plot, plane, x, textSize, anchor));
213
			}
214
			if (this.showLabel && this.label) {
215
				x += (textSize * 2) - 2;
216
				var y = plotArea.size.height / 2;
217
				var text = document.createElement("div");
218
				var s = text.style;
219
				text.innerHTML = this.label;
220
				s.fontSize = (textSize + 2) + "px";
221
				s.fontFamily = "sans-serif";
222
				s.fontWeight = "bold";
223
				s.position = "absolute";
224
				s.height = plotArea.size.height + "px";
225
				s.writingMode = "tb-rl";
226
				s.textAlign = "center";
227
				s[anchor] = x + "px";
228
				document.body.appendChild(text);
229
				s.top = y - (text.offsetHeight / 2) + "px";
230
				g.appendChild(text);
231
			}
232
		}
233
		g.appendChild(line);
234
		return g;
235
	}});
236
}
237