| 1 |
define(["dojo/_base/lang", "dojo/_base/declare", "dojo/Stateful"], function(lang, declare, Stateful){ |
| 2 |
return declare("dojox.dgauges.LogScaler", Stateful, { |
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
minimum: 0, |
| 13 |
|
| 14 |
|
| 15 |
maximum: 1000, |
| 16 |
|
| 17 |
|
| 18 |
multiplier: 10, |
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
majorTicks: null, |
| 23 |
|
| 24 |
_computedMultiplier: NaN, |
| 25 |
|
| 26 |
constructor: function(){ |
| 27 |
this.watchedProperties = ["minimum", "maximum", "multiplier"]; |
| 28 |
}, |
| 29 |
_buildMajorTickItems: function(){ |
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
var majorTickCache = []; |
| 35 |
this._computedMinimum = this.getComputedMinimum(); |
| 36 |
this._computedMaximum = this.getComputedMaximum(); |
| 37 |
this._computedMultiplier = this.getComputedMultiplier(); |
| 38 |
|
| 39 |
if(this._computedMaximum > this._computedMinimum){ |
| 40 |
var start = Math.max(0, Math.floor(Math.log(this._computedMinimum + 0.000000001) / Math.LN10)); |
| 41 |
var end = Math.max(0, Math.floor(Math.log(this._computedMaximum + 0.000000001) / Math.LN10)); |
| 42 |
var data; |
| 43 |
for(var i = start; i <= end; i += this._computedMultiplier){ |
| 44 |
data = {}; |
| 45 |
data.value = Math.pow(10, i); |
| 46 |
data.position = (i - start) / (end - start); |
| 47 |
majorTickCache.push(data); |
| 48 |
} |
| 49 |
} |
| 50 |
return majorTickCache; |
| 51 |
}, |
| 52 |
|
| 53 |
getComputedMinimum: function(){ |
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
return Math.pow(10, Math.max(0, Math.floor(Math.log(this.minimum + 0.000000001) / Math.LN10))); |
| 59 |
}, |
| 60 |
|
| 61 |
getComputedMaximum: function(){ |
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
return Math.pow(10, Math.max(0, Math.floor(Math.log(this.maximum + 0.000000001) / Math.LN10))); |
| 67 |
}, |
| 68 |
|
| 69 |
|
| 70 |
getComputedMultiplier: function(){ |
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
return Math.max(1, Math.floor(Math.log(this.multiplier + 0.000000001) / Math.LN10)); |
| 76 |
|
| 77 |
}, |
| 78 |
|
| 79 |
computeTicks: function(){ |
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
this.majorTicks = this._buildMajorTickItems(); |
| 85 |
return this.majorTicks.concat(); |
| 86 |
}, |
| 87 |
|
| 88 |
positionForValue: function(value){ |
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
if(this._computedMaximum < this._computedMinimum || value <= this._computedMinimum || value < 1 || isNaN(value)){ |
| 97 |
value = this._computedMinimum; |
| 98 |
} |
| 99 |
if(value >= this._computedMaximum){ |
| 100 |
value = this._computedMaximum; |
| 101 |
} |
| 102 |
value = Math.log(value) / Math.LN10; |
| 103 |
var sv = Math.log(this._computedMinimum) / Math.LN10; |
| 104 |
var ev = Math.log(this._computedMaximum) / Math.LN10; |
| 105 |
return (value - sv) / (ev - sv); |
| 106 |
}, |
| 107 |
|
| 108 |
valueForPosition: function(position){ |
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
var sv = Math.log(this._computedMinimum) / Math.LN10; |
| 116 |
var ev = Math.log(this._computedMaximum) / Math.LN10; |
| 117 |
return Math.pow(10, sv + position * (ev - sv)); |
| 118 |
} |
| 119 |
}); |
| 120 |
}); |