44 lines
No EOL
1 KiB
JavaScript
44 lines
No EOL
1 KiB
JavaScript
jvm.ColorScale = function(colors, normalizeFunction, minValue, maxValue) {
|
|
jvm.ColorScale.parentClass.apply(this, arguments);
|
|
}
|
|
|
|
jvm.inherits(jvm.ColorScale, jvm.NumericScale);
|
|
|
|
jvm.ColorScale.prototype.setScale = function(scale) {
|
|
var i;
|
|
|
|
for (i = 0; i < scale.length; i++) {
|
|
this.scale[i] = jvm.ColorScale.rgbToArray(scale[i]);
|
|
}
|
|
};
|
|
|
|
jvm.ColorScale.prototype.getValue = function(value) {
|
|
return jvm.ColorScale.numToRgb(jvm.ColorScale.parentClass.prototype.getValue.call(this, value));
|
|
};
|
|
|
|
jvm.ColorScale.arrayToRgb = function(ar) {
|
|
var rgb = '#',
|
|
d,
|
|
i;
|
|
|
|
for (i = 0; i < ar.length; i++) {
|
|
d = ar[i].toString(16);
|
|
rgb += d.length == 1 ? '0'+d : d;
|
|
}
|
|
return rgb;
|
|
};
|
|
|
|
jvm.ColorScale.numToRgb = function(num) {
|
|
num = num.toString(16);
|
|
|
|
while (num.length < 6) {
|
|
num = '0' + num;
|
|
}
|
|
|
|
return '#'+num;
|
|
};
|
|
|
|
jvm.ColorScale.rgbToArray = function(rgb) {
|
|
rgb = rgb.substr(1);
|
|
return [parseInt(rgb.substr(0, 2), 16), parseInt(rgb.substr(2, 2), 16), parseInt(rgb.substr(4, 2), 16)];
|
|
}; |