Opened 10 years ago

Closed 6 years ago

#14551 closed defect (patchwelcome)

divide by 0 errors in gradient, matrix code

Reported by: jkl Owned by: Eugene Lazutkin
Priority: high Milestone: 1.13
Component: DojoX GFX Version: 1.7.1
Keywords: gradient matrix Cc:
Blocked By: Blocking:


There are divide by 0 problems in dojox/gfx/gradient.js and dojo/gfx/matrix.js. The problem can be observed in IE 6 on a stacked column chart using a gradient fill, where one of the bars has the value 0, and hence height 0. Chart rendering crashes with an exception because the sort callback used in the gradient projection function gets called with NaN values.

In the gradient code, divide-by-0 happens in the getPoint (line 103) function if the scale parameter is 0.

return {r: r, p: p, o: scale == 0 ? 0 : m.multiplyPoint(shiftAndRotate, p).x / scale};

In the matrix code, divide-by-0 happens in the project function (beginning around line 168) in the degenerate case where a == 0 and b == 0.

var a2 = a * a, b2 = b * b, n2 = a2 + b2, xy = a * b / n2; return new m.Matrix2D({ xx: a2 / n2, xy: xy, yx: xy, yy: b2 / n2 }); dojox.gfx.matrix.Matrix2D

There are probably several ways to approach this problem, at various levels of the code. One possible approach involves doing something like this in the gradient code:

return {r: r, p: p, o: scale == 0 ? 0 : m.multiplyPoint(shiftAndRotate, p).x / scale};

and this for the matrix code:

if (a == 0 && b == 0) {

return new m.Matrix2D({ xx: 0, xy: 0, yx: 0, yy: 0 });


Note that for some reason the stacked column plot in allows height 0 in its rendering sanity check, but requires width >= 1 (line 87). It isn't clear why that is. Perhaps it is desirable to draw the stroke around a 0-height box. In any case, another approach would be to skip rendering altogether for the height == 0 case, or maybe just skip fill rendering. That wouldn't fix the problem in full generality, but it might be safer than making changes to the gfx code.

Change History (1)

comment:1 Changed 6 years ago by dylan

Milestone: tbd1.12
Resolution: patchwelcome
Status: newclosed

Given that no one has shown interest in creating a patch in the past 3+ years, I'm closing this as patchwelcome.

Note: See TracTickets for help on using tickets.