JAL-1807 Bob's JalviewJS prototype first commit
[jalviewjs.git] / bin / jalview / schemes / GraduatedColor.js
1 Clazz.declarePackage ("jalview.schemes");\r
2 Clazz.load (null, "jalview.schemes.GraduatedColor", ["jalview.schemes.UserColourScheme", "java.awt.Color", "java.lang.Float"], function () {\r
3 c$ = Clazz.decorateAsClass (function () {\r
4 this.thresholdState = -1;\r
5 this.lr = 0;\r
6 this.lg = 0;\r
7 this.lb = 0;\r
8 this.dr = 0;\r
9 this.dg = 0;\r
10 this.db = 0;\r
11 this.base = 0;\r
12 this.range = 0;\r
13 this.thrsh = 0;\r
14 this.tolow = false;\r
15 this.autoScale = true;\r
16 this.ucs = null;\r
17 this.colourByLabel = false;\r
18 Clazz.instantialize (this, arguments);\r
19 }, jalview.schemes, "GraduatedColor");\r
20 Clazz.makeConstructor (c$, \r
21 function (low, high, min, max) {\r
22 this.thrsh = NaN;\r
23 this.tolow = min >= max;\r
24 this.lr = low.getRed () / 255;\r
25 this.lg = low.getGreen () / 255;\r
26 this.lb = low.getBlue () / 255;\r
27 this.dr = (high.getRed () / 255) - this.lr;\r
28 this.dg = (high.getGreen () / 255) - this.lg;\r
29 this.db = (high.getBlue () / 255) - this.lb;\r
30 if (this.tolow) {\r
31 this.base = max;\r
32 this.range = min - max;\r
33 } else {\r
34 this.base = min;\r
35 this.range = max - min;\r
36 }}, "java.awt.Color,java.awt.Color,~N,~N");\r
37 Clazz.makeConstructor (c$, \r
38 function (oldcs) {\r
39 this.lr = oldcs.lr;\r
40 this.lg = oldcs.lg;\r
41 this.lb = oldcs.lb;\r
42 this.dr = oldcs.dr;\r
43 this.dg = oldcs.dg;\r
44 this.db = oldcs.db;\r
45 this.base = oldcs.base;\r
46 this.range = oldcs.range;\r
47 this.tolow = oldcs.tolow;\r
48 this.thresholdState = oldcs.thresholdState;\r
49 this.thrsh = oldcs.thrsh;\r
50 this.autoScale = oldcs.autoScale;\r
51 this.colourByLabel = oldcs.colourByLabel;\r
52 }, "jalview.schemes.GraduatedColor");\r
53 Clazz.makeConstructor (c$, \r
54 function (oldcs, min, max) {\r
55 this.construct (oldcs);\r
56 this.updateBounds (min, max);\r
57 }, "jalview.schemes.GraduatedColor,~N,~N");\r
58 Clazz.defineMethod (c$, "getMinColor", \r
59 function () {\r
60 return  new java.awt.Color (this.lr, this.lg, this.lb);\r
61 });\r
62 Clazz.defineMethod (c$, "getMaxColor", \r
63 function () {\r
64 return  new java.awt.Color (this.lr + this.dr, this.lg + this.dg, this.lb + this.db);\r
65 });\r
66 Clazz.defineMethod (c$, "getTolow", \r
67 function () {\r
68 return this.tolow;\r
69 });\r
70 Clazz.defineMethod (c$, "setTolow", \r
71 function (tolower) {\r
72 this.tolow = tolower;\r
73 }, "~B");\r
74 Clazz.defineMethod (c$, "isColored", \r
75 function (feature) {\r
76 var val = feature.getScore ();\r
77 if (Float.isNaN (val)) {\r
78 return true;\r
79 }if (this.thresholdState == -1) {\r
80 return true;\r
81 }if (Float.isNaN (this.thrsh)) {\r
82 return true;\r
83 }var rtn = this.thresholdState == 1;\r
84 if (val <= this.thrsh) {\r
85 return !rtn;\r
86 } else {\r
87 return rtn;\r
88 }}, "jalview.datamodel.SequenceFeature");\r
89 Clazz.defineMethod (c$, "isColourByLabel", \r
90 function () {\r
91 return this.colourByLabel;\r
92 });\r
93 Clazz.defineMethod (c$, "setColourByLabel", \r
94 function (colourByLabel) {\r
95 this.colourByLabel = colourByLabel;\r
96 }, "~B");\r
97 Clazz.defineMethod (c$, "findColor", \r
98 function (feature) {\r
99 if (this.colourByLabel) {\r
100 if (this.ucs == null) {\r
101 this.ucs =  new jalview.schemes.UserColourScheme ();\r
102 }return this.ucs.createColourFromName (feature.getDescription ());\r
103 }if (this.range == 0.0) {\r
104 return this.getMaxColor ();\r
105 }var scr = feature.getScore ();\r
106 if (Float.isNaN (scr)) {\r
107 return this.getMinColor ();\r
108 }var scl = (scr - this.base) / this.range;\r
109 if (this.tolow) {\r
110 scl = -scl;\r
111 }if (scl < 0) {\r
112 scl = 0;\r
113 }if (scl > 1) {\r
114 scl = 1;\r
115 }return  new java.awt.Color (this.lr + scl * this.dr, this.lg + scl * this.dg, this.lb + scl * this.db);\r
116 }, "jalview.datamodel.SequenceFeature");\r
117 Clazz.defineMethod (c$, "setThresh", \r
118 function (value) {\r
119 this.thrsh = value;\r
120 }, "~N");\r
121 Clazz.defineMethod (c$, "getThresh", \r
122 function () {\r
123 return this.thrsh;\r
124 });\r
125 Clazz.defineMethod (c$, "setThreshType", \r
126 function (aboveThreshold) {\r
127 this.thresholdState = aboveThreshold;\r
128 }, "~N");\r
129 Clazz.defineMethod (c$, "getThreshType", \r
130 function () {\r
131 return this.thresholdState;\r
132 });\r
133 Clazz.defineMethod (c$, "getMax", \r
134 function () {\r
135 return (this.tolow) ? this.base : (this.base + this.range);\r
136 });\r
137 Clazz.defineMethod (c$, "getMin", \r
138 function () {\r
139 return (this.tolow) ? (this.base + this.range) : this.base;\r
140 });\r
141 Clazz.defineMethod (c$, "isAutoScale", \r
142 function () {\r
143 return this.autoScale;\r
144 });\r
145 Clazz.defineMethod (c$, "setAutoScaled", \r
146 function (autoscale) {\r
147 this.autoScale = autoscale;\r
148 }, "~B");\r
149 Clazz.defineMethod (c$, "updateBounds", \r
150 function (min, max) {\r
151 if (max < min) {\r
152 this.base = max;\r
153 this.range = min - max;\r
154 this.tolow = true;\r
155 } else {\r
156 this.base = min;\r
157 this.range = max - min;\r
158 this.tolow = false;\r
159 }}, "~N,~N");\r
160 });\r