source: Dev/trunk/src/client/dojox/charting/Chart3D.js @ 532

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

Added Dojo 1.9.3 release.

File size: 3.1 KB
Line 
1define(["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        // module:
5        //              dojox/charting/Chart3D
6        // summary:
7        //              This module provides basic 3d charting capablities (using 2d vector graphics to simulate 3d.
8
9        /*=====
10        var __Chart3DCtorArgs = function(node, lights, camera, theme){
11                // summary:
12                //              The keyword arguments that can be passed in a Chart constructor.
13                //
14                // node: Node
15                //              The DOM node to construct the chart on.
16                // lights:
17                //              Lighting properties for the 3d scene
18                // camera: Object
19                //              Camera properties describing the viewing camera position.
20                // theme: Object
21                //              Charting theme to use for coloring chart elements.
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                        // setup a view
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                        // initialize internal variables
37                        this.walls = [];
38                        this.plots = [];
39                },
40               
41                // public API
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                // internal API
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(/*String*/dir){
100                        return this;
101                }
102        });
103        return has("dojo-bidi")? declare("dojox.charting.Chart3D", [Chart3D, BidiChart3D]) : Chart3D;
104});
Note: See TracBrowser for help on using the repository browser.