Subversion Repositories Applications.papyrus

Rev

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