]> git.pond.sub.org Git - eow/blob - static/dojo-release-1.1.1/dojox/charting/Chart3D.js
Comment class stub
[eow] / static / dojo-release-1.1.1 / dojox / charting / Chart3D.js
1 if(!dojo._hasResource["dojox.charting.Chart3D"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
2 dojo._hasResource["dojox.charting.Chart3D"] = true;
3 dojo.provide("dojox.charting.Chart3D");
4
5 dojo.require("dojox.gfx3d");
6
7 (function(){
8         var observerVector = {x: 0, y: 0, z: 1}, v = dojox.gfx3d.vector, n = dojox.gfx.normalizedLength;
9
10         dojo.declare("dojox.charting.Chart3D", null, {
11                 constructor: function(node, lights, camera, theme){
12                         // setup a view
13                         this.node = dojo.byId(node);
14                         this.surface = dojox.gfx.createSurface(this.node, n(this.node.style.width), n(this.node.style.height));
15                         this.view = this.surface.createViewport();
16                         this.view.setLights(lights.lights, lights.ambient, lights.specular);
17                         this.view.setCameraTransform(camera);
18                         this.theme = theme;
19                         
20                         // initialize internal variables
21                         this.walls = [];
22                         this.plots = [];
23                 },
24                 
25                 // public API
26                 generate: function(){
27                         return this._generateWalls()._generatePlots();
28                 },
29                 invalidate: function(){
30                         this.view.invalidate();
31                         return this;
32                 },
33                 render: function(){
34                         this.view.render();
35                         return this;
36                 },
37                 addPlot: function(plot){
38                         return this._add(this.plots, plot);
39                 },
40                 removePlot: function(plot){
41                         return this._remove(this.plots, plot);
42                 },
43                 addWall: function(wall){
44                         return this._add(this.walls, wall);
45                 },
46                 removeWall: function(wall){
47                         return this._remove(this.walls, wall);
48                 },
49                 
50                 // internal API
51                 _add: function(array, item){
52                         if(!dojo.some(array, function(i){ return i == item; })){
53                                 array.push(item);
54                                 this.view.invalidate();
55                         }
56                         return this;
57                 },
58                 _remove: function(array, item){
59                         var a = dojo.filter(array, function(i){ return i != item; });
60                         return a.length < array.length ? (array = a, this.invalidate()) : this;
61                 },
62                 _generateWalls: function(){
63                         for(var i = 0; i < this.walls.length; ++i){
64                                 if(v.dotProduct(observerVector, this.walls[i].normal) > 0){
65                                         this.walls[i].generate(this);
66                                 }
67                         }
68                         return this;
69                 },
70                 _generatePlots: function(){
71                         var depth = 0, m = dojox.gfx3d.matrix, i = 0;
72                         for(; i < this.plots.length; ++i){
73                                 depth += this.plots[i].getDepth();
74                         }
75                         for(--i; i >= 0; --i){
76                                 var scene = this.view.createScene();
77                                 scene.setTransform(m.translate(0, 0, -depth));
78                                 this.plots[i].generate(this, scene);
79                                 depth -= this.plots[i].getDepth();
80                         }
81                         return this;
82                 }
83         });
84 })();
85
86 }