source: Dev/trunk/src/client/dojox/charting/plot3d/Bars.js @ 512

Last change on this file since 512 was 483, checked in by hendrikvanantwerpen, 11 years ago

Added Dojo 1.9.3 release.

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