- Author:
- David Nickerson <nickerso@users.sourceforge.net>
- Date:
- 2009-07-16 02:00:03+12:00
- Desc:
- the starting point for the HH tutorial example
- Permanent Source URI:
- https://models.fieldml.org/workspace/a1/rawfile/f6a8f90307388eb4b040ee3566b84d88b59247f7/dojo-presentation/js/dojo/dojox/charting/scaler/common.js
dojo.provide("dojox.charting.scaler.common");
(function(){
var eq = function(/*Number*/ a, /*Number*/ b){
// summary: compare two FP numbers for equality
return Math.abs(a - b) <= 1e-6 * (Math.abs(a) + Math.abs(b)); // Boolean
};
dojo.mixin(dojox.charting.scaler.common, {
findString: function(/*String*/ val, /*Array*/ text){
val = val.toLowerCase();
for(var i = 0; i < text.length; ++i){
if(val == text[i]){ return true; }
}
return false;
},
getNumericLabel: function(/*Number*/ number, /*Number*/ precision, /*Object*/ kwArgs){
if(kwArgs.labels){
// classic binary search
var l = kwArgs.labels, lo = 0, hi = l.length;
while(lo < hi){
var mid = Math.floor((lo + hi) / 2), val = l[mid].value;
if(val < number){
lo = mid + 1;
}else{
hi = mid;
}
}
// lets take into account FP errors
if(lo < l.length && eq(l[lo].value, number)){
return l[lo].text;
}
--lo;
if(lo >= 0 && lo < l.length && eq(l[lo].value, number)){
return l[lo].text;
}
lo += 2;
if(lo < l.length && eq(l[lo].value, number)){
return l[lo].text;
}
// otherwise we will produce a number
}
return kwArgs.fixed ? number.toFixed(precision < 0 ? -precision : 0) : number.toString();
}
});
})();