-
Notifications
You must be signed in to change notification settings - Fork 430
/
color-scale.js
44 lines (34 loc) · 1 KB
/
color-scale.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
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)];
};