Subversion Repositories Applications.papyrus

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
2150 mathias 1
if(!dojo._hasResource["dojox.charting.plot3d.Cylinders"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
2
dojo._hasResource["dojox.charting.plot3d.Cylinders"] = true;
3
dojo.provide("dojox.charting.plot3d.Cylinders");
4
 
5
dojo.require("dojox.charting.plot3d.Base");
6
 
7
(function(){
8
 
9
	// reduce function borrowed from dojox.fun
10
	var reduce = function(/*Array*/ a, /*Function|String|Array*/ f, /*Object?*/ o){
11
		// summary: repeatedly applies a binary function to an array from left
12
		//	to right; returns the final value.
13
		a = typeof a == "string" ? a.split("") : a; o = o || dojo.global;
14
		var z = a[0];
15
		for(var i = 1; i < a.length; z = f.call(o, z, a[i++]));
16
		return z;	// Object
17
	};
18
 
19
	dojo.declare("dojox.charting.plot3d.Cylinders", dojox.charting.plot3d.Base, {
20
		constructor: function(width, height, kwArgs){
21
			this.depth = "auto";
22
			this.gap   = 0;
23
			this.data  = [];
24
			this.material = {type: "plastic", finish: "shiny", color: "lime"};
25
			this.outline  = null;
26
			if(kwArgs){
27
				if("depth" in kwArgs){ this.depth = kwArgs.depth; }
28
				if("gap"   in kwArgs){ this.gap   = kwArgs.gap; }
29
				if("material" in kwArgs){
30
					var m = kwArgs.material;
31
					if(typeof m == "string" || m instanceof dojo.Color){
32
						this.material.color = m;
33
					}else{
34
						this.material = m;
35
					}
36
				}
37
				if("outline" in kwArgs){ this.outline = kwArgs.outline; }
38
			}
39
		},
40
		getDepth: function(){
41
			if(this.depth == "auto"){
42
				var w = this.width;
43
				if(this.data && this.data.length){
44
					w = w / this.data.length;
45
				}
46
				return w - 2 * this.gap;
47
			}
48
			return this.depth;
49
		},
50
		generate: function(chart, creator){
51
			if(!this.data){ return this; }
52
			var step = this.width / this.data.length, org = 0,
53
				scale = this.height / reduce(this.data, Math.max);
54
			if(!creator){ creator = chart.view; }
55
			for(var i = 0; i < this.data.length; ++i, org += step){
56
				creator
57
					.createCylinder({
58
						center: {x: org + step / 2, y: 0, z: 0},
59
						radius: step / 2 - this.gap,
60
						height: this.data[i] * scale
61
					})
62
					.setTransform(dojox.gfx3d.matrix.rotateXg(-90))
63
					.setFill(this.material).setStroke(this.outline);
64
			}
65
		}
66
	});
67
})();
68
 
69
}