8ae19a0a51c0ed75912c4a1e923a01bb7a819165.svn-base 2.6 KB

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