[483] | 1 | define(["dojox/gfx3d/matrix", "dojo/_base/declare", "dojo/_base/Color", "dojo/_base/kernel", "dojo/has", "./Base"], |
---|
| 2 | function(matrix3d, declare, Color, kernel, 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.Cylinders", Base, { |
---|
| 16 | constructor: function(width, height, kwArgs){ |
---|
| 17 | this.depth = "auto"; |
---|
| 18 | this.gap = 0; |
---|
| 19 | this.data = []; |
---|
| 20 | this.material = {type: "plastic", finish: "shiny", color: "lime"}; |
---|
| 21 | this.outline = null; |
---|
| 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 | if("outline" in kwArgs){ this.outline = kwArgs.outline; } |
---|
| 34 | } |
---|
| 35 | }, |
---|
| 36 | getDepth: function(){ |
---|
| 37 | if(this.depth == "auto"){ |
---|
| 38 | var w = this.width; |
---|
| 39 | if(this.data && this.data.length){ |
---|
| 40 | w = w / this.data.length; |
---|
| 41 | } |
---|
| 42 | return w - 2 * this.gap; |
---|
| 43 | } |
---|
| 44 | return this.depth; |
---|
| 45 | }, |
---|
| 46 | generate: function(chart, creator){ |
---|
| 47 | if(!this.data){ return this; } |
---|
| 48 | var step = this.width / this.data.length, org = 0, |
---|
| 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 | .createCylinder({ |
---|
| 54 | center: {x: org + step / 2, y: 0, z: 0}, |
---|
| 55 | radius: step / 2 - this.gap, |
---|
| 56 | height: this.data[i] * scale |
---|
| 57 | }) |
---|
| 58 | .setTransform(matrix3d.rotateXg(-90)) |
---|
| 59 | .setFill(this.material).setStroke(this.outline); |
---|
| 60 | } |
---|
| 61 | if(has("dojo-bidi")){ |
---|
| 62 | this._checkOrientation(chart); |
---|
| 63 | } |
---|
| 64 | } |
---|
| 65 | }); |
---|
| 66 | }); |
---|
| 67 | |
---|