2150 |
mathias |
1 |
if(!dojo._hasResource["dojox.charting.plot3d.Bars"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
|
|
|
2 |
dojo._hasResource["dojox.charting.plot3d.Bars"] = true;
|
|
|
3 |
dojo.provide("dojox.charting.plot3d.Bars");
|
|
|
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.Bars", 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: "dull", color: "lime"};
|
|
|
25 |
if(kwArgs){
|
|
|
26 |
if("depth" in kwArgs){ this.depth = kwArgs.depth; }
|
|
|
27 |
if("gap" in kwArgs){ this.gap = kwArgs.gap; }
|
|
|
28 |
if("material" in kwArgs){
|
|
|
29 |
var m = kwArgs.material;
|
|
|
30 |
if(typeof m == "string" || m instanceof dojo.Color){
|
|
|
31 |
this.material.color = m;
|
|
|
32 |
}else{
|
|
|
33 |
this.material = m;
|
|
|
34 |
}
|
|
|
35 |
}
|
|
|
36 |
}
|
|
|
37 |
},
|
|
|
38 |
getDepth: function(){
|
|
|
39 |
if(this.depth == "auto"){
|
|
|
40 |
var w = this.width;
|
|
|
41 |
if(this.data && this.data.length){
|
|
|
42 |
w = w / this.data.length;
|
|
|
43 |
}
|
|
|
44 |
return w - 2 * this.gap;
|
|
|
45 |
}
|
|
|
46 |
return this.depth;
|
|
|
47 |
},
|
|
|
48 |
generate: function(chart, creator){
|
|
|
49 |
if(!this.data){ return this; }
|
|
|
50 |
var step = this.width / this.data.length, org = 0,
|
|
|
51 |
depth = this.depth == "auto" ? step - 2 * this.gap : this.depth,
|
|
|
52 |
scale = this.height / reduce(this.data, Math.max);
|
|
|
53 |
if(!creator){ creator = chart.view; }
|
|
|
54 |
for(var i = 0; i < this.data.length; ++i, org += step){
|
|
|
55 |
creator
|
|
|
56 |
.createCube({
|
|
|
57 |
bottom: {x: org + this.gap, y: 0, z: 0},
|
|
|
58 |
top: {x: org + step - this.gap, y: this.data[i] * scale, z: depth}
|
|
|
59 |
})
|
|
|
60 |
.setFill(this.material);
|
|
|
61 |
}
|
|
|
62 |
}
|
|
|
63 |
});
|
|
|
64 |
})();
|
|
|
65 |
|
|
|
66 |
}
|