Chris Leonello avatar Chris Leonello committed 3a2c969

Fixed bug with stacked bar chart and negative values.

Comments (0)

Files changed (1)

src/plugins/jqplot.barRenderer.js

 			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);
+            // called with scope of series
+            function getYStart(sidx, didx, comp) {
+                // check if sign change
+                // console.log('in getYStart', sidx, didx);
+                var seriesIndex = sidx,
+                    prevSeriesIndex = sidx - 1,
+                    ystart,
+                    prevYVal;
+
+                // is this not the first series?
+                if (seriesIndex > 0) {
+                    prevYVal = plot.series[prevSeriesIndex]._plotData[didx][1];
+                    // console.log(comp*prevYVal);
+
+                    // is there a sign change
+                    if ((comp * prevYVal) < 0) {
+                        // console.log('sign change');
+                        ystart = getYStart(prevSeriesIndex, didx, comp);
+                    }
+
+                    // no sign change.
+                    else {
+                        ystart = plot.series[prevSeriesIndex].gridData[didx][1];
+                    }
+
                 }
-                else if (ystart === null || idx === 0) {
-                    ystart = series._yaxis.series_u2p(0);
+
+                // if first series, return y value at 0
+                else {
+                    ystart = plot.series[seriesIndex]._yaxis.series_u2p(0);
                 }
+
                 return ystart;
             }
             
                     }
                     points = [];
                     base = gridData[i][0] + this._barNudge;
-                    ystart;
                     
                     // stacked
                     if (this._stack && this._prevGridData.length) {
-                        // ystart = this._prevGridData[i][1];
 
-                        // if (ystart === null) {
-                        //     ystart = this._yaxis.series_u2p(0);
-                        // }
-                        ystart = getYStart(this.index, i, this.data[i][1]);
+                        ystart = getYStart(this.index, i, this._plotData[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.