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
 
11
dojo.provide("dojo.charting.PlotArea");
12
dojo.require("dojo.lang.common");
13
dojo.require("dojo.gfx.color");
14
dojo.require("dojo.gfx.color.hsl");
15
dojo.require("dojo.charting.Plot");
16
dojo.charting.PlotArea = function () {
17
	var id = "dojo-charting-plotarea-" + dojo.charting.PlotArea.count++;
18
	this.getId = function () {
19
		return id;
20
	};
21
	this.setId = function (key) {
22
		id = key;
23
	};
24
	this.areaType = "standard";
25
	this.plots = [];
26
	this.size = {width:600, height:400};
27
	this.padding = {top:10, right:10, bottom:20, left:20};
28
	this.nodes = {main:null, area:null, background:null, axes:null, plots:null};
29
	this._color = {h:140, s:120, l:120, step:27};
30
};
31
dojo.charting.PlotArea.count = 0;
32
dojo.extend(dojo.charting.PlotArea, {nextColor:function () {
33
	var rgb = dojo.gfx.color.hsl2rgb(this._color.h, this._color.s, this._color.l);
34
	this._color.h = (this._color.h + this._color.step) % 360;
35
	while (this._color.h < 140) {
36
		this._color.h += this._color.step;
37
	}
38
	return dojo.gfx.color.rgb2hex(rgb[0], rgb[1], rgb[2]);
39
}, getArea:function () {
40
	return {left:this.padding.left, right:this.size.width - this.padding.right, top:this.padding.top, bottom:this.size.height - this.padding.bottom, toString:function () {
41
		var a = [this.top, this.right, this.bottom, this.left];
42
		return "[" + a.join() + "]";
43
	}};
44
}, getAxes:function () {
45
	var axes = {};
46
	for (var i = 0; i < this.plots.length; i++) {
47
		var plot = this.plots[i];
48
		axes[plot.axisX.getId()] = {axis:plot.axisX, drawAgainst:plot.axisY, plot:plot, plane:"x"};
49
		axes[plot.axisY.getId()] = {axis:plot.axisY, drawAgainst:plot.axisX, plot:plot, plane:"y"};
50
	}
51
	return axes;
52
}, getLegendInfo:function () {
53
	var a = [];
54
	for (var i = 0; i < this.plots.length; i++) {
55
		for (var j = 0; j < this.plots[i].series.length; j++) {
56
			var data = this.plots[i].series[j].data;
57
			a.push({label:data.label, color:data.color});
58
		}
59
	}
60
	return a;
61
}, setAxesRanges:function () {
62
	var ranges = {};
63
	var axes = {};
64
	for (var i = 0; i < this.plots.length; i++) {
65
		var plot = this.plots[i];
66
		var ranges = plot.getRanges();
67
		var x = ranges.x;
68
		var y = ranges.y;
69
		var ax, ay;
70
		if (!axes[plot.axisX.getId()]) {
71
			axes[plot.axisX.getId()] = plot.axisX;
72
			ranges[plot.axisX.getId()] = {upper:x.upper, lower:x.lower};
73
		}
74
		ax = ranges[plot.axisX.getId()];
75
		ax.upper = Math.max(ax.upper, x.upper);
76
		ax.lower = Math.min(ax.lower, x.lower);
77
		if (!axes[plot.axisY.getId()]) {
78
			axes[plot.axisY.getId()] = plot.axisY;
79
			ranges[plot.axisY.getId()] = {upper:y.upper, lower:y.lower};
80
		}
81
		ay = ranges[plot.axisY.getId()];
82
		ay.upper = Math.max(ay.upper, y.upper);
83
		ay.lower = Math.min(ay.lower, y.lower);
84
	}
85
	for (var p in axes) {
86
		axes[p].range = ranges[p];
87
	}
88
}, render:function (kwArgs, applyToData) {
89
	if (!this.nodes.main || !this.nodes.area || !this.nodes.background || !this.nodes.plots || !this.nodes.axes) {
90
		this.initialize();
91
	}
92
	this.resize();
93
	for (var i = 0; i < this.plots.length; i++) {
94
		var plot = this.plots[i];
95
		if (plot.dataNode) {
96
			this.nodes.plots.removeChild(plot.dataNode);
97
		}
98
		var target = this.initializePlot(plot);
99
		switch (plot.renderType) {
100
		  case dojo.charting.RenderPlotSeries.Grouped:
101
			if (plot.series[0]) {
102
				target.appendChild(plot.series[0].plotter(this, plot, kwArgs, applyToData));
103
			}
104
			break;
105
		  case dojo.charting.RenderPlotSeries.Singly:
106
		  default:
107
			for (var j = 0; j < plot.series.length; j++) {
108
				var series = plot.series[j];
109
				var data = series.data.evaluate(kwArgs);
110
				target.appendChild(series.plotter(data, this, plot, applyToData));
111
			}
112
		}
113
		this.nodes.plots.appendChild(target);
114
	}
115
}, destroy:function () {
116
	for (var i = 0; i < this.plots.length; i++) {
117
		this.plots[i].destroy();
118
	}
119
	for (var p in this.nodes) {
120
		var node = this.nodes[p];
121
		if (!node) {
122
			continue;
123
		}
124
		if (!node.childNodes) {
125
			continue;
126
		}
127
		while (node.childNodes.length > 0) {
128
			node.removeChild(node.childNodes[0]);
129
		}
130
		this.nodes[p] = null;
131
	}
132
}});
133
dojo.requireIf(dojo.render.svg.capable, "dojo.charting.svg.PlotArea");
134
dojo.requireIf(dojo.render.vml.capable, "dojo.charting.vml.PlotArea");
135