Subversion Repositories Applications.papyrus

Rev

Rev 1372 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1372 Rev 1422
1
/*
1
/*
2
	Copyright (c) 2004-2006, The Dojo Foundation
2
	Copyright (c) 2004-2006, The Dojo Foundation
3
	All Rights Reserved.
3
	All Rights Reserved.
4
 
4
 
5
	Licensed under the Academic Free License version 2.1 or above OR the
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:
6
	modified BSD license. For more information on Dojo licensing, see:
7
 
7
 
8
		http://dojotoolkit.org/community/licensing.shtml
8
		http://dojotoolkit.org/community/licensing.shtml
9
*/
9
*/
-
 
10
 
-
 
11
 
10
 
12
 
11
dojo.provide("dojo.widget.svg.Chart");
13
dojo.provide("dojo.widget.svg.Chart");
12
dojo.require("dojo.widget.HtmlWidget");
14
dojo.require("dojo.widget.HtmlWidget");
13
dojo.require("dojo.widget.Chart");
15
dojo.require("dojo.widget.Chart");
14
dojo.require("dojo.html.layout");
16
dojo.require("dojo.html.layout");
15
dojo.require("dojo.math");
17
dojo.require("dojo.math");
16
dojo.require("dojo.svg");
18
dojo.require("dojo.svg");
17
dojo.require("dojo.gfx.color");
19
dojo.require("dojo.gfx.color");
18
dojo.require("dojo.json");
20
dojo.require("dojo.json");
19
dojo.widget.defineWidget("dojo.widget.svg.Chart", [dojo.widget.HtmlWidget, dojo.widget.Chart], function () {
21
dojo.widget.defineWidget("dojo.widget.svg.Chart", [dojo.widget.HtmlWidget, dojo.widget.Chart], function () {
20
	this.templatePath = null;
22
	this.templatePath = null;
21
	this.templateCssPath = null;
23
	this.templateCssPath = null;
22
	this._isInitialize = false;
24
	this._isInitialize = false;
23
	this.hasData = false;
25
	this.hasData = false;
24
	this.vectorNode = null;
26
	this.vectorNode = null;
25
	this.plotArea = null;
27
	this.plotArea = null;
26
	this.dataGroup = null;
28
	this.dataGroup = null;
27
	this.axisGroup = null;
29
	this.axisGroup = null;
28
	this.properties = {height:0, width:0, defaultWidth:600, defaultHeight:400, plotType:null, padding:{top:10, bottom:2, left:60, right:30}, axes:{x:{plotAt:0, label:"", unitLabel:"", unitType:Number, nUnitsToShow:10, range:{min:0, max:200}}, y:{plotAt:0, label:"", unitLabel:"", unitType:Number, nUnitsToShow:10, range:{min:0, max:200}}}};
30
	this.properties = {height:0, width:0, defaultWidth:600, defaultHeight:400, plotType:null, padding:{top:10, bottom:2, left:60, right:30}, axes:{x:{plotAt:0, label:"", unitLabel:"", unitType:Number, nUnitsToShow:10, range:{min:0, max:200}}, y:{plotAt:0, label:"", unitLabel:"", unitType:Number, nUnitsToShow:10, range:{min:0, max:200}}}};
29
}, {parseProperties:function (node) {
31
}, {parseProperties:function (node) {
30
	var bRangeX = false;
32
	var bRangeX = false;
31
	var bRangeY = false;
33
	var bRangeY = false;
32
	if (node.getAttribute("width")) {
34
	if (node.getAttribute("width")) {
33
		this.properties.width = node.getAttribute("width");
35
		this.properties.width = node.getAttribute("width");
34
	}
36
	}
35
	if (node.getAttribute("height")) {
37
	if (node.getAttribute("height")) {
36
		this.properties.height = node.getAttribute("height");
38
		this.properties.height = node.getAttribute("height");
37
	}
39
	}
38
	if (node.getAttribute("plotType")) {
40
	if (node.getAttribute("plotType")) {
39
		this.properties.plotType = node.getAttribute("plotType");
41
		this.properties.plotType = node.getAttribute("plotType");
40
	}
42
	}
41
	if (node.getAttribute("padding")) {
43
	if (node.getAttribute("padding")) {
42
		if (node.getAttribute("padding").indexOf(",") > -1) {
44
		if (node.getAttribute("padding").indexOf(",") > -1) {
43
			var p = node.getAttribute("padding").split(",");
45
			var p = node.getAttribute("padding").split(",");
44
		} else {
46
		} else {
45
			var p = node.getAttribute("padding").split(" ");
47
			var p = node.getAttribute("padding").split(" ");
46
		}
48
		}
47
		if (p.length == 1) {
49
		if (p.length == 1) {
48
			var pad = parseFloat(p[0]);
50
			var pad = parseFloat(p[0]);
49
			this.properties.padding.top = pad;
51
			this.properties.padding.top = pad;
50
			this.properties.padding.right = pad;
52
			this.properties.padding.right = pad;
51
			this.properties.padding.bottom = pad;
53
			this.properties.padding.bottom = pad;
52
			this.properties.padding.left = pad;
54
			this.properties.padding.left = pad;
53
		} else {
55
		} else {
54
			if (p.length == 2) {
56
			if (p.length == 2) {
55
				var padV = parseFloat(p[0]);
57
				var padV = parseFloat(p[0]);
56
				var padH = parseFloat(p[1]);
58
				var padH = parseFloat(p[1]);
57
				this.properties.padding.top = padV;
59
				this.properties.padding.top = padV;
58
				this.properties.padding.right = padH;
60
				this.properties.padding.right = padH;
59
				this.properties.padding.bottom = padV;
61
				this.properties.padding.bottom = padV;
60
				this.properties.padding.left = padH;
62
				this.properties.padding.left = padH;
61
			} else {
63
			} else {
62
				if (p.length == 4) {
64
				if (p.length == 4) {
63
					this.properties.padding.top = parseFloat(p[0]);
65
					this.properties.padding.top = parseFloat(p[0]);
64
					this.properties.padding.right = parseFloat(p[1]);
66
					this.properties.padding.right = parseFloat(p[1]);
65
					this.properties.padding.bottom = parseFloat(p[2]);
67
					this.properties.padding.bottom = parseFloat(p[2]);
66
					this.properties.padding.left = parseFloat(p[3]);
68
					this.properties.padding.left = parseFloat(p[3]);
67
				}
69
				}
68
			}
70
			}
69
		}
71
		}
70
	}
72
	}
71
	if (node.getAttribute("rangeX")) {
73
	if (node.getAttribute("rangeX")) {
72
		var p = node.getAttribute("rangeX");
74
		var p = node.getAttribute("rangeX");
73
		if (p.indexOf(",") > -1) {
75
		if (p.indexOf(",") > -1) {
74
			p = p.split(",");
76
			p = p.split(",");
75
		} else {
77
		} else {
76
			p = p.split(" ");
78
			p = p.split(" ");
77
		}
79
		}
78
		this.properties.axes.x.range.min = parseFloat(p[0]);
80
		this.properties.axes.x.range.min = parseFloat(p[0]);
79
		this.properties.axes.x.range.max = parseFloat(p[1]);
81
		this.properties.axes.x.range.max = parseFloat(p[1]);
80
		bRangeX = true;
82
		bRangeX = true;
81
	}
83
	}
82
	if (node.getAttribute("rangeY")) {
84
	if (node.getAttribute("rangeY")) {
83
		var p = node.getAttribute("rangeY");
85
		var p = node.getAttribute("rangeY");
84
		if (p.indexOf(",") > -1) {
86
		if (p.indexOf(",") > -1) {
85
			p = p.split(",");
87
			p = p.split(",");
86
		} else {
88
		} else {
87
			p = p.split(" ");
89
			p = p.split(" ");
88
		}
90
		}
89
		this.properties.axes.y.range.min = parseFloat(p[0]);
91
		this.properties.axes.y.range.min = parseFloat(p[0]);
90
		this.properties.axes.y.range.max = parseFloat(p[1]);
92
		this.properties.axes.y.range.max = parseFloat(p[1]);
91
		bRangeY = true;
93
		bRangeY = true;
92
	}
94
	}
93
	return {rangeX:bRangeX, rangeY:bRangeY};
95
	return {rangeX:bRangeX, rangeY:bRangeY};
94
}, setAxesPlot:function (table) {
96
}, setAxesPlot:function (table) {
95
	if (table.getAttribute("axisAt")) {
97
	if (table.getAttribute("axisAt")) {
96
		var p = table.getAttribute("axisAt");
98
		var p = table.getAttribute("axisAt");
97
		if (p.indexOf(",") > -1) {
99
		if (p.indexOf(",") > -1) {
98
			p = p.split(",");
100
			p = p.split(",");
99
		} else {
101
		} else {
100
			p = p.split(" ");
102
			p = p.split(" ");
101
		}
103
		}
102
		if (!isNaN(parseFloat(p[0]))) {
104
		if (!isNaN(parseFloat(p[0]))) {
103
			this.properties.axes.x.plotAt = parseFloat(p[0]);
105
			this.properties.axes.x.plotAt = parseFloat(p[0]);
104
		} else {
106
		} else {
105
			if (p[0].toLowerCase() == "ymin") {
107
			if (p[0].toLowerCase() == "ymin") {
106
				this.properties.axes.x.plotAt = this.properties.axes.y.range.min;
108
				this.properties.axes.x.plotAt = this.properties.axes.y.range.min;
107
			} else {
109
			} else {
108
				if (p[0].toLowerCase() == "ymax") {
110
				if (p[0].toLowerCase() == "ymax") {
109
					this.properties.axes.x.plotAt = this.properties.axes.y.range.max;
111
					this.properties.axes.x.plotAt = this.properties.axes.y.range.max;
110
				}
112
				}
111
			}
113
			}
112
		}
114
		}
113
		if (!isNaN(parseFloat(p[1]))) {
115
		if (!isNaN(parseFloat(p[1]))) {
114
			this.properties.axes.y.plotAt = parseFloat(p[1]);
116
			this.properties.axes.y.plotAt = parseFloat(p[1]);
115
		} else {
117
		} else {
116
			if (p[1].toLowerCase() == "xmin") {
118
			if (p[1].toLowerCase() == "xmin") {
117
				this.properties.axes.y.plotAt = this.properties.axes.x.range.min;
119
				this.properties.axes.y.plotAt = this.properties.axes.x.range.min;
118
			} else {
120
			} else {
119
				if (p[1].toLowerCase() == "xmax") {
121
				if (p[1].toLowerCase() == "xmax") {
120
					this.properties.axes.y.plotAt = this.properties.axes.x.range.max;
122
					this.properties.axes.y.plotAt = this.properties.axes.x.range.max;
121
				}
123
				}
122
			}
124
			}
123
		}
125
		}
124
	} else {
126
	} else {
125
		this.properties.axes.x.plotAt = this.properties.axes.y.range.min;
127
		this.properties.axes.x.plotAt = this.properties.axes.y.range.min;
126
		this.properties.axes.y.plotAt = this.properties.axes.x.range.min;
128
		this.properties.axes.y.plotAt = this.properties.axes.x.range.min;
127
	}
129
	}
128
}, drawVectorNode:function () {
130
}, drawVectorNode:function () {
129
	dojo.svg.g.suspend();
131
	dojo.svg.g.suspend();
130
	if (this.vectorNode) {
132
	if (this.vectorNode) {
131
		this.destroy();
133
		this.destroy();
132
	}
134
	}
133
	this.vectorNode = document.createElementNS(dojo.svg.xmlns.svg, "svg");
135
	this.vectorNode = document.createElementNS(dojo.svg.xmlns.svg, "svg");
134
	this.vectorNode.setAttribute("width", this.properties.width);
136
	this.vectorNode.setAttribute("width", this.properties.width);
135
	this.vectorNode.setAttribute("height", this.properties.height);
137
	this.vectorNode.setAttribute("height", this.properties.height);
136
	dojo.svg.g.resume();
138
	dojo.svg.g.resume();
137
}, drawPlotArea:function () {
139
}, drawPlotArea:function () {
138
	dojo.svg.g.suspend();
140
	dojo.svg.g.suspend();
139
	if (this.plotArea) {
141
	if (this.plotArea) {
140
		this.plotArea.parentNode.removeChild(this.plotArea);
142
		this.plotArea.parentNode.removeChild(this.plotArea);
141
		this.plotArea = null;
143
		this.plotArea = null;
142
	}
144
	}
143
	var defs = document.createElementNS(dojo.svg.xmlns.svg, "defs");
145
	var defs = document.createElementNS(dojo.svg.xmlns.svg, "defs");
144
	var clip = document.createElementNS(dojo.svg.xmlns.svg, "clipPath");
146
	var clip = document.createElementNS(dojo.svg.xmlns.svg, "clipPath");
145
	clip.setAttribute("id", "plotClip" + this.widgetId);
147
	clip.setAttribute("id", "plotClip" + this.widgetId);
146
	var rect = document.createElementNS(dojo.svg.xmlns.svg, "rect");
148
	var rect = document.createElementNS(dojo.svg.xmlns.svg, "rect");
147
	rect.setAttribute("x", this.properties.padding.left);
149
	rect.setAttribute("x", this.properties.padding.left);
148
	rect.setAttribute("y", this.properties.padding.top);
150
	rect.setAttribute("y", this.properties.padding.top);
149
	rect.setAttribute("width", this.properties.width - this.properties.padding.left - this.properties.padding.right);
151
	rect.setAttribute("width", this.properties.width - this.properties.padding.left - this.properties.padding.right);
150
	rect.setAttribute("height", this.properties.height - this.properties.padding.top - this.properties.padding.bottom);
152
	rect.setAttribute("height", this.properties.height - this.properties.padding.top - this.properties.padding.bottom);
151
	clip.appendChild(rect);
153
	clip.appendChild(rect);
152
	defs.appendChild(clip);
154
	defs.appendChild(clip);
153
	this.vectorNode.appendChild(defs);
155
	this.vectorNode.appendChild(defs);
154
	this.plotArea = document.createElementNS(dojo.svg.xmlns.svg, "g");
156
	this.plotArea = document.createElementNS(dojo.svg.xmlns.svg, "g");
155
	this.vectorNode.appendChild(this.plotArea);
157
	this.vectorNode.appendChild(this.plotArea);
156
	var rect = document.createElementNS(dojo.svg.xmlns.svg, "rect");
158
	var rect = document.createElementNS(dojo.svg.xmlns.svg, "rect");
157
	rect.setAttribute("x", this.properties.padding.left);
159
	rect.setAttribute("x", this.properties.padding.left);
158
	rect.setAttribute("y", this.properties.padding.top);
160
	rect.setAttribute("y", this.properties.padding.top);
159
	rect.setAttribute("width", this.properties.width - this.properties.padding.left - this.properties.padding.right);
161
	rect.setAttribute("width", this.properties.width - this.properties.padding.left - this.properties.padding.right);
160
	rect.setAttribute("height", this.properties.height - this.properties.padding.top - this.properties.padding.bottom);
162
	rect.setAttribute("height", this.properties.height - this.properties.padding.top - this.properties.padding.bottom);
161
	rect.setAttribute("fill", "#fff");
163
	rect.setAttribute("fill", "#fff");
162
	this.plotArea.appendChild(rect);
164
	this.plotArea.appendChild(rect);
163
	dojo.svg.g.resume();
165
	dojo.svg.g.resume();
164
}, drawDataGroup:function () {
166
}, drawDataGroup:function () {
165
	dojo.svg.g.suspend();
167
	dojo.svg.g.suspend();
166
	if (this.dataGroup) {
168
	if (this.dataGroup) {
167
		this.dataGroup.parentNode.removeChild(this.dataGroup);
169
		this.dataGroup.parentNode.removeChild(this.dataGroup);
168
		this.dataGroup = null;
170
		this.dataGroup = null;
169
	}
171
	}
170
	this.dataGroup = document.createElementNS(dojo.svg.xmlns.svg, "g");
172
	this.dataGroup = document.createElementNS(dojo.svg.xmlns.svg, "g");
171
	this.dataGroup.setAttribute("style", "clip-path:url(#plotClip" + this.widgetId + ");");
173
	this.dataGroup.setAttribute("style", "clip-path:url(#plotClip" + this.widgetId + ");");
172
	this.plotArea.appendChild(this.dataGroup);
174
	this.plotArea.appendChild(this.dataGroup);
173
	dojo.svg.g.resume();
175
	dojo.svg.g.resume();
174
}, drawAxes:function () {
176
}, drawAxes:function () {
175
	dojo.svg.g.suspend();
177
	dojo.svg.g.suspend();
176
	if (this.axisGroup) {
178
	if (this.axisGroup) {
177
		this.axisGroup.parentNode.removeChild(this.axisGroup);
179
		this.axisGroup.parentNode.removeChild(this.axisGroup);
178
		this.axisGroup = null;
180
		this.axisGroup = null;
179
	}
181
	}
180
	this.axisGroup = document.createElementNS(dojo.svg.xmlns.svg, "g");
182
	this.axisGroup = document.createElementNS(dojo.svg.xmlns.svg, "g");
181
	this.plotArea.appendChild(this.axisGroup);
183
	this.plotArea.appendChild(this.axisGroup);
182
	var stroke = 1;
184
	var stroke = 1;
183
	var line = document.createElementNS(dojo.svg.xmlns.svg, "line");
185
	var line = document.createElementNS(dojo.svg.xmlns.svg, "line");
184
	var y = dojo.widget.svg.Chart.Plotter.getY(this.properties.axes.x.plotAt, this);
186
	var y = dojo.widget.svg.Chart.Plotter.getY(this.properties.axes.x.plotAt, this);
185
	line.setAttribute("y1", y);
187
	line.setAttribute("y1", y);
186
	line.setAttribute("y2", y);
188
	line.setAttribute("y2", y);
187
	line.setAttribute("x1", this.properties.padding.left - stroke);
189
	line.setAttribute("x1", this.properties.padding.left - stroke);
188
	line.setAttribute("x2", this.properties.width - this.properties.padding.right);
190
	line.setAttribute("x2", this.properties.width - this.properties.padding.right);
189
	line.setAttribute("style", "stroke:#000;stroke-width:" + stroke + ";");
191
	line.setAttribute("style", "stroke:#000;stroke-width:" + stroke + ";");
190
	this.axisGroup.appendChild(line);
192
	this.axisGroup.appendChild(line);
191
	var textSize = 10;
193
	var textSize = 10;
192
	var text = document.createElementNS(dojo.svg.xmlns.svg, "text");
194
	var text = document.createElementNS(dojo.svg.xmlns.svg, "text");
193
	text.setAttribute("x", this.properties.padding.left);
195
	text.setAttribute("x", this.properties.padding.left);
194
	text.setAttribute("y", this.properties.height - this.properties.padding.bottom + textSize + 2);
196
	text.setAttribute("y", this.properties.height - this.properties.padding.bottom + textSize + 2);
195
	text.setAttribute("style", "text-anchor:middle;font-size:" + textSize + "px;fill:#000;");
197
	text.setAttribute("style", "text-anchor:middle;font-size:" + textSize + "px;fill:#000;");
196
	text.appendChild(document.createTextNode(dojo.math.round(parseFloat(this.properties.axes.x.range.min), 2)));
198
	text.appendChild(document.createTextNode(dojo.math.round(parseFloat(this.properties.axes.x.range.min), 2)));
197
	this.axisGroup.appendChild(text);
199
	this.axisGroup.appendChild(text);
198
	var text = document.createElementNS(dojo.svg.xmlns.svg, "text");
200
	var text = document.createElementNS(dojo.svg.xmlns.svg, "text");
199
	text.setAttribute("x", this.properties.width - this.properties.padding.right - (textSize / 2));
201
	text.setAttribute("x", this.properties.width - this.properties.padding.right - (textSize / 2));
200
	text.setAttribute("y", this.properties.height - this.properties.padding.bottom + textSize + 2);
202
	text.setAttribute("y", this.properties.height - this.properties.padding.bottom + textSize + 2);
201
	text.setAttribute("style", "text-anchor:middle;font-size:" + textSize + "px;fill:#000;");
203
	text.setAttribute("style", "text-anchor:middle;font-size:" + textSize + "px;fill:#000;");
202
	text.appendChild(document.createTextNode(dojo.math.round(parseFloat(this.properties.axes.x.range.max), 2)));
204
	text.appendChild(document.createTextNode(dojo.math.round(parseFloat(this.properties.axes.x.range.max), 2)));
203
	this.axisGroup.appendChild(text);
205
	this.axisGroup.appendChild(text);
204
	var line = document.createElementNS(dojo.svg.xmlns.svg, "line");
206
	var line = document.createElementNS(dojo.svg.xmlns.svg, "line");
205
	var x = dojo.widget.svg.Chart.Plotter.getX(this.properties.axes.y.plotAt, this);
207
	var x = dojo.widget.svg.Chart.Plotter.getX(this.properties.axes.y.plotAt, this);
206
	line.setAttribute("x1", x);
208
	line.setAttribute("x1", x);
207
	line.setAttribute("x2", x);
209
	line.setAttribute("x2", x);
208
	line.setAttribute("y1", this.properties.padding.top);
210
	line.setAttribute("y1", this.properties.padding.top);
209
	line.setAttribute("y2", this.properties.height - this.properties.padding.bottom);
211
	line.setAttribute("y2", this.properties.height - this.properties.padding.bottom);
210
	line.setAttribute("style", "stroke:#000;stroke-width:" + stroke + ";");
212
	line.setAttribute("style", "stroke:#000;stroke-width:" + stroke + ";");
211
	this.axisGroup.appendChild(line);
213
	this.axisGroup.appendChild(line);
212
	var text = document.createElementNS(dojo.svg.xmlns.svg, "text");
214
	var text = document.createElementNS(dojo.svg.xmlns.svg, "text");
213
	text.setAttribute("x", this.properties.padding.left - 4);
215
	text.setAttribute("x", this.properties.padding.left - 4);
214
	text.setAttribute("y", this.properties.height - this.properties.padding.bottom);
216
	text.setAttribute("y", this.properties.height - this.properties.padding.bottom);
215
	text.setAttribute("style", "text-anchor:end;font-size:" + textSize + "px;fill:#000;");
217
	text.setAttribute("style", "text-anchor:end;font-size:" + textSize + "px;fill:#000;");
216
	text.appendChild(document.createTextNode(dojo.math.round(parseFloat(this.properties.axes.y.range.min), 2)));
218
	text.appendChild(document.createTextNode(dojo.math.round(parseFloat(this.properties.axes.y.range.min), 2)));
217
	this.axisGroup.appendChild(text);
219
	this.axisGroup.appendChild(text);
218
	var text = document.createElementNS(dojo.svg.xmlns.svg, "text");
220
	var text = document.createElementNS(dojo.svg.xmlns.svg, "text");
219
	text.setAttribute("x", this.properties.padding.left - 4);
221
	text.setAttribute("x", this.properties.padding.left - 4);
220
	text.setAttribute("y", this.properties.padding.top + (textSize / 2));
222
	text.setAttribute("y", this.properties.padding.top + (textSize / 2));
221
	text.setAttribute("style", "text-anchor:end;font-size:" + textSize + "px;fill:#000;");
223
	text.setAttribute("style", "text-anchor:end;font-size:" + textSize + "px;fill:#000;");
222
	text.appendChild(document.createTextNode(dojo.math.round(parseFloat(this.properties.axes.y.range.max), 2)));
224
	text.appendChild(document.createTextNode(dojo.math.round(parseFloat(this.properties.axes.y.range.max), 2)));
223
	this.axisGroup.appendChild(text);
225
	this.axisGroup.appendChild(text);
224
	dojo.svg.g.resume();
226
	dojo.svg.g.resume();
225
}, init:function () {
227
}, init:function () {
226
	if (!this.properties.width || !this.properties.height) {
228
	if (!this.properties.width || !this.properties.height) {
227
		var box = dojo.html.getContentBox(this.domNode);
229
		var box = dojo.html.getContentBox(this.domNode);
228
		if (!this.properties.width) {
230
		if (!this.properties.width) {
229
			this.properties.width = (box.width < 32) ? this.properties.defaultWidth : box.width;
231
			this.properties.width = (box.width < 32) ? this.properties.defaultWidth : box.width;
230
		}
232
		}
231
		if (!this.properties.height) {
233
		if (!this.properties.height) {
232
			this.properties.height = (box.height < 32) ? this.properties.defaultHeight : box.height;
234
			this.properties.height = (box.height < 32) ? this.properties.defaultHeight : box.height;
233
		}
235
		}
234
	}
236
	}
235
	this.drawVectorNode();
237
	this.drawVectorNode();
236
	this.drawPlotArea();
238
	this.drawPlotArea();
237
	this.drawDataGroup();
239
	this.drawDataGroup();
238
	this.drawAxes();
240
	this.drawAxes();
239
	this.domNode.appendChild(this.vectorNode);
241
	this.domNode.appendChild(this.vectorNode);
240
	this.assignColors();
242
	this.assignColors();
241
	this._isInitialized = true;
243
	this._isInitialized = true;
242
}, destroy:function () {
244
}, destroy:function () {
243
	while (this.domNode.childNodes.length > 0) {
245
	while (this.domNode.childNodes.length > 0) {
244
		this.domNode.removeChild(this.domNode.childNodes.item(0));
246
		this.domNode.removeChild(this.domNode.childNodes.item(0));
245
	}
247
	}
246
	this.vectorNode = this.plotArea = this.dataGroup = this.axisGroup = null;
248
	this.vectorNode = this.plotArea = this.dataGroup = this.axisGroup = null;
247
}, render:function () {
249
}, render:function () {
248
	dojo.svg.g.suspend();
250
	dojo.svg.g.suspend();
249
	if (this.dataGroup) {
251
	if (this.dataGroup) {
250
		while (this.dataGroup.childNodes.length > 0) {
252
		while (this.dataGroup.childNodes.length > 0) {
251
			this.dataGroup.removeChild(this.dataGroup.childNodes.item(0));
253
			this.dataGroup.removeChild(this.dataGroup.childNodes.item(0));
252
		}
254
		}
253
	} else {
255
	} else {
254
		this.init();
256
		this.init();
255
	}
257
	}
256
	for (var i = 0; i < this.series.length; i++) {
258
	for (var i = 0; i < this.series.length; i++) {
257
		dojo.widget.svg.Chart.Plotter.plot(this.series[i], this);
259
		dojo.widget.svg.Chart.Plotter.plot(this.series[i], this);
258
	}
260
	}
259
	dojo.svg.g.resume();
261
	dojo.svg.g.resume();
260
}, postCreate:function () {
262
}, postCreate:function () {
261
	var table = this.domNode.getElementsByTagName("table")[0];
263
	var table = this.domNode.getElementsByTagName("table")[0];
262
	if (table) {
264
	if (table) {
263
		var ranges = this.parseProperties(table);
265
		var ranges = this.parseProperties(table);
264
		var bRangeX = false;
266
		var bRangeX = false;
265
		var bRangeY = false;
267
		var bRangeY = false;
266
		var axisValues = this.parseData(table);
268
		var axisValues = this.parseData(table);
267
		if (!bRangeX) {
269
		if (!bRangeX) {
268
			this.properties.axes.x.range = {min:axisValues.x.min, max:axisValues.x.max};
270
			this.properties.axes.x.range = {min:axisValues.x.min, max:axisValues.x.max};
269
		}
271
		}
270
		if (!bRangeY) {
272
		if (!bRangeY) {
271
			this.properties.axes.y.range = {min:axisValues.y.min, max:axisValues.y.max};
273
			this.properties.axes.y.range = {min:axisValues.y.min, max:axisValues.y.max};
272
		}
274
		}
273
		this.setAxesPlot(table);
275
		this.setAxesPlot(table);
274
		this.domNode.removeChild(table);
276
		this.domNode.removeChild(table);
275
	}
277
	}
276
	if (this.series.length > 0) {
278
	if (this.series.length > 0) {
277
		this.render();
279
		this.render();
278
	}
280
	}
279
}});
281
}});
280
dojo.widget.svg.Chart.Plotter = new function () {
282
dojo.widget.svg.Chart.Plotter = new function () {
281
	var self = this;
283
	var self = this;
282
	var plotters = {};
284
	var plotters = {};
283
	var types = dojo.widget.Chart.PlotTypes;
285
	var types = dojo.widget.Chart.PlotTypes;
284
	this.getX = function (value, chart) {
286
	this.getX = function (value, chart) {
285
		var v = parseFloat(value);
287
		var v = parseFloat(value);
286
		var min = chart.properties.axes.x.range.min;
288
		var min = chart.properties.axes.x.range.min;
287
		var max = chart.properties.axes.x.range.max;
289
		var max = chart.properties.axes.x.range.max;
288
		var ofst = 0 - min;
290
		var ofst = 0 - min;
289
		min += ofst;
291
		min += ofst;
290
		max += ofst;
292
		max += ofst;
291
		v += ofst;
293
		v += ofst;
292
		var xmin = chart.properties.padding.left;
294
		var xmin = chart.properties.padding.left;
293
		var xmax = chart.properties.width - chart.properties.padding.right;
295
		var xmax = chart.properties.width - chart.properties.padding.right;
294
		var x = (v * ((xmax - xmin) / max)) + xmin;
296
		var x = (v * ((xmax - xmin) / max)) + xmin;
295
		return x;
297
		return x;
296
	};
298
	};
297
	this.getY = function (value, chart) {
299
	this.getY = function (value, chart) {
298
		var v = parseFloat(value);
300
		var v = parseFloat(value);
299
		var max = chart.properties.axes.y.range.max;
301
		var max = chart.properties.axes.y.range.max;
300
		var min = chart.properties.axes.y.range.min;
302
		var min = chart.properties.axes.y.range.min;
301
		var ofst = 0;
303
		var ofst = 0;
302
		if (min < 0) {
304
		if (min < 0) {
303
			ofst += Math.abs(min);
305
			ofst += Math.abs(min);
304
		}
306
		}
305
		min += ofst;
307
		min += ofst;
306
		max += ofst;
308
		max += ofst;
307
		v += ofst;
309
		v += ofst;
308
		var ymin = chart.properties.height - chart.properties.padding.bottom;
310
		var ymin = chart.properties.height - chart.properties.padding.bottom;
309
		var ymax = chart.properties.padding.top;
311
		var ymax = chart.properties.padding.top;
310
		var y = (((ymin - ymax) / (max - min)) * (max - v)) + ymax;
312
		var y = (((ymin - ymax) / (max - min)) * (max - v)) + ymax;
311
		return y;
313
		return y;
312
	};
314
	};
313
	this.addPlotter = function (name, func) {
315
	this.addPlotter = function (name, func) {
314
		plotters[name] = func;
316
		plotters[name] = func;
315
	};
317
	};
316
	this.plot = function (series, chart) {
318
	this.plot = function (series, chart) {
317
		if (series.values.length == 0) {
319
		if (series.values.length == 0) {
318
			return;
320
			return;
319
		}
321
		}
320
		if (series.plotType && plotters[series.plotType]) {
322
		if (series.plotType && plotters[series.plotType]) {
321
			return plotters[series.plotType](series, chart);
323
			return plotters[series.plotType](series, chart);
322
		} else {
324
		} else {
323
			if (chart.plotType && plotters[chart.plotType]) {
325
			if (chart.plotType && plotters[chart.plotType]) {
324
				return plotters[chart.plotType](series, chart);
326
				return plotters[chart.plotType](series, chart);
325
			}
327
			}
326
		}
328
		}
327
	};
329
	};
328
	plotters["bar"] = function (series, chart) {
330
	plotters["bar"] = function (series, chart) {
329
		var space = 1;
331
		var space = 1;
330
		var lastW = 0;
332
		var lastW = 0;
331
		for (var i = 0; i < series.values.length; i++) {
333
		for (var i = 0; i < series.values.length; i++) {
332
			var x = self.getX(series.values[i].x, chart);
334
			var x = self.getX(series.values[i].x, chart);
333
			var w;
335
			var w;
334
			if (i == series.values.length - 1) {
336
			if (i == series.values.length - 1) {
335
				w = lastW;
337
				w = lastW;
336
			} else {
338
			} else {
337
				w = self.getX(series.values[i + 1].x, chart) - x - space;
339
				w = self.getX(series.values[i + 1].x, chart) - x - space;
338
				lastW = w;
340
				lastW = w;
339
			}
341
			}
340
			x -= (w / 2);
342
			x -= (w / 2);
341
			var yA = self.getY(chart.properties.axes.x.plotAt, chart);
343
			var yA = self.getY(chart.properties.axes.x.plotAt, chart);
342
			var y = self.getY(series.values[i].value, chart);
344
			var y = self.getY(series.values[i].value, chart);
343
			var h = Math.abs(yA - y);
345
			var h = Math.abs(yA - y);
344
			if (parseFloat(series.values[i].value) < chart.properties.axes.x.plotAt) {
346
			if (parseFloat(series.values[i].value) < chart.properties.axes.x.plotAt) {
345
				var oy = yA;
347
				var oy = yA;
346
				yA = y;
348
				yA = y;
347
				y = oy;
349
				y = oy;
348
			}
350
			}
349
			var bar = document.createElementNS(dojo.svg.xmlns.svg, "rect");
351
			var bar = document.createElementNS(dojo.svg.xmlns.svg, "rect");
350
			bar.setAttribute("fill", series.color);
352
			bar.setAttribute("fill", series.color);
351
			bar.setAttribute("title", series.label + ": " + series.values[i].value);
353
			bar.setAttribute("title", series.label + ": " + series.values[i].value);
352
			bar.setAttribute("stroke-width", "0");
354
			bar.setAttribute("stroke-width", "0");
353
			bar.setAttribute("x", x);
355
			bar.setAttribute("x", x);
354
			bar.setAttribute("y", y);
356
			bar.setAttribute("y", y);
355
			bar.setAttribute("width", w);
357
			bar.setAttribute("width", w);
356
			bar.setAttribute("height", h);
358
			bar.setAttribute("height", h);
357
			bar.setAttribute("fill-opacity", "0.9");
359
			bar.setAttribute("fill-opacity", "0.9");
358
			chart.dataGroup.appendChild(bar);
360
			chart.dataGroup.appendChild(bar);
359
		}
361
		}
360
	};
362
	};
361
	plotters["line"] = function (series, chart) {
363
	plotters["line"] = function (series, chart) {
362
		var tension = 1.5;
364
		var tension = 1.5;
363
		var line = document.createElementNS(dojo.svg.xmlns.svg, "path");
365
		var line = document.createElementNS(dojo.svg.xmlns.svg, "path");
364
		line.setAttribute("fill", "none");
366
		line.setAttribute("fill", "none");
365
		line.setAttribute("stroke", series.color);
367
		line.setAttribute("stroke", series.color);
366
		line.setAttribute("stroke-width", "2");
368
		line.setAttribute("stroke-width", "2");
367
		line.setAttribute("stroke-opacity", "0.85");
369
		line.setAttribute("stroke-opacity", "0.85");
368
		line.setAttribute("title", series.label);
370
		line.setAttribute("title", series.label);
369
		chart.dataGroup.appendChild(line);
371
		chart.dataGroup.appendChild(line);
370
		var path = [];
372
		var path = [];
371
		for (var i = 0; i < series.values.length; i++) {
373
		for (var i = 0; i < series.values.length; i++) {
372
			var x = self.getX(series.values[i].x, chart);
374
			var x = self.getX(series.values[i].x, chart);
373
			var y = self.getY(series.values[i].value, chart);
375
			var y = self.getY(series.values[i].value, chart);
374
			var dx = chart.properties.padding.left + 1;
376
			var dx = chart.properties.padding.left + 1;
375
			var dy = chart.properties.height - chart.properties.padding.bottom;
377
			var dy = chart.properties.height - chart.properties.padding.bottom;
376
			if (i > 0) {
378
			if (i > 0) {
377
				dx = x - self.getX(series.values[i - 1].x, chart);
379
				dx = x - self.getX(series.values[i - 1].x, chart);
378
				dy = self.getY(series.values[i - 1].value, chart);
380
				dy = self.getY(series.values[i - 1].value, chart);
379
			}
381
			}
380
			if (i == 0) {
382
			if (i == 0) {
381
				path.push("M");
383
				path.push("M");
382
			} else {
384
			} else {
383
				path.push("C");
385
				path.push("C");
384
				var cx = x - (tension - 1) * (dx / tension);
386
				var cx = x - (tension - 1) * (dx / tension);
385
				path.push(cx + "," + dy);
387
				path.push(cx + "," + dy);
386
				cx = x - (dx / tension);
388
				cx = x - (dx / tension);
387
				path.push(cx + "," + y);
389
				path.push(cx + "," + y);
388
			}
390
			}
389
			path.push(x + "," + y);
391
			path.push(x + "," + y);
390
		}
392
		}
391
		line.setAttribute("d", path.join(" "));
393
		line.setAttribute("d", path.join(" "));
392
	};
394
	};
393
	plotters["area"] = function (series, chart) {
395
	plotters["area"] = function (series, chart) {
394
		var tension = 1.5;
396
		var tension = 1.5;
395
		var line = document.createElementNS(dojo.svg.xmlns.svg, "path");
397
		var line = document.createElementNS(dojo.svg.xmlns.svg, "path");
396
		line.setAttribute("fill", series.color);
398
		line.setAttribute("fill", series.color);
397
		line.setAttribute("fill-opacity", "0.4");
399
		line.setAttribute("fill-opacity", "0.4");
398
		line.setAttribute("stroke", series.color);
400
		line.setAttribute("stroke", series.color);
399
		line.setAttribute("stroke-width", "1");
401
		line.setAttribute("stroke-width", "1");
400
		line.setAttribute("stroke-opacity", "0.8");
402
		line.setAttribute("stroke-opacity", "0.8");
401
		line.setAttribute("title", series.label);
403
		line.setAttribute("title", series.label);
402
		chart.dataGroup.appendChild(line);
404
		chart.dataGroup.appendChild(line);
403
		var path = [];
405
		var path = [];
404
		for (var i = 0; i < series.values.length; i++) {
406
		for (var i = 0; i < series.values.length; i++) {
405
			var x = self.getX(series.values[i].x, chart);
407
			var x = self.getX(series.values[i].x, chart);
406
			var y = self.getY(series.values[i].value, chart);
408
			var y = self.getY(series.values[i].value, chart);
407
			var dx = chart.properties.padding.left + 1;
409
			var dx = chart.properties.padding.left + 1;
408
			var dy = chart.properties.height - chart.properties.padding.bottom;
410
			var dy = chart.properties.height - chart.properties.padding.bottom;
409
			if (i > 0) {
411
			if (i > 0) {
410
				dx = x - self.getX(series.values[i - 1].x, chart);
412
				dx = x - self.getX(series.values[i - 1].x, chart);
411
				dy = self.getY(series.values[i - 1].value, chart);
413
				dy = self.getY(series.values[i - 1].value, chart);
412
			}
414
			}
413
			if (i == 0) {
415
			if (i == 0) {
414
				path.push("M");
416
				path.push("M");
415
			} else {
417
			} else {
416
				path.push("C");
418
				path.push("C");
417
				var cx = x - (tension - 1) * (dx / tension);
419
				var cx = x - (tension - 1) * (dx / tension);
418
				path.push(cx + "," + dy);
420
				path.push(cx + "," + dy);
419
				cx = x - (dx / tension);
421
				cx = x - (dx / tension);
420
				path.push(cx + "," + y);
422
				path.push(cx + "," + y);
421
			}
423
			}
422
			path.push(x + "," + y);
424
			path.push(x + "," + y);
423
		}
425
		}
424
		path.push("L");
426
		path.push("L");
425
		path.push(x + "," + self.getY(0, chart));
427
		path.push(x + "," + self.getY(0, chart));
426
		path.push("L");
428
		path.push("L");
427
		path.push(self.getX(0, chart) + "," + self.getY(0, chart));
429
		path.push(self.getX(0, chart) + "," + self.getY(0, chart));
428
		path.push("Z");
430
		path.push("Z");
429
		line.setAttribute("d", path.join(" "));
431
		line.setAttribute("d", path.join(" "));
430
	}, plotters["scatter"] = function (series, chart) {
432
	}, plotters["scatter"] = function (series, chart) {
431
		var r = 7;
433
		var r = 7;
432
		for (var i = 0; i < series.values.length; i++) {
434
		for (var i = 0; i < series.values.length; i++) {
433
			var x = self.getX(series.values[i].x, chart);
435
			var x = self.getX(series.values[i].x, chart);
434
			var y = self.getY(series.values[i].value, chart);
436
			var y = self.getY(series.values[i].value, chart);
435
			var point = document.createElementNS(dojo.svg.xmlns.svg, "path");
437
			var point = document.createElementNS(dojo.svg.xmlns.svg, "path");
436
			point.setAttribute("fill", series.color);
438
			point.setAttribute("fill", series.color);
437
			point.setAttribute("stroke-width", "0");
439
			point.setAttribute("stroke-width", "0");
438
			point.setAttribute("title", series.label + ": " + series.values[i].value);
440
			point.setAttribute("title", series.label + ": " + series.values[i].value);
439
			point.setAttribute("d", "M " + x + "," + (y - r) + " " + "Q " + x + "," + y + " " + (x + r) + "," + y + " " + "Q " + x + "," + y + " " + x + "," + (y + r) + " " + "Q " + x + "," + y + " " + (x - r) + "," + y + " " + "Q " + x + "," + y + " " + x + "," + (y - r) + " " + "Z");
441
			point.setAttribute("d", "M " + x + "," + (y - r) + " " + "Q " + x + "," + y + " " + (x + r) + "," + y + " " + "Q " + x + "," + y + " " + x + "," + (y + r) + " " + "Q " + x + "," + y + " " + (x - r) + "," + y + " " + "Q " + x + "," + y + " " + x + "," + (y - r) + " " + "Z");
440
			chart.dataGroup.appendChild(point);
442
			chart.dataGroup.appendChild(point);
441
		}
443
		}
442
	};
444
	};
443
	plotters["bubble"] = function (series, chart) {
445
	plotters["bubble"] = function (series, chart) {
444
		var minR = 1;
446
		var minR = 1;
445
		var min = chart.properties.axes.x.range.min;
447
		var min = chart.properties.axes.x.range.min;
446
		var max = chart.properties.axes.x.range.max;
448
		var max = chart.properties.axes.x.range.max;
447
		var ofst = 0 - min;
449
		var ofst = 0 - min;
448
		min += ofst;
450
		min += ofst;
449
		max += ofst;
451
		max += ofst;
450
		var xmin = chart.properties.padding.left;
452
		var xmin = chart.properties.padding.left;
451
		var xmax = chart.properties.width - chart.properties.padding.right;
453
		var xmax = chart.properties.width - chart.properties.padding.right;
452
		var factor = (max - min) / (xmax - xmin) * 25;
454
		var factor = (max - min) / (xmax - xmin) * 25;
453
		for (var i = 0; i < series.values.length; i++) {
455
		for (var i = 0; i < series.values.length; i++) {
454
			var size = series.values[i].size;
456
			var size = series.values[i].size;
455
			if (isNaN(parseFloat(size))) {
457
			if (isNaN(parseFloat(size))) {
456
				size = minR;
458
				size = minR;
457
			}
459
			}
458
			var point = document.createElementNS(dojo.svg.xmlns.svg, "circle");
460
			var point = document.createElementNS(dojo.svg.xmlns.svg, "circle");
459
			point.setAttribute("stroke-width", 0);
461
			point.setAttribute("stroke-width", 0);
460
			point.setAttribute("fill", series.color);
462
			point.setAttribute("fill", series.color);
461
			point.setAttribute("fill-opacity", "0.8");
463
			point.setAttribute("fill-opacity", "0.8");
462
			point.setAttribute("r", (parseFloat(size) * factor) / 2);
464
			point.setAttribute("r", (parseFloat(size) * factor) / 2);
463
			point.setAttribute("cx", self.getX(series.values[i].x, chart));
465
			point.setAttribute("cx", self.getX(series.values[i].x, chart));
464
			point.setAttribute("cy", self.getY(series.values[i].value, chart));
466
			point.setAttribute("cy", self.getY(series.values[i].value, chart));
465
			point.setAttribute("title", series.label + ": " + series.values[i].value + " (" + size + ")");
467
			point.setAttribute("title", series.label + ": " + series.values[i].value + " (" + size + ")");
466
			chart.dataGroup.appendChild(point);
468
			chart.dataGroup.appendChild(point);
467
		}
469
		}
468
	};
470
	};
469
}();
471
}();
470
 
472