Commits

Chris Leonello committed 3829d78

some refactoring

  • Participants
  • Parent commits d266632

Comments (0)

Files changed (1)

src/jqplot.canvasGridRenderer.js

         ctx.fillStyle = this.backgroundColor || this.background;
         ctx.fillRect(this._left, this._top, this._width, this._height);
         
-        if (true) {
-            ctx.save();
-            ctx.lineJoin = 'miter';
-            ctx.lineCap = 'butt';
-            ctx.lineWidth = this.gridLineWidth;
-            ctx.strokeStyle = this.gridLineColor;
-            var b, e, s, m;
-            var ax = ['xaxis', 'yaxis', 'x2axis', 'y2axis'];
-            for (var i=4; i>0; i--) {
-                var name = ax[i-1];
-                var axis = axes[name];
-                var ticks = axis._ticks;
-                var numticks = ticks.length;
-                if (axis.show) {
-                    for (var j=numticks; j>0; j--) {
-                        var t = ticks[j-1];
-                        if (t.show) {
-                            var pos = Math.round(axis.u2p(t.value)) + 0.5;
-                            switch (name) {
-                                case 'xaxis':
-                                    // draw the grid line if we should
-                                    if (t.showGridline && this.drawGridlines) {
-                                        drawLine(pos, this._top, pos, this._bottom);
+        ctx.save();
+        ctx.lineJoin = 'miter';
+        ctx.lineCap = 'butt';
+        ctx.lineWidth = this.gridLineWidth;
+        ctx.strokeStyle = this.gridLineColor;
+        var b, e, s, m;
+        var ax = ['xaxis', 'yaxis', 'x2axis', 'y2axis'];
+        for (var i=4; i>0; i--) {
+            var name = ax[i-1];
+            var axis = axes[name];
+            var ticks = axis._ticks;
+            var numticks = ticks.length;
+            if (axis.show) {
+                for (var j=numticks; j>0; j--) {
+                    var t = ticks[j-1];
+                    if (t.show) {
+                        var pos = Math.round(axis.u2p(t.value)) + 0.5;
+                        switch (name) {
+                            case 'xaxis':
+                                // draw the grid line if we should
+                                if (t.showGridline && this.drawGridlines) {
+                                    drawLine(pos, this._top, pos, this._bottom);
+                                }
+                                // else if first tick and show y baseline
+                                else if (j === 1 && axes.yaxis.show && axes.yaxis.drawBaseline) {
+                                    drawLine(pos, this._top, pos, this._bottom);
+                                }
+                                // else if last tick and show y2 baseline
+                                else if (j === numticks && axes.y2axis.show && axes.y2axis.drawBaseline) {
+                                    drawLine(pos, this._top, pos, this._bottom);
+                                }
+                                
+                                // draw the mark
+                                if (t.showMark && t.mark) {
+                                    s = t.markSize;
+                                    m = t.mark;
+                                    var pos = Math.round(axis.u2p(t.value)) + 0.5;
+                                    switch (m) {
+                                        case 'outside':
+                                            b = this._bottom;
+                                            e = this._bottom+s;
+                                            break;
+                                        case 'inside':
+                                            b = this._bottom-s;
+                                            e = this._bottom;
+                                            break;
+                                        case 'cross':
+                                            b = this._bottom-s;
+                                            e = this._bottom+s;
+                                            break;
+                                        default:
+                                            b = this._bottom;
+                                            e = this._bottom+s;
+                                            break;
                                     }
-                                    // else if first tick and show y baseline
-                                    else if (j === 1 && axes.yaxis.show && axes.yaxis.drawBaseline) {
-                                        drawLine(pos, this._top, pos, this._bottom);
+                                    // draw the shadow
+                                    if (this.shadow) {
+                                        this.renderer.shadowRenderer.draw(ctx, [[pos,b],[pos,e]], {lineCap:'butt', lineWidth:this.gridLineWidth, offset:this.gridLineWidth*0.75, depth:2, fill:false, closePath:false});
                                     }
-                                    // else if last tick and show y2 baseline
-                                    else if (j === numticks && axes.y2axis.show && axes.y2axis.drawBaseline) {
-                                        drawLine(pos, this._top, pos, this._bottom);
+                                    // draw the line
+                                    drawLine(pos, b, pos, e);
+                                }
+                                break;
+                            case 'yaxis':
+                                // draw the grid line
+                                if (t.showGridline && this.drawGridlines) {
+                                    drawLine(this._right, pos, this._left, pos);
+                                }
+                                // else if first tick and show x baseline
+                                else if (j === 1 && axes.xaxis.show && axes.xaxis.drawBaseline) {
+                                    drawLine(this._right, pos, this._left, pos);
+                                }
+                                // else if last tick and show x2 baseline
+                                else if (j === numticks && axes.x2axis.show && axes.x2axis.drawBaseline) {
+                                    drawLine(this._right, pos, this._left, pos);
+                                }
+                                // draw the mark
+                                if (t.showMark && t.mark) {
+                                    s = t.markSize;
+                                    m = t.mark;
+                                    var pos = Math.round(axis.u2p(t.value)) + 0.5;
+                                    switch (m) {
+                                        case 'outside':
+                                            b = this._left-s;
+                                            e = this._left;
+                                            break;
+                                        case 'inside':
+                                            b = this._left;
+                                            e = this._left+s;
+                                            break;
+                                        case 'cross':
+                                            b = this._left-s;
+                                            e = this._left+s;
+                                            break;
+                                        default:
+                                            b = this._left-s;
+                                            e = this._left;
+                                            break;
+                                            }
+                                    // draw the shadow
+                                    if (this.shadow) {
+                                        this.renderer.shadowRenderer.draw(ctx, [[b, pos], [e, pos]], {lineCap:'butt', lineWidth:this.gridLineWidth*1.5, offset:this.gridLineWidth*0.75, fill:false, closePath:false});
                                     }
-                                    
-                                    // draw the mark
-	                                if (t.showMark && t.mark) {
-                                        s = t.markSize;
-                                        m = t.mark;
-                                        var pos = Math.round(axis.u2p(t.value)) + 0.5;
-                                        switch (m) {
-                                            case 'outside':
-                                                b = this._bottom;
-                                                e = this._bottom+s;
-                                                break;
-                                            case 'inside':
-                                                b = this._bottom-s;
-                                                e = this._bottom;
-                                                break;
-                                            case 'cross':
-                                                b = this._bottom-s;
-                                                e = this._bottom+s;
-                                                break;
-                                            default:
-                                                b = this._bottom;
-                                                e = this._bottom+s;
-                                                break;
-                                        }
-                                        // draw the shadow
-                                        if (this.shadow) {
-                                            this.renderer.shadowRenderer.draw(ctx, [[pos,b],[pos,e]], {lineCap:'butt', lineWidth:this.gridLineWidth, offset:this.gridLineWidth*0.75, depth:2, fill:false, closePath:false});
-                                        }
-                                        // draw the line
-                                        drawLine(pos, b, pos, e);
+                                    drawLine(b, pos, e, pos, {strokeStyle:axis.borderColor});
+                                }
+                                break;
+                            case 'x2axis':
+                                // draw the grid line
+                                if (t.showGridline && this.drawGridlines) {
+                                    drawLine(pos, this._bottom, pos, this._top);
+                                }
+                                // else if first tick and show y baseline
+                                else if (j === 1 && axes.yaxis.show && axes.yaxis.drawBaseline) {
+                                    drawLine(pos, this._bottom, pos, this._top);
+                                }
+                                // else if last tick and show y2 baseline
+                                else if (j === numticks && axes.y2axis.show && axes.y2axis.drawBaseline) {
+                                    drawLine(pos, this._bottom, pos, this._top);
+                                }
+                                // draw the mark
+                                if (t.showMark && t.mark) {
+                                    s = t.markSize;
+                                    m = t.mark;
+                                    var pos = Math.round(axis.u2p(t.value)) + 0.5;
+                                    switch (m) {
+                                        case 'outside':
+                                            b = this._top-s;
+                                            e = this._top;
+                                            break;
+                                        case 'inside':
+                                            b = this._top;
+                                            e = this._top+s;
+                                            break;
+                                        case 'cross':
+                                            b = this._top-s;
+                                            e = this._top+s;
+                                            break;
+                                        default:
+                                            b = this._top-s;
+                                            e = this._top;
+                                            break;
+                                            }
+                                    // draw the shadow
+                                    if (this.shadow) {
+                                        this.renderer.shadowRenderer.draw(ctx, [[pos,b],[pos,e]], {lineCap:'butt', lineWidth:this.gridLineWidth, offset:this.gridLineWidth*0.75, depth:2, fill:false, closePath:false});
                                     }
-                                    break;
-                                case 'yaxis':
-                                    // draw the grid line
-                                    if (t.showGridline && this.drawGridlines) {
-                                        drawLine(this._right, pos, this._left, pos);
+                                    drawLine(pos, b, pos, e);
+                                }
+                                break;
+                            case 'y2axis':
+                                // draw the grid line
+                                if (t.showGridline && this.drawGridlines) {
+                                    drawLine(this._left, pos, this._right, pos);
+                                }
+                                // else if first tick and show x baseline
+                                else if (j === 1 && axes.xaxis.show && axes.xaxis.drawBaseline) {
+                                    drawLine(this._left, pos, this._right, pos);
+                                }
+                                // else if last tick and show x2 baseline
+                                else if (j === numticks && axes.x2axis.show && axes.x2axis.drawBaseline) {
+                                    drawLine(this._left, pos, this._right, pos);
+                                }
+                                // draw the mark
+                                if (t.showMark && t.mark) {
+                                    s = t.markSize;
+                                    m = t.mark;
+                                    var pos = Math.round(axis.u2p(t.value)) + 0.5;
+                                    switch (m) {
+                                        case 'outside':
+                                            b = this._right;
+                                            e = this._right+s;
+                                            break;
+                                        case 'inside':
+                                            b = this._right-s;
+                                            e = this._right;
+                                            break;
+                                        case 'cross':
+                                            b = this._right-s;
+                                            e = this._right+s;
+                                            break;
+                                        default:
+                                            b = this._right;
+                                            e = this._right+s;
+                                            break;
+                                            }
+                                    // draw the shadow
+                                    if (this.shadow) {
+                                        this.renderer.shadowRenderer.draw(ctx, [[b, pos], [e, pos]], {lineCap:'butt', lineWidth:this.gridLineWidth*1.5, offset:this.gridLineWidth*0.75, fill:false, closePath:false});
                                     }
-                                    // else if first tick and show x baseline
-                                    else if (j === 1 && axes.xaxis.show && axes.xaxis.drawBaseline) {
-                                        drawLine(this._right, pos, this._left, pos);
-                                    }
-                                    // else if last tick and show x2 baseline
-                                    else if (j === numticks && axes.x2axis.show && axes.x2axis.drawBaseline) {
-                                        drawLine(this._right, pos, this._left, pos);
-                                    }
-                                    // draw the mark
-                                    if (t.showMark && t.mark) {
-                                        s = t.markSize;
-                                        m = t.mark;
-                                        var pos = Math.round(axis.u2p(t.value)) + 0.5;
-                                        switch (m) {
-                                            case 'outside':
-                                                b = this._left-s;
-                                                e = this._left;
-                                                break;
-                                            case 'inside':
-                                                b = this._left;
-                                                e = this._left+s;
-                                                break;
-                                            case 'cross':
-                                                b = this._left-s;
-                                                e = this._left+s;
-                                                break;
-                                            default:
-                                                b = this._left-s;
-                                                e = this._left;
-                                                break;
-                                                }
-                                        // draw the shadow
-                                        if (this.shadow) {
-                                            this.renderer.shadowRenderer.draw(ctx, [[b, pos], [e, pos]], {lineCap:'butt', lineWidth:this.gridLineWidth*1.5, offset:this.gridLineWidth*0.75, fill:false, closePath:false});
-                                        }
-                                        drawLine(b, pos, e, pos, {strokeStyle:axis.borderColor});
-                                    }
-                                    break;
-                                case 'x2axis':
-                                    // draw the grid line
-                                    if (t.showGridline && this.drawGridlines) {
-                                        drawLine(pos, this._bottom, pos, this._top);
-                                    }
-                                    // else if first tick and show y baseline
-                                    else if (j === 1 && axes.yaxis.show && axes.yaxis.drawBaseline) {
-                                        drawLine(pos, this._bottom, pos, this._top);
-                                    }
-                                    // else if last tick and show y2 baseline
-                                    else if (j === numticks && axes.y2axis.show && axes.y2axis.drawBaseline) {
-                                        drawLine(pos, this._bottom, pos, this._top);
-                                    }
-                                    // draw the mark
-                                    if (t.showMark && t.mark) {
-                                        s = t.markSize;
-                                        m = t.mark;
-                                        var pos = Math.round(axis.u2p(t.value)) + 0.5;
-                                        switch (m) {
-                                            case 'outside':
-                                                b = this._top-s;
-                                                e = this._top;
-                                                break;
-                                            case 'inside':
-                                                b = this._top;
-                                                e = this._top+s;
-                                                break;
-                                            case 'cross':
-                                                b = this._top-s;
-                                                e = this._top+s;
-                                                break;
-                                            default:
-                                                b = this._top-s;
-                                                e = this._top;
-                                                break;
-                                                }
-                                        // draw the shadow
-                                        if (this.shadow) {
-                                            this.renderer.shadowRenderer.draw(ctx, [[pos,b],[pos,e]], {lineCap:'butt', lineWidth:this.gridLineWidth, offset:this.gridLineWidth*0.75, depth:2, fill:false, closePath:false});
-                                        }
-                                        drawLine(pos, b, pos, e);
-                                    }
-                                    break;
-                                case 'y2axis':
-                                    // draw the grid line
-                                    if (t.showGridline && this.drawGridlines) {
-                                        drawLine(this._left, pos, this._right, pos);
-                                    }
-                                    // else if first tick and show x baseline
-                                    else if (j === 1 && axes.xaxis.show && axes.xaxis.drawBaseline) {
-                                        drawLine(this._left, pos, this._right, pos);
-                                    }
-                                    // else if last tick and show x2 baseline
-                                    else if (j === numticks && axes.x2axis.show && axes.x2axis.drawBaseline) {
-                                        drawLine(this._left, pos, this._right, pos);
-                                    }
-                                    // draw the mark
-                                    if (t.showMark && t.mark) {
-                                        s = t.markSize;
-                                        m = t.mark;
-                                        var pos = Math.round(axis.u2p(t.value)) + 0.5;
-                                        switch (m) {
-                                            case 'outside':
-                                                b = this._right;
-                                                e = this._right+s;
-                                                break;
-                                            case 'inside':
-                                                b = this._right-s;
-                                                e = this._right;
-                                                break;
-                                            case 'cross':
-                                                b = this._right-s;
-                                                e = this._right+s;
-                                                break;
-                                            default:
-                                                b = this._right;
-                                                e = this._right+s;
-                                                break;
-                                                }
-                                        // draw the shadow
-                                        if (this.shadow) {
-                                            this.renderer.shadowRenderer.draw(ctx, [[b, pos], [e, pos]], {lineCap:'butt', lineWidth:this.gridLineWidth*1.5, offset:this.gridLineWidth*0.75, fill:false, closePath:false});
-                                        }
-                                        drawLine(b, pos, e, pos, {strokeStyle:axis.borderColor});
-                                    }
-                                    break;
-                                default:
-                                    break;
-                            }
+                                    drawLine(b, pos, e, pos, {strokeStyle:axis.borderColor});
+                                }
+                                break;
+                            default:
+                                break;
                         }
                     }
+                }
+                t = null;
+            }
+            axis = null;
+            ticks = null;
+        }
+        // Now draw grid lines for additional y axes
+        //////
+        // TO DO: handle yMidAxis
+        //////
+        ax = ['y3axis', 'y4axis', 'y5axis', 'y6axis', 'y7axis', 'y8axis', 'y9axis', 'yMidAxis'];
+        for (var i=7; i>0; i--) {
+            var axis = axes[ax[i-1]];
+            var ticks = axis._ticks;
+            if (axis.show) {
+                var tn = ticks[axis.numberTicks-1];
+                var t0 = ticks[0];
+                var left = axis.getLeft();
+                var points = [[left, tn.getTop() + tn.getHeight()/2], [left, t0.getTop() + t0.getHeight()/2 + 1.0]];
+                // draw the shadow
+                if (this.shadow) {
+                    this.renderer.shadowRenderer.draw(ctx, points, {lineCap:'butt', fill:false, closePath:false});
+                }
+                // draw the line
+                drawLine(points[0][0], points[0][1], points[1][0], points[1][1], {lineCap:'butt', strokeStyle:axis.borderColor, lineWidth:axis.borderWidth});
+                // draw the tick marks
+                for (var j=ticks.length; j>0; j--) {
+                    var t = ticks[j-1];
+                    s = t.markSize;
+                    m = t.mark;
+                    var pos = Math.round(axis.u2p(t.value)) + 0.5;
+                    if (t.showMark && t.mark) {
+                        switch (m) {
+                            case 'outside':
+                                b = left;
+                                e = left+s;
+                                break;
+                            case 'inside':
+                                b = left-s;
+                                e = left;
+                                break;
+                            case 'cross':
+                                b = left-s;
+                                e = left+s;
+                                break;
+                            default:
+                                b = left;
+                                e = left+s;
+                                break;
+                        }
+                        points = [[b,pos], [e,pos]];
+                        // draw the shadow
+                        if (this.shadow) {
+                            this.renderer.shadowRenderer.draw(ctx, points, {lineCap:'butt', lineWidth:this.gridLineWidth*1.5, offset:this.gridLineWidth*0.75, fill:false, closePath:false});
+                        }
+                        // draw the line
+                        drawLine(b, pos, e, pos, {strokeStyle:axis.borderColor});
+                    }
                     t = null;
                 }
-                axis = null;
-                ticks = null;
+                t0 = null;
             }
-            // Now draw grid lines for additional y axes
-            ax = ['y3axis', 'y4axis', 'y5axis', 'y6axis', 'y7axis', 'y8axis', 'y9axis'];
-            for (var i=7; i>0; i--) {
-                var axis = axes[ax[i-1]];
-                var ticks = axis._ticks;
-                if (axis.show) {
-                    var tn = ticks[axis.numberTicks-1];
-                    var t0 = ticks[0];
-                    var left = axis.getLeft();
-                    var points = [[left, tn.getTop() + tn.getHeight()/2], [left, t0.getTop() + t0.getHeight()/2 + 1.0]];
-                    // draw the shadow
-                    if (this.shadow) {
-                        this.renderer.shadowRenderer.draw(ctx, points, {lineCap:'butt', fill:false, closePath:false});
-                    }
-                    // draw the line
-                    drawLine(points[0][0], points[0][1], points[1][0], points[1][1], {lineCap:'butt', strokeStyle:axis.borderColor, lineWidth:axis.borderWidth});
-                    // draw the tick marks
-                    for (var j=ticks.length; j>0; j--) {
-                        var t = ticks[j-1];
-                        s = t.markSize;
-                        m = t.mark;
-                        var pos = Math.round(axis.u2p(t.value)) + 0.5;
-                        if (t.showMark && t.mark) {
-                            switch (m) {
-                                case 'outside':
-                                    b = left;
-                                    e = left+s;
-                                    break;
-                                case 'inside':
-                                    b = left-s;
-                                    e = left;
-                                    break;
-                                case 'cross':
-                                    b = left-s;
-                                    e = left+s;
-                                    break;
-                                default:
-                                    b = left;
-                                    e = left+s;
-                                    break;
-                            }
-                            points = [[b,pos], [e,pos]];
-                            // draw the shadow
-                            if (this.shadow) {
-                                this.renderer.shadowRenderer.draw(ctx, points, {lineCap:'butt', lineWidth:this.gridLineWidth*1.5, offset:this.gridLineWidth*0.75, fill:false, closePath:false});
-                            }
-                            // draw the line
-                            drawLine(b, pos, e, pos, {strokeStyle:axis.borderColor});
-                        }
-                        t = null;
-                    }
-                    t0 = null;
-                }
-                axis = null;
-                ticks =  null;
-            }
-            
-            ctx.restore();
+            axis = null;
+            ticks =  null;
         }
         
+        ctx.restore();
+        
         function drawLine(bx, by, ex, ey, opts) {
             ctx.save();
             opts = opts || {};