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