jvm.NumericScale = function(scale, normalizeFunction, minValue, maxValue) {
this.scale = [];
normalizeFunction = normalizeFunction || 'linear';
if (scale) this.setScale(scale);
if (normalizeFunction) this.setNormalizeFunction(normalizeFunction);
if (typeof minValue !== 'undefined' ) this.setMin(minValue);
if (typeof maxValue !== 'undefined' ) this.setMax(maxValue);
};
jvm.NumericScale.prototype = {
setMin: function(min) {
this.clearMinValue = min;
if (typeof this.normalize === 'function') {
this.minValue = this.normalize(min);
} else {
this.minValue = min;
}
},
setMax: function(max) {
this.clearMaxValue = max;
if (typeof this.normalize === 'function') {
this.maxValue = this.normalize(max);
} else {
this.maxValue = max;
}
},
setScale: function(scale) {
var i;
this.scale = [];
for (i = 0; i < scale.length; i++) {
this.scale[i] = [scale[i]];
}
},
setNormalizeFunction: function(f) {
if (f === 'polynomial') {
this.normalize = function(value) {
return Math.pow(value, 0.2);
}
} else if (f === 'linear') {
delete this.normalize;
} else {
this.normalize = f;
}
this.setMin(this.clearMinValue);
this.setMax(this.clearMaxValue);
},
getValue: function(value) {
var lengthes = [],
fullLength = 0,
l,
i = 0,
c;
if (typeof this.normalize === 'function') {
value = this.normalize(value);
}
for (i = 0; i < this.scale.length-1; i++) {
l = this.vectorLength(this.vectorSubtract(this.scale[i+1], this.scale[i]));
lengthes.push(l);
fullLength += l;
}
c = (this.maxValue - this.minValue) / fullLength;
for (i=0; i