| 1 |
define(["dojo/_base/array", "dojo/dom","dojo/_base/declare", "dojox/gfx", "dojox/gfx3d", |
| 2 |
"dojo/has", "dojo/has!dojo-bidi?./bidi/Chart3D"], |
| 3 |
function(arr, dom, declare, gfx, gfx3d, has, BidiChart3D){ |
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
var observerVector = {x: 0, y: 0, z: 1}, v = gfx3d.vector, n = gfx.normalizedLength; |
| 25 |
|
| 26 |
var Chart3D = declare(has("dojo-bidi")? "dojox.charting.NonBidiChart3D" : "dojox.charting.Chart3D", null, { |
| 27 |
constructor: function(node, lights, camera, theme){ |
| 28 |
|
| 29 |
this.node = dom.byId(node); |
| 30 |
this.surface = gfx.createSurface(this.node, n(this.node.style.width), n(this.node.style.height)); |
| 31 |
this.view = this.surface.createViewport(); |
| 32 |
this.view.setLights(lights.lights, lights.ambient, lights.specular); |
| 33 |
this.view.setCameraTransform(camera); |
| 34 |
this.theme = theme; |
| 35 |
|
| 36 |
|
| 37 |
this.walls = []; |
| 38 |
this.plots = []; |
| 39 |
}, |
| 40 |
|
| 41 |
|
| 42 |
generate: function(){ |
| 43 |
return this._generateWalls()._generatePlots(); |
| 44 |
}, |
| 45 |
invalidate: function(){ |
| 46 |
this.view.invalidate(); |
| 47 |
return this; |
| 48 |
}, |
| 49 |
render: function(){ |
| 50 |
this.view.render(); |
| 51 |
return this; |
| 52 |
}, |
| 53 |
addPlot: function(plot){ |
| 54 |
return this._add(this.plots, plot); |
| 55 |
}, |
| 56 |
removePlot: function(plot){ |
| 57 |
return this._remove(this.plots, plot); |
| 58 |
}, |
| 59 |
addWall: function(wall){ |
| 60 |
return this._add(this.walls, wall); |
| 61 |
}, |
| 62 |
removeWall: function(wall){ |
| 63 |
return this._remove(this.walls, wall); |
| 64 |
}, |
| 65 |
|
| 66 |
|
| 67 |
_add: function(array, item){ |
| 68 |
if(!arr.some(array, function(i){ return i == item; })){ |
| 69 |
array.push(item); |
| 70 |
this.view.invalidate(); |
| 71 |
} |
| 72 |
return this; |
| 73 |
}, |
| 74 |
_remove: function(array, item){ |
| 75 |
var a = arr.filter(array, function(i){ return i != item; }); |
| 76 |
return a.length < array.length ? (array = a, this.invalidate()) : this; |
| 77 |
}, |
| 78 |
_generateWalls: function(){ |
| 79 |
for(var i = 0; i < this.walls.length; ++i){ |
| 80 |
if(v.dotProduct(observerVector, this.walls[i].normal) > 0){ |
| 81 |
this.walls[i].generate(this); |
| 82 |
} |
| 83 |
} |
| 84 |
return this; |
| 85 |
}, |
| 86 |
_generatePlots: function(){ |
| 87 |
var depth = 0, m = gfx3d.matrix, i = 0; |
| 88 |
for(; i < this.plots.length; ++i){ |
| 89 |
depth += this.plots[i].getDepth(); |
| 90 |
} |
| 91 |
for(--i; i >= 0; --i){ |
| 92 |
var scene = this.view.createScene(); |
| 93 |
scene.setTransform(m.translate(0, 0, -depth)); |
| 94 |
this.plots[i].generate(this, scene); |
| 95 |
depth -= this.plots[i].getDepth(); |
| 96 |
} |
| 97 |
return this; |
| 98 |
}, |
| 99 |
setDir: function(dir){ |
| 100 |
return this; |
| 101 |
} |
| 102 |
}); |
| 103 |
return has("dojo-bidi")? declare("dojox.charting.Chart3D", [Chart3D, BidiChart3D]) : Chart3D; |
| 104 |
}); |