Commits

Chris Leonello committed 27dd2d0

Working on bug with stacked bars and negative values.

  • Participants
  • Parent commits dd65cd0

Comments (0)

Files changed (1)

src/plugins/jqplot.barRenderer.js

         return ret;
     }
     
-    $.jqplot.BarRenderer.prototype.draw = function(ctx, gridData, options) {
+    $.jqplot.BarRenderer.prototype.draw = function(ctx, gridData, options, plot) {
         var i;
         // Ughhh, have to make a copy of options b/c it may be modified later.
         var opts = $.extend({}, options);
 			var base;
 			var xstart; 
 			var ystart;
+
+            function getYStart(idx, it, comp) {
+                var series = plot.series[idx];
+                var ystart = series._prevGridData[it][1];
+                var temp;
+                // if sign change, look for previous series point of same sign.
+                if ((series._prevPlotData[it][1] * comp) < 0 && idx > 0) {
+                    temp = idx - 1;
+                    getYStart(temp, it, comp);
+                }
+                else if (ystart === null || idx === 0) {
+                    ystart = series._yaxis.series_u2p(0);
+                }
+                return ystart;
+            }
             
             if (this.barDirection == 'vertical') {
                 for (var i=0; i<gridData.length; i++) {
                     
                     // stacked
                     if (this._stack && this._prevGridData.length) {
-                        ystart = this._prevGridData[i][1];
+                        // ystart = this._prevGridData[i][1];
 
-                        if (ystart === null) {
-                            ystart = this._yaxis.series_u2p(0);
-                        }
+                        // if (ystart === null) {
+                        //     ystart = this._yaxis.series_u2p(0);
+                        // }
+                        ystart = getYStart(this.index, i, this.data[i][1]);
                     }
                     // not stacked and first series in stack
                     else {