4 package jalview.schemes;
6 import jalview.datamodel.SequenceFeature;
11 * Value and/or thresholded colour scale used for colouring by annotation and feature score
15 public class GraduatedColor
17 int thresholdState = AnnotationColourGradient.NO_THRESHOLD; // or ABOVE_THRESHOLD or BELOW_THRESHOLD
18 float lr,lg,lb,dr,dg,db;
20 * linear scaling parameters, base, minimum colour threshold, range of linear scale from lower to upper
22 float base,range,thrsh;
24 * when true, colour from u to u-d rather than u to u+d
28 * when false, min/max range has been manually set so should not be dynamically adjusted.
30 boolean autoScale = true;
32 * construct a graduatedColor object from simple parameters
37 * color low->high from min->max
39 public GraduatedColor(Color low,Color high, float min,float max)
43 lr = low.getRed()/255f;
44 lg = low.getGreen()/255f;
45 lb = low.getBlue()/255f;
46 dr = (high.getRed()/255f)-lr;
47 dg = (high.getGreen()/255f)-lg;
48 db = (high.getBlue()/255f)-lb;
58 public GraduatedColor(GraduatedColor oldcs)
69 thresholdState = oldcs.thresholdState;
71 autoScale = oldcs.autoScale;
74 * make a new gradient from an old one with a different scale range
79 public GraduatedColor(GraduatedColor oldcs, float min, float max)
82 updateBounds(min, max);
84 public Color getMinColor()
86 return new Color(lr,lg,lb);
88 public Color getMaxColor()
90 return new Color(lr+dr,lg+dg,lb+db);
92 public boolean getTolow()
96 public void setTolow(boolean tolower)
100 public boolean isColored(SequenceFeature feature)
102 float val = feature.getScore();
107 if (this.thresholdState==AnnotationColourGradient.NO_THRESHOLD)
111 if (this.thrsh==Float.NaN)
115 boolean rtn = thresholdState==AnnotationColourGradient.ABOVE_THRESHOLD;
118 return !rtn; // ? !tolow : tolow;
120 return rtn; // ? tolow : !tolow;
123 public Color findColor(SequenceFeature feature)
127 return getMaxColor();
129 float scr = feature.getScore();
132 return getMinColor();
134 float scl = (scr-base)/range;
135 if (tolow) { scl = -scl; }
136 if (scl<0f) { scl = 0f; }
137 if (scl>1f) { scl = 1f; }
138 return new Color(lr+scl*dr,lg+scl*dg,lb+scl*db);
140 public void setThresh(float value)
144 public float getThresh() {
147 public void setThreshType(int aboveThreshold)
149 thresholdState = aboveThreshold;
151 public int getThreshType()
153 return thresholdState;
155 public float getMax()
157 // regenerate the original values passed in to the constructor
158 return (tolow) ? base : (base + range);
160 public float getMin()
162 // regenerate the original value passed in to the constructor
163 return (tolow) ? (base+range) : base;
165 public boolean isAutoScale()
169 public void setAutoScaled(boolean autoscale) {
170 autoScale = autoscale;
173 * update the base and range appropriatly for the given minmax range
174 * @param a float[] {min,max} array containing minmax range for the associated score values
176 public void updateBounds(float min,float max)