Cylinders.js 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. /*
  2. Copyright (c) 2004-2012, The Dojo Foundation All Rights Reserved.
  3. Available via Academic Free License >= 2.1 OR the modified BSD license.
  4. see: http://dojotoolkit.org/license for details
  5. */
  6. if(!dojo._hasResource["dojox.charting.plot3d.Cylinders"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
  7. dojo._hasResource["dojox.charting.plot3d.Cylinders"] = true;
  8. dojo.provide("dojox.charting.plot3d.Cylinders");
  9. dojo.require("dojox.charting.plot3d.Base");
  10. (function(){
  11. // reduce function borrowed from dojox.fun
  12. var reduce = function(/*Array*/ a, /*Function|String|Array*/ f, /*Object?*/ o){
  13. // summary: repeatedly applies a binary function to an array from left
  14. // to right; returns the final value.
  15. a = typeof a == "string" ? a.split("") : a; o = o || dojo.global;
  16. var z = a[0];
  17. for(var i = 1; i < a.length; z = f.call(o, z, a[i++]));
  18. return z; // Object
  19. };
  20. dojo.declare("dojox.charting.plot3d.Cylinders", dojox.charting.plot3d.Base, {
  21. constructor: function(width, height, kwArgs){
  22. this.depth = "auto";
  23. this.gap = 0;
  24. this.data = [];
  25. this.material = {type: "plastic", finish: "shiny", color: "lime"};
  26. this.outline = null;
  27. if(kwArgs){
  28. if("depth" in kwArgs){ this.depth = kwArgs.depth; }
  29. if("gap" in kwArgs){ this.gap = kwArgs.gap; }
  30. if("material" in kwArgs){
  31. var m = kwArgs.material;
  32. if(typeof m == "string" || m instanceof dojo.Color){
  33. this.material.color = m;
  34. }else{
  35. this.material = m;
  36. }
  37. }
  38. if("outline" in kwArgs){ this.outline = kwArgs.outline; }
  39. }
  40. },
  41. getDepth: function(){
  42. if(this.depth == "auto"){
  43. var w = this.width;
  44. if(this.data && this.data.length){
  45. w = w / this.data.length;
  46. }
  47. return w - 2 * this.gap;
  48. }
  49. return this.depth;
  50. },
  51. generate: function(chart, creator){
  52. if(!this.data){ return this; }
  53. var step = this.width / this.data.length, org = 0,
  54. scale = this.height / reduce(this.data, Math.max);
  55. if(!creator){ creator = chart.view; }
  56. for(var i = 0; i < this.data.length; ++i, org += step){
  57. creator
  58. .createCylinder({
  59. center: {x: org + step / 2, y: 0, z: 0},
  60. radius: step / 2 - this.gap,
  61. height: this.data[i] * scale
  62. })
  63. .setTransform(dojox.gfx3d.matrix.rotateXg(-90))
  64. .setFill(this.material).setStroke(this.outline);
  65. }
  66. }
  67. });
  68. })();
  69. }