1 | define(["dojox/gfx3d", "dojo/_base/window", "dojo/_base/declare", "dojo/_base/Color", "./Base"], |
---|
2 | function(gfx3d, win, declare, Color, Base) { |
---|
3 | |
---|
4 | // reduce function borrowed from dojox.fun |
---|
5 | var reduce = function(/*Array*/ a, /*Function|String|Array*/ f, /*Object?*/ o){ |
---|
6 | // summary: repeatedly applies a binary function to an array from left |
---|
7 | // to right; returns the final value. |
---|
8 | a = typeof a == "string" ? a.split("") : a; o = o || win.global; |
---|
9 | var z = a[0]; |
---|
10 | for(var i = 1; i < a.length; z = f.call(o, z, a[i++])); |
---|
11 | return z; // Object |
---|
12 | }; |
---|
13 | /*===== |
---|
14 | var Base = dojox.charting.plot3d.Base; |
---|
15 | =====*/ |
---|
16 | return declare("dojox.charting.plot3d.Bars", Base, { |
---|
17 | constructor: function(width, height, kwArgs){ |
---|
18 | this.depth = "auto"; |
---|
19 | this.gap = 0; |
---|
20 | this.data = []; |
---|
21 | this.material = {type: "plastic", finish: "dull", color: "lime"}; |
---|
22 | if(kwArgs){ |
---|
23 | if("depth" in kwArgs){ this.depth = kwArgs.depth; } |
---|
24 | if("gap" in kwArgs){ this.gap = kwArgs.gap; } |
---|
25 | if("material" in kwArgs){ |
---|
26 | var m = kwArgs.material; |
---|
27 | if(typeof m == "string" || m instanceof Color){ |
---|
28 | this.material.color = m; |
---|
29 | }else{ |
---|
30 | this.material = m; |
---|
31 | } |
---|
32 | } |
---|
33 | } |
---|
34 | }, |
---|
35 | getDepth: function(){ |
---|
36 | if(this.depth == "auto"){ |
---|
37 | var w = this.width; |
---|
38 | if(this.data && this.data.length){ |
---|
39 | w = w / this.data.length; |
---|
40 | } |
---|
41 | return w - 2 * this.gap; |
---|
42 | } |
---|
43 | return this.depth; |
---|
44 | }, |
---|
45 | generate: function(chart, creator){ |
---|
46 | if(!this.data){ return this; } |
---|
47 | var step = this.width / this.data.length, org = 0, |
---|
48 | depth = this.depth == "auto" ? step - 2 * this.gap : this.depth, |
---|
49 | scale = this.height / reduce(this.data, Math.max); |
---|
50 | if(!creator){ creator = chart.view; } |
---|
51 | for(var i = 0; i < this.data.length; ++i, org += step){ |
---|
52 | creator |
---|
53 | .createCube({ |
---|
54 | bottom: {x: org + this.gap, y: 0, z: 0}, |
---|
55 | top: {x: org + step - this.gap, y: this.data[i] * scale, z: depth} |
---|
56 | }) |
---|
57 | .setFill(this.material); |
---|
58 | } |
---|
59 | } |
---|
60 | }); |
---|
61 | }); |
---|