Commits

Chris Leonello committed fb2d8ab

Implemented plot bands for y axes of pyramidRenderer.
Refactored pyramidRenderer barWidth calculation.

Comments (0)

Files changed (2)

src/plugins/jqplot.pyramidGridRenderer.js

         this._ctx;
         this.plotBands = {
             show: false,
-            color: 'rgb(230, 219, 179)'
+            color: 'rgb(230, 219, 179)',
             axis: 'y',
-            start: 0,
+            start: null,
             interval: 10
         }
         $.extend(true, this, options);
 
         if (this.plotBands.show) {
             ctx.save();
-            ctx.fillStyle = this.plotBands.color;
+            var pb = this.plotBands;
+            ctx.fillStyle = pb.color;
             var axis;
             var x, y, w, h;
             // find axis to work with
-            if (this.plotBands.axis.charAt(0) === 'x') {
+            if (pb.axis.charAt(0) === 'x') {
                 if (axes.xaxis.show) {
                     axis = axes.xaxis;
                 }
-                else if (axes.x2axis.show) {
-                    axis = axes.x2axis;
-                }
             }
-            else if (this.plotBands.axis.charAt(0) === 'y') {
+            else if (pb.axis.charAt(0) === 'y') {
                 if (axes.yaxis.show) {
                     axis = axes.yaxis;
                 }
 
             if (axis !== undefined) {
                 // draw some rectangles
-                for (var i = this.plotBands.start; i <= axis.max; i += 2 * this.plotBands.interval) {
+                var start = pb.start;
+                if (start === null) {
+                    start = axis.min;
+                }
+                for (var i = start; i < axis.max; i += 2 * pb.interval) {
                     if (axis.name.charAt(0) === 'y') {
-                        x = 0;
-                        y = axis.series_u2p(i);
-                        w = this._width;
-                        h = 
+                        x = this._left;
+                        y = axis.series_u2p(i + pb.interval) + this._top;
+                        w = this._right - this._left;
+                        h = axis.series_u2p(start) - axis.series_u2p(start + pb.interval);
+                        ctx.fillRect(x, y, w, h);
                     }
+                    // else {
+                    //     y = 0;
+                    //     x = axis.series_u2p(i);
+                    //     h = this._height;
+                    //     w = axis.series_u2p(start + pb.interval) - axis.series_u2p(start);
+                    // }
+
                 }
             }
+            ctx.restore();
         }
         
         ctx.save();

src/plugins/jqplot.pyramidRenderer.js

         var nticks = paxis.numberTicks;
         var nbins = (nticks-1)/2;
         // so, now we have total number of axis values.
+        var temp = (this.barPadding === 0) ? 1.0 : 0;
         if (paxis.name == 'xaxis' || paxis.name == 'x2axis') {
-            this.barWidth = Math.round((paxis._offsets.max - paxis._offsets.min) / nvals - this.barPadding + Math.pow(3, -Math.abs(this.barPadding)));
+            // this.barWidth = Math.round((paxis._offsets.max - paxis._offsets.min) / nvals - this.barPadding + 1.2*Math.pow(4, -Math.abs(this.barPadding)));
+            // this.barWidth = Math.round((paxis._offsets.max - paxis._offsets.min) / nvals - this.barPadding + temp);
+            this.barWidth = (paxis._offsets.max - paxis._offsets.min) / nvals - this.barPadding + temp;
         }
         else {
             if (this.fill) {
-                var fact = (paxis._offsets.min - paxis._offsets.max) / nvals - this.barPadding + Math.pow(3, -Math.abs(this.barPadding));
+                // var fact = (paxis._offsets.min - paxis._offsets.max) / nvals - this.barPadding + 1.2*Math.pow(4, -Math.abs(this.barPadding));
+                // var fact = (paxis._offsets.min - paxis._offsets.max) / nvals - this.barPadding + temp);
+                this.barWidth = (paxis._offsets.min - paxis._offsets.max) / nvals - this.barPadding + temp;
             }
             else {
-                var fact = (paxis._offsets.min - paxis._offsets.max) / nvals;
+                // var fact = (paxis._offsets.min - paxis._offsets.max) / nvals;
+                this.barWidth = (paxis._offsets.min - paxis._offsets.max) / nvals;
             }
-            this.barWidth = Math.round(fact);
+            // this.barWidth = Math.round(fact);
         }
     };