Subversion Repositories Applications.papyrus

Rev

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

Rev 1372 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.Axis");
13
dojo.provide("dojo.charting.Axis");
12
dojo.require("dojo.lang.common");
14
dojo.require("dojo.lang.common");
13
dojo.charting.Axis = function (label, scale, labels) {
15
dojo.charting.Axis = function (label, scale, labels) {
14
	var id = "dojo-charting-axis-" + dojo.charting.Axis.count++;
16
	var id = "dojo-charting-axis-" + dojo.charting.Axis.count++;
15
	this.getId = function () {
17
	this.getId = function () {
16
		return id;
18
		return id;
17
	};
19
	};
18
	this.setId = function (key) {
20
	this.setId = function (key) {
19
		id = key;
21
		id = key;
20
	};
22
	};
21
	this.scale = scale || "linear";
23
	this.scale = scale || "linear";
22
	this.label = label || "";
24
	this.label = label || "";
23
	this.showLabel = true;
25
	this.showLabel = true;
24
	this.showLabels = true;
26
	this.showLabels = true;
25
	this.showLines = false;
27
	this.showLines = false;
26
	this.showTicks = false;
28
	this.showTicks = false;
27
	this.range = {upper:100, lower:0};
29
	this.range = {upper:100, lower:0};
28
	this.origin = "min";
30
	this.origin = "min";
29
	this._origin = null;
31
	this._origin = null;
30
	this.labels = labels || [];
32
	this.labels = labels || [];
31
	this._labels = [];
33
	this._labels = [];
32
	this.nodes = {main:null, axis:null, label:null, labels:null, lines:null, ticks:null};
34
	this.nodes = {main:null, axis:null, label:null, labels:null, lines:null, ticks:null};
33
	this._rerender = false;
35
	this._rerender = false;
34
};
36
};
35
dojo.charting.Axis.count = 0;
37
dojo.charting.Axis.count = 0;
36
dojo.extend(dojo.charting.Axis, {getCoord:function (val, plotArea, plot) {
38
dojo.extend(dojo.charting.Axis, {getCoord:function (val, plotArea, plot) {
37
	val = parseFloat(val, 10);
39
	val = parseFloat(val, 10);
38
	var area = plotArea.getArea();
40
	var area = plotArea.getArea();
39
	if (plot.axisX == this) {
41
	if (plot.axisX == this) {
40
		var offset = 0 - this.range.lower;
42
		var offset = 0 - this.range.lower;
41
		var min = this.range.lower + offset;
43
		var min = this.range.lower + offset;
42
		var max = this.range.upper + offset;
44
		var max = this.range.upper + offset;
43
		val += offset;
45
		val += offset;
44
		return (val * ((area.right - area.left) / max)) + area.left;
46
		return (val * ((area.right - area.left) / max)) + area.left;
45
	} else {
47
	} else {
46
		var max = this.range.upper;
48
		var max = this.range.upper;
47
		var min = this.range.lower;
49
		var min = this.range.lower;
48
		var offset = 0;
50
		var offset = 0;
49
		if (min < 0) {
51
		if (min < 0) {
50
			offset += Math.abs(min);
52
			offset += Math.abs(min);
51
		}
53
		}
52
		max += offset;
54
		max += offset;
53
		min += offset;
55
		min += offset;
54
		val += offset;
56
		val += offset;
55
		var pmin = area.bottom;
57
		var pmin = area.bottom;
56
		var pmax = area.top;
58
		var pmax = area.top;
57
		return (((pmin - pmax) / (max - min)) * (max - val)) + pmax;
59
		return (((pmin - pmax) / (max - min)) * (max - val)) + pmax;
58
	}
60
	}
59
}, initializeOrigin:function (drawAgainst, plane) {
61
}, initializeOrigin:function (drawAgainst, plane) {
60
	if (this._origin == null) {
62
	if (this._origin == null) {
61
		this._origin = this.origin;
63
		this._origin = this.origin;
62
	}
64
	}
63
	if (isNaN(this._origin)) {
65
	if (isNaN(this._origin)) {
64
		if (this._origin.toLowerCase() == "max") {
66
		if (this._origin.toLowerCase() == "max") {
65
			this.origin = drawAgainst.range[(plane == "y") ? "upper" : "lower"];
67
			this.origin = drawAgainst.range[(plane == "y") ? "upper" : "lower"];
66
		} else {
68
		} else {
67
			if (this._origin.toLowerCase() == "min") {
69
			if (this._origin.toLowerCase() == "min") {
68
				this.origin = drawAgainst.range[(plane == "y") ? "lower" : "upper"];
70
				this.origin = drawAgainst.range[(plane == "y") ? "lower" : "upper"];
69
			} else {
71
			} else {
70
				this.origin = 0;
72
				this.origin = 0;
71
			}
73
			}
72
		}
74
		}
73
	}
75
	}
74
}, initializeLabels:function () {
76
}, initializeLabels:function () {
75
	this._labels = [];
77
	this._labels = [];
76
	if (this.labels.length == 0) {
78
	if (this.labels.length == 0) {
77
		this.showLabels = false;
79
		this.showLabels = false;
78
		this.showLines = false;
80
		this.showLines = false;
79
		this.showTicks = false;
81
		this.showTicks = false;
80
	} else {
82
	} else {
81
		if (this.labels[0].label && this.labels[0].value != null) {
83
		if (this.labels[0].label && this.labels[0].value != null) {
82
			for (var i = 0; i < this.labels.length; i++) {
84
			for (var i = 0; i < this.labels.length; i++) {
83
				this._labels.push(this.labels[i]);
85
				this._labels.push(this.labels[i]);
84
			}
86
			}
85
		} else {
87
		} else {
86
			if (!isNaN(this.labels[0])) {
88
			if (!isNaN(this.labels[0])) {
87
				for (var i = 0; i < this.labels.length; i++) {
89
				for (var i = 0; i < this.labels.length; i++) {
88
					this._labels.push({label:this.labels[i], value:this.labels[i]});
90
					this._labels.push({label:this.labels[i], value:this.labels[i]});
89
				}
91
				}
90
			} else {
92
			} else {
91
				var a = [];
93
				var a = [];
92
				for (var i = 0; i < this.labels.length; i++) {
94
				for (var i = 0; i < this.labels.length; i++) {
93
					a.push(this.labels[i]);
95
					a.push(this.labels[i]);
94
				}
96
				}
95
				var s = a.shift();
97
				var s = a.shift();
96
				this._labels.push({label:s, value:this.range.lower});
98
				this._labels.push({label:s, value:this.range.lower});
97
				if (a.length > 0) {
99
				if (a.length > 0) {
98
					var s = a.pop();
100
					var s = a.pop();
99
					this._labels.push({label:s, value:this.range.upper});
101
					this._labels.push({label:s, value:this.range.upper});
100
				}
102
				}
101
				if (a.length > 0) {
103
				if (a.length > 0) {
102
					var range = this.range.upper - this.range.lower;
104
					var range = this.range.upper - this.range.lower;
103
					var step = range / (this.labels.length - 1);
105
					var step = range / (this.labels.length - 1);
104
					for (var i = 1; i <= a.length; i++) {
106
					for (var i = 1; i <= a.length; i++) {
105
						this._labels.push({label:a[i - 1], value:this.range.lower + (step * i)});
107
						this._labels.push({label:a[i - 1], value:this.range.lower + (step * i)});
106
					}
108
					}
107
				}
109
				}
108
			}
110
			}
109
		}
111
		}
110
	}
112
	}
111
}, initialize:function (plotArea, plot, drawAgainst, plane) {
113
}, initialize:function (plotArea, plot, drawAgainst, plane) {
112
	this.destroy();
114
	this.destroy();
113
	this.initializeOrigin(drawAgainst, plane);
115
	this.initializeOrigin(drawAgainst, plane);
114
	this.initializeLabels();
116
	this.initializeLabels();
115
	var node = this.render(plotArea, plot, drawAgainst, plane);
117
	var node = this.render(plotArea, plot, drawAgainst, plane);
116
	return node;
118
	return node;
117
}, destroy:function () {
119
}, destroy:function () {
118
	for (var p in this.nodes) {
120
	for (var p in this.nodes) {
119
		while (this.nodes[p] && this.nodes[p].childNodes.length > 0) {
121
		while (this.nodes[p] && this.nodes[p].childNodes.length > 0) {
120
			this.nodes[p].removeChild(this.nodes[p].childNodes[0]);
122
			this.nodes[p].removeChild(this.nodes[p].childNodes[0]);
121
		}
123
		}
122
		if (this.nodes[p] && this.nodes[p].parentNode) {
124
		if (this.nodes[p] && this.nodes[p].parentNode) {
123
			this.nodes[p].parentNode.removeChild(this.nodes[p]);
125
			this.nodes[p].parentNode.removeChild(this.nodes[p]);
124
		}
126
		}
125
		this.nodes[p] = null;
127
		this.nodes[p] = null;
126
	}
128
	}
127
}});
129
}});
128
dojo.requireIf(dojo.render.svg.capable, "dojo.charting.svg.Axis");
130
dojo.requireIf(dojo.render.svg.capable, "dojo.charting.svg.Axis");
129
dojo.requireIf(dojo.render.vml.capable, "dojo.charting.vml.Axis");
131
dojo.requireIf(dojo.render.vml.capable, "dojo.charting.vml.Axis");
130
 
132