- Author:
- David Nickerson <david.nickerson@gmail.com>
- Date:
- 2021-09-17 15:39:51+12:00
- Desc:
- tweak html formatting
- Permanent Source URI:
- https://models.fieldml.org/workspace/a1/rawfile/c47db6b2fedb368422c7f4d5191aeb9f319ad684/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();
}
});
})();