Subversion Repositories Applications.papyrus

Rev

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