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