b7fdf8b02fd881a9f0d29c768b684d3ccdd3fafa.svn-base 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. if (!dojo._hasResource["dojox.charting.plot2d.StackedBars"]) { // _hasResource
  2. // checks added
  3. // by build. Do
  4. // not use
  5. // _hasResource
  6. // directly in
  7. // your code.
  8. dojo._hasResource["dojox.charting.plot2d.StackedBars"] = true;
  9. dojo.provide("dojox.charting.plot2d.StackedBars");
  10. dojo.require("dojox.charting.plot2d.common");
  11. dojo.require("dojox.charting.plot2d.Bars");
  12. dojo.require("dojox.lang.functional");
  13. (function() {
  14. var df = dojox.lang.functional, dc = dojox.charting.plot2d.common, purgeGroup = df
  15. .lambda("item.purgeGroup()");
  16. dojo.declare("dojox.charting.plot2d.StackedBars",
  17. dojox.charting.plot2d.Bars, {
  18. calculateAxes : function(dim) {
  19. var stats = dc.collectStackedStats(this.series), t;
  20. this._maxRunLength = stats.hmax;
  21. stats.hmin -= 0.5;
  22. stats.hmax += 0.5;
  23. t = stats.hmin, stats.hmin = stats.vmin, stats.vmin = t;
  24. t = stats.hmax, stats.hmax = stats.vmax, stats.vmax = t;
  25. this._calc(dim, stats);
  26. return this;
  27. },
  28. render : function(dim, offsets) {
  29. // stack all values
  30. var acc = df.repeat(this._maxRunLength, "-> 0", 0);
  31. for (var i = 0; i < this.series.length; ++i) {
  32. var run = this.series[i];
  33. for (var j = 0; j < run.data.length; ++j) {
  34. var v = run.data[j];
  35. if (isNaN(v)) {
  36. v = 0;
  37. }
  38. acc[j] += v;
  39. }
  40. }
  41. // draw runs in backwards
  42. if (this.dirty) {
  43. dojo.forEach(this.series, purgeGroup);
  44. this.cleanGroup();
  45. var s = this.group;
  46. df.forEachReversed(this.series, function(item) {
  47. item.cleanGroup(s);
  48. });
  49. }
  50. var t = this.chart.theme, color, stroke, fill, f, gap = this.opt.gap < this._vScaler.scale
  51. / 3 ? this.opt.gap : 0;
  52. for (var i = this.series.length - 1; i >= 0; --i) {
  53. var run = this.series[i];
  54. if (!this.dirty && !run.dirty) {
  55. continue;
  56. }
  57. run.cleanGroup();
  58. var s = run.group;
  59. if (!run.fill || !run.stroke) {
  60. // need autogenerated color
  61. color = run.dyn.color = new dojo.Color(t
  62. .next("color"));
  63. }
  64. stroke = run.stroke ? run.stroke : dc
  65. .augmentStroke(t.series.stroke, color);
  66. fill = run.fill ? run.fill : dc.augmentFill(
  67. t.series.fill, color);
  68. for (var j = 0; j < acc.length; ++j) {
  69. var v = acc[j], width = this._hScaler.scale
  70. * (v - this._hScaler.bounds.lower), height = this._vScaler.scale
  71. - 2 * gap;
  72. if (width >= 1 && height >= 1) {
  73. var shape = s.createRect({
  74. x : offsets.l,
  75. y : dim.height
  76. - offsets.b
  77. - this._vScaler.scale
  78. * (j + 1.5 - this._vScaler.bounds.lower)
  79. + gap,
  80. width : width,
  81. height : height
  82. }).setFill(fill).setStroke(stroke);
  83. run.dyn.fill = shape.getFill();
  84. run.dyn.stroke = shape.getStroke();
  85. }
  86. }
  87. run.dirty = false;
  88. // update the accumulator
  89. for (var j = 0; j < run.data.length; ++j) {
  90. var v = run.data[j];
  91. if (isNaN(v)) {
  92. v = 0;
  93. }
  94. acc[j] -= v;
  95. }
  96. }
  97. this.dirty = false;
  98. return this;
  99. }
  100. });
  101. })();
  102. }