Subversion Repositories Applications.papyrus

Rev

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