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 * construct a graduatedColor object from simple parameters
33 * color low->high from min->max
35 public GraduatedColor(Color low,Color high, float min,float max)
39 lr = low.getRed()/255f;
40 lg = low.getGreen()/255f;
41 lb = low.getBlue()/255f;
42 dr = (high.getRed()/255f)-lr;
43 dg = (high.getGreen()/255f)-lg;
44 db = (high.getBlue()/255f)-lb;
54 public GraduatedColor(GraduatedColor oldcs)
65 thresholdState = oldcs.thresholdState;
69 * make a new gradient from an old one with a different scale range
74 public GraduatedColor(GraduatedColor oldcs, float min, float max)
88 public Color getMinColor()
90 return new Color(lr,lg,lb);
92 public Color getMaxColor()
94 return new Color(lr+dr,lg+dg,lb+db);
96 public boolean getTolow()
100 public void setTolow(boolean tolower)
104 public boolean isColored(SequenceFeature feature)
106 float val = feature.getScore();
111 if (this.thresholdState==AnnotationColourGradient.NO_THRESHOLD)
115 if (this.thrsh==Float.NaN)
119 boolean rtn = thresholdState==AnnotationColourGradient.ABOVE_THRESHOLD;
122 return !rtn; // ? !tolow : tolow;
124 return rtn; // ? tolow : !tolow;
127 public Color findColor(SequenceFeature feature)
131 return getMaxColor();
133 float scr = feature.getScore();
136 return getMinColor();
138 float scl = (scr-base)/range;
139 if (tolow) { scl = -scl; }
140 if (scl<0f) { scl = 0f; }
141 if (scl>1f) { scl = 1f; }
142 return new Color(lr+scl*dr,lg+scl*dg,lb+scl*db);
144 public void setThresh(float value)
148 public void setThreshType(int aboveThreshold)
150 thresholdState = aboveThreshold;
152 public int getThreshType()
154 return thresholdState;