Subversion Repositories Applications.papyrus

Rev

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