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