Chris Leonello avatar Chris Leonello committed 27dd2d0

Working on bug with stacked bars and negative values.

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 {
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.