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.Plot");
12
dojo.require("dojo.lang.common");
13
dojo.require("dojo.charting.Axis");
14
dojo.require("dojo.charting.Series");
15
dojo.charting.RenderPlotSeries = {Singly:"single", Grouped:"grouped"};
16
dojo.charting.Plot = function (xaxis, yaxis, series) {
17
	var id = "dojo-charting-plot-" + dojo.charting.Plot.count++;
18
	this.getId = function () {
19
		return id;
20
	};
21
	this.setId = function (key) {
22
		id = key;
23
	};
24
	this.axisX = null;
25
	this.axisY = null;
26
	this.series = [];
27
	this.dataNode = null;
28
	this.renderType = dojo.charting.RenderPlotSeries.Singly;
29
	if (xaxis) {
30
		this.setAxis(xaxis, "x");
31
	}
32
	if (yaxis) {
33
		this.setAxis(yaxis, "y");
34
	}
35
	if (series) {
36
		for (var i = 0; i < series.length; i++) {
37
			this.addSeries(series[i]);
38
		}
39
	}
40
};
41
dojo.charting.Plot.count = 0;
42
dojo.extend(dojo.charting.Plot, {addSeries:function (series, plotter) {
43
	if (series.plotter) {
44
		this.series.push(series);
45
	} else {
46
		this.series.push({data:series, plotter:plotter || dojo.charting.Plotters["Default"]});
47
	}
48
}, setAxis:function (axis, which) {
49
	if (which.toLowerCase() == "x") {
50
		this.axisX = axis;
51
	} else {
52
		if (which.toLowerCase() == "y") {
53
			this.axisY = axis;
54
		}
55
	}
56
}, getRanges:function () {
57
	var xmin, xmax, ymin, ymax;
58
	xmin = ymin = Number.MAX_VALUE;
59
	xmax = ymax = Number.MIN_VALUE;
60
	for (var i = 0; i < this.series.length; i++) {
61
		var values = this.series[i].data.evaluate();
62
		for (var j = 0; j < values.length; j++) {
63
			var comp = values[j];
64
			xmin = Math.min(comp.x, xmin);
65
			ymin = Math.min(comp.y, ymin);
66
			xmax = Math.max(comp.x, xmax);
67
			ymax = Math.max(comp.y, ymax);
68
		}
69
	}
70
	return {x:{upper:xmax, lower:xmin}, y:{upper:ymax, lower:ymin}, toString:function () {
71
		return "[ x:" + xmax + " - " + xmin + ", y:" + ymax + " - " + ymin + "]";
72
	}};
73
}, destroy:function () {
74
	var node = this.dataNode;
75
	while (node && node.childNodes && node.childNodes.length > 0) {
76
		node.removeChild(node.childNodes[0]);
77
	}
78
	this.dataNode = null;
79
}});
80