Subversion Repositories Applications.papyrus

Rev

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