| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| (function($) { |
| |
| |
| |
| $.jqplot.CanvasGridRenderer = function(){ |
| this.shadowRenderer = new $.jqplot.ShadowRenderer(); |
| }; |
| |
| |
| $.jqplot.CanvasGridRenderer.prototype.init = function(options) { |
| this._ctx; |
| $.extend(true, this, options); |
| |
| var sopts = {lineJoin:'miter', lineCap:'round', fill:false, isarc:false, angle:this.shadowAngle, offset:this.shadowOffset, alpha:this.shadowAlpha, depth:this.shadowDepth, lineWidth:this.shadowWidth, closePath:false, strokeStyle:this.shadowColor}; |
| this.renderer.shadowRenderer.init(sopts); |
| }; |
| |
| |
| $.jqplot.CanvasGridRenderer.prototype.createElement = function(plot) { |
| var elem; |
| |
| if (this._elem) { |
| if ($.jqplot.use_excanvas && window.G_vmlCanvasManager.uninitElement !== undefined) { |
| elem = this._elem.get(0); |
| window.G_vmlCanvasManager.uninitElement(elem); |
| elem = null; |
| } |
| |
| this._elem.emptyForce(); |
| this._elem = null; |
| } |
| |
| elem = plot.canvasManager.getCanvas(); |
|
|
| var w = this._plotDimensions.width; |
| var h = this._plotDimensions.height; |
| elem.width = w; |
| elem.height = h; |
| this._elem = $(elem); |
| this._elem.addClass('jqplot-grid-canvas'); |
| this._elem.css({ position: 'absolute', left: 0, top: 0 }); |
| |
| elem = plot.canvasManager.initCanvas(elem); |
|
|
| this._top = this._offsets.top; |
| this._bottom = h - this._offsets.bottom; |
| this._left = this._offsets.left; |
| this._right = w - this._offsets.right; |
| this._width = this._right - this._left; |
| this._height = this._bottom - this._top; |
| |
| elem = null; |
| return this._elem; |
| }; |
| |
| $.jqplot.CanvasGridRenderer.prototype.draw = function() { |
| this._ctx = this._elem.get(0).getContext("2d"); |
| var ctx = this._ctx; |
| var axes = this._axes; |
| |
| ctx.save(); |
| ctx.clearRect(0, 0, this._plotDimensions.width, this._plotDimensions.height); |
| ctx.fillStyle = this.backgroundColor || this.background; |
| ctx.fillRect(this._left, this._top, this._width, this._height); |
| |
| 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) { |
| if (axis.drawBaseline) { |
| var bopts = {}; |
| if (axis.baselineWidth !== null) { |
| bopts.lineWidth = axis.baselineWidth; |
| } |
| if (axis.baselineColor !== null) { |
| bopts.strokeStyle = axis.baselineColor; |
| } |
| switch (name) { |
| case 'xaxis': |
| drawLine (this._left, this._bottom, this._right, this._bottom, bopts); |
| break; |
| case 'yaxis': |
| drawLine (this._left, this._bottom, this._left, this._top, bopts); |
| break; |
| case 'x2axis': |
| drawLine (this._left, this._bottom, this._right, this._bottom, bopts); |
| break; |
| case 'y2axis': |
| drawLine (this._right, this._bottom, this._right, this._top, bopts); |
| break; |
| } |
| } |
| 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': |
| |
| if (t.showGridline && this.drawGridlines && ((!t.isMinorTick && axis.drawMajorGridlines) || (t.isMinorTick && axis.drawMinorGridlines)) ) { |
| drawLine(pos, this._top, pos, this._bottom); |
| } |
| |
| if (t.showMark && t.mark && ((!t.isMinorTick && axis.drawMajorTickMarks) || (t.isMinorTick && axis.drawMinorTickMarks)) ) { |
| 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; |
| } |
| |
| 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 'yaxis': |
| |
| if (t.showGridline && this.drawGridlines && ((!t.isMinorTick && axis.drawMajorGridlines) || (t.isMinorTick && axis.drawMinorGridlines)) ) { |
| drawLine(this._right, pos, this._left, pos); |
| } |
| |
| if (t.showMark && t.mark && ((!t.isMinorTick && axis.drawMajorTickMarks) || (t.isMinorTick && axis.drawMinorTickMarks)) ) { |
| 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; |
| } |
| |
| 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': |
| |
| if (t.showGridline && this.drawGridlines && ((!t.isMinorTick && axis.drawMajorGridlines) || (t.isMinorTick && axis.drawMinorGridlines)) ) { |
| drawLine(pos, this._bottom, pos, this._top); |
| } |
| |
| if (t.showMark && t.mark && ((!t.isMinorTick && axis.drawMajorTickMarks) || (t.isMinorTick && axis.drawMinorTickMarks)) ) { |
| 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; |
| } |
| |
| 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': |
| |
| if (t.showGridline && this.drawGridlines && ((!t.isMinorTick && axis.drawMajorGridlines) || (t.isMinorTick && axis.drawMinorGridlines)) ) { |
| drawLine(this._left, pos, this._right, pos); |
| } |
| |
| if (t.showMark && t.mark && ((!t.isMinorTick && axis.drawMajorTickMarks) || (t.isMinorTick && axis.drawMinorTickMarks)) ) { |
| 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; |
| } |
| |
| 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; |
| } |
| } |
| } |
| t = null; |
| } |
| axis = null; |
| ticks = null; |
| } |
| |
| |
| |
| |
| 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]]; |
| |
| if (this.shadow) { |
| this.renderer.shadowRenderer.draw(ctx, points, {lineCap:'butt', fill:false, closePath:false}); |
| } |
| |
| drawLine(points[0][0], points[0][1], points[1][0], points[1][1], {lineCap:'butt', strokeStyle:axis.borderColor, lineWidth:axis.borderWidth}); |
| |
| 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]]; |
| |
| 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}); |
| } |
| |
| drawLine(b, pos, e, pos, {strokeStyle:axis.borderColor}); |
| } |
| t = null; |
| } |
| t0 = null; |
| } |
| axis = null; |
| ticks = null; |
| } |
| |
| ctx.restore(); |
| |
| function drawLine(bx, by, ex, ey, opts) { |
| ctx.save(); |
| opts = opts || {}; |
| if (opts.lineWidth == null || opts.lineWidth != 0){ |
| $.extend(true, ctx, opts); |
| ctx.beginPath(); |
| ctx.moveTo(bx, by); |
| ctx.lineTo(ex, ey); |
| ctx.stroke(); |
| ctx.restore(); |
| } |
| } |
| |
| if (this.shadow) { |
| var points = [[this._left, this._bottom], [this._right, this._bottom], [this._right, this._top]]; |
| this.renderer.shadowRenderer.draw(ctx, points); |
| } |
| |
| |
| if (this.borderWidth != 0 && this.drawBorder) { |
| drawLine (this._left, this._top, this._right, this._top, {lineCap:'round', strokeStyle:axes.x2axis.borderColor, lineWidth:axes.x2axis.borderWidth}); |
| drawLine (this._right, this._top, this._right, this._bottom, {lineCap:'round', strokeStyle:axes.y2axis.borderColor, lineWidth:axes.y2axis.borderWidth}); |
| drawLine (this._right, this._bottom, this._left, this._bottom, {lineCap:'round', strokeStyle:axes.xaxis.borderColor, lineWidth:axes.xaxis.borderWidth}); |
| drawLine (this._left, this._bottom, this._left, this._top, {lineCap:'round', strokeStyle:axes.yaxis.borderColor, lineWidth:axes.yaxis.borderWidth}); |
| } |
| |
| |
| |
| |
| ctx.restore(); |
| ctx = null; |
| axes = null; |
| }; |
| })(jQuery); |