2f9c48d41b2aaa75bda4818d4d4f2cdeb46a5702.svn-base 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. if (!dojo._hasResource["dojox.charting.plot3d.Cylinders"]) { // _hasResource
  2. // checks added
  3. // by build. Do
  4. // not use
  5. // _hasResource
  6. // directly in
  7. // your code.
  8. dojo._hasResource["dojox.charting.plot3d.Cylinders"] = true;
  9. dojo.provide("dojox.charting.plot3d.Cylinders");
  10. dojo.require("dojox.charting.plot3d.Base");
  11. (function() {
  12. // reduce function borrowed from dojox.fun
  13. var reduce = function(/* Array */a, /* Function|String|Array */f, /* Object? */
  14. o) {
  15. // summary: repeatedly applies a binary function to an array from
  16. // left
  17. // to right; returns the final value.
  18. a = typeof a == "string" ? a.split("") : a;
  19. o = o || dojo.global;
  20. var z = a[0];
  21. for (var i = 1; i < a.length; z = f.call(o, z, a[i++]));
  22. return z; // Object
  23. };
  24. dojo.declare("dojox.charting.plot3d.Cylinders",
  25. dojox.charting.plot3d.Base, {
  26. constructor : function(width, height, kwArgs) {
  27. this.depth = "auto";
  28. this.gap = 0;
  29. this.data = [];
  30. this.material = {
  31. type : "plastic",
  32. finish : "shiny",
  33. color : "lime"
  34. };
  35. this.outline = null;
  36. if (kwArgs) {
  37. if ("depth" in kwArgs) {
  38. this.depth = kwArgs.depth;
  39. }
  40. if ("gap" in kwArgs) {
  41. this.gap = kwArgs.gap;
  42. }
  43. if ("material" in kwArgs) {
  44. var m = kwArgs.material;
  45. if (typeof m == "string"
  46. || m instanceof dojo.Color) {
  47. this.material.color = m;
  48. } else {
  49. this.material = m;
  50. }
  51. }
  52. if ("outline" in kwArgs) {
  53. this.outline = kwArgs.outline;
  54. }
  55. }
  56. },
  57. getDepth : function() {
  58. if (this.depth == "auto") {
  59. var w = this.width;
  60. if (this.data && this.data.length) {
  61. w = w / this.data.length;
  62. }
  63. return w - 2 * this.gap;
  64. }
  65. return this.depth;
  66. },
  67. generate : function(chart, creator) {
  68. if (!this.data) {
  69. return this;
  70. }
  71. var step = this.width / this.data.length, org = 0, scale = this.height
  72. / reduce(this.data, Math.max);
  73. if (!creator) {
  74. creator = chart.view;
  75. }
  76. for (var i = 0; i < this.data.length; ++i, org += step) {
  77. creator.createCylinder({
  78. center : {
  79. x : org + step / 2,
  80. y : 0,
  81. z : 0
  82. },
  83. radius : step / 2 - this.gap,
  84. height : this.data[i] * scale
  85. }).setTransform(dojox.gfx3d.matrix
  86. .rotateXg(-90)).setFill(this.material)
  87. .setStroke(this.outline);
  88. }
  89. }
  90. });
  91. })();
  92. }