When Swivel graphs a set of data, it shows a sparkline graph in addition to the big graph. A sparkline graph is the small version of the graph with no axis. Dojo charts provides this capability.
But, we ran into a problem. When we tried graphing straight lines (lines with equal Y values) the sparkline didn't show up. We kept thinking that dojo was drawing a straight line down below the drawing area. That wasn't the case. It turned out that when dojo draws with no axes it uses this little formula in dojotoolkit/dojox/charting/scaler/primitive.js
buildScaler: function(/*Number*/ min, /*Number*/ max, /*Number*/ span, /*Object*/ kwArgs){
return {
bounds: {
lower: min,
upper: max,
from: min,
to: max,
scale: span/(max - min),
span: span
},
scaler: dojox.charting.scaler.primitive
};
},
So if you pay a close attention to this line: scale: span/(max -min), in a straight line all the y values are equal so max becomes equal to min so the (max - min) equation becomes zero making span/ (max -min) going to infinity and makes scale be a NaN value in javascript.
This is simply fixed by three lines of code:
if (min == max) {
scale = 1;
min = -1;
} else {
scale = span/(max - min);
}
That's it. min = -1 makes the drawing of the line to go up 1 pixel. If you don't add that line, your graph would not show up in IE.
Recent Comments