ClusteredColumns.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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.plot2d.ClusteredColumns"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
  7. dojo._hasResource["dojox.charting.plot2d.ClusteredColumns"] = true;
  8. dojo.provide("dojox.charting.plot2d.ClusteredColumns");
  9. dojo.require("dojox.charting.plot2d.common");
  10. dojo.require("dojox.charting.plot2d.Columns");
  11. dojo.require("dojox.lang.functional");
  12. dojo.require("dojox.lang.functional.reversed");
  13. (function(){
  14. var df = dojox.lang.functional, dc = dojox.charting.plot2d.common,
  15. purgeGroup = df.lambda("item.purgeGroup()");
  16. dojo.declare("dojox.charting.plot2d.ClusteredColumns", dojox.charting.plot2d.Columns, {
  17. // summary:
  18. // A plot representing grouped or clustered columns (vertical bars).
  19. render: function(dim, offsets){
  20. // summary:
  21. // Run the calculations for any axes for this plot.
  22. // dim: Object
  23. // An object in the form of { width, height }
  24. // offsets: Object
  25. // An object of the form { l, r, t, b}.
  26. // returns: dojox.charting.plot2d.ClusteredColumns
  27. // A reference to this plot for functional chaining.
  28. if(this.zoom && !this.isDataDirty()){
  29. return this.performZoom(dim, offsets);
  30. }
  31. this.resetEvents();
  32. this.dirty = this.isDirty();
  33. if(this.dirty){
  34. dojo.forEach(this.series, purgeGroup);
  35. this._eventSeries = {};
  36. this.cleanGroup();
  37. var s = this.group;
  38. df.forEachRev(this.series, function(item){ item.cleanGroup(s); });
  39. }
  40. var t = this.chart.theme, f, gap, width, thickness,
  41. ht = this._hScaler.scaler.getTransformerFromModel(this._hScaler),
  42. vt = this._vScaler.scaler.getTransformerFromModel(this._vScaler),
  43. baseline = Math.max(0, this._vScaler.bounds.lower),
  44. baselineHeight = vt(baseline),
  45. events = this.events();
  46. f = dc.calculateBarSize(this._hScaler.bounds.scale, this.opt, this.series.length);
  47. gap = f.gap;
  48. width = thickness = f.size;
  49. for(var i = 0; i < this.series.length; ++i){
  50. var run = this.series[i], shift = thickness * i;
  51. if(!this.dirty && !run.dirty){
  52. t.skip();
  53. this._reconnectEvents(run.name);
  54. continue;
  55. }
  56. run.cleanGroup();
  57. var theme = t.next("column", [this.opt, run]), s = run.group,
  58. eventSeries = new Array(run.data.length);
  59. for(var j = 0; j < run.data.length; ++j){
  60. var value = run.data[j];
  61. if(value !== null){
  62. var v = typeof value == "number" ? value : value.y,
  63. vv = vt(v),
  64. height = vv - baselineHeight,
  65. h = Math.abs(height),
  66. finalTheme = typeof value != "number" ?
  67. t.addMixin(theme, "column", value, true) :
  68. t.post(theme, "column");
  69. if(width >= 1 && h >= 0){
  70. var rect = {
  71. x: offsets.l + ht(j + 0.5) + gap + shift,
  72. y: dim.height - offsets.b - (v > baseline ? vv : baselineHeight),
  73. width: width, height: h
  74. };
  75. var specialFill = this._plotFill(finalTheme.series.fill, dim, offsets);
  76. specialFill = this._shapeFill(specialFill, rect);
  77. var shape = s.createRect(rect).setFill(specialFill).setStroke(finalTheme.series.stroke);
  78. run.dyn.fill = shape.getFill();
  79. run.dyn.stroke = shape.getStroke();
  80. if(events){
  81. var o = {
  82. element: "column",
  83. index: j,
  84. run: run,
  85. shape: shape,
  86. x: j + 0.5,
  87. y: v
  88. };
  89. this._connectEvents(o);
  90. eventSeries[j] = o;
  91. }
  92. if(this.animate){
  93. this._animateColumn(shape, dim.height - offsets.b - baselineHeight, h);
  94. }
  95. }
  96. }
  97. }
  98. this._eventSeries[run.name] = eventSeries;
  99. run.dirty = false;
  100. }
  101. this.dirty = false;
  102. return this; // dojox.charting.plot2d.ClusteredColumns
  103. }
  104. });
  105. })();
  106. }