1. Chris Leonello
  2. jqplot
Issue #466 new

Division by zero error in FF 3.6.15 in jquery.jqplot.js and jqPlot.categoryAxisRenderer.js

Jerinaw
created an issue

== Issue == This error is happening to me in FF3.6.15 when there is no data to graph. It's for a bar graph, and jqplot is trying to draw the vertical grid lines using categoryAxisRenderer. Everything works fine in Chrome and the latest FF. This is do to how the browsers handle NaN and Infinity when passed to the canvas draw functions.

{{{

!Javascript

// called with scope of axis 425 $.jqplot.CategoryAxisRenderer.prototype.pack = function(pos, offsets) { 426 var ticks = this._ticks; 427 var max = this.max; //0.5 428 var min = this.min; //0.5 429 var offmax = offsets.max; 430 var offmin = offsets.min; 431 var lshow = (this._label == null) ? false : this._label.show; 432 var i; 433 434 for (var p in pos) { 435 this._elem.css(p, pos[p]); 436 } 437 438 this._offsets = offsets; 439 // pixellength will be + for x axes and - for y axes becasue pixels always measured from top left. 440 var pixellength = offmax - offmin; 441 var unitlength = max - min; //HERE this is = 0 442 ...

448 this.u2p = function(u){ 449 return (u - min) * pixellength / unitlength + offmin; // DIVISION by zero error 450 };

}}} I'm going to add a check to the u2p function for 0 unitlength and return 0, but I'm not sure what kind of errors this will cause down the road.

== Here's what I did to fix the issue: == Line 3886 in jquery.jqplot.js should be changed to {{{

!Javascript

function drawLine(bx, by, ex, ey, opts) { ctx.save(); opts = opts || {}; if( isNaN(bx) || isNaN(by) || isNaN(ex) || isNaN(ey) || bx == null || by == null || ex == null || ey == null ){ return; }

        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();
        }
}

}}} That will fix the draw function for older browsers.

This problem continues on to the shadow render. Need to add !isNaN() to line 5706 {{{

!Javascript

if (points[i][0] != null && !isNaN(points[i][0]) && points[i][1] != null && !isNaN(points[i][1]) ) { ...} }}}

Comments (0)

  1. Log in to comment