From 9483294f728bf319f90322fbe4dd5aacc6e9fa45 Mon Sep 17 00:00:00 2001 From: gmungoc Date: Fri, 2 Dec 2016 14:02:09 +0000 Subject: [PATCH] JAL-2346 fixed bug (in code not reached by Jalview) --- src/jalview/schemes/AnnotationColourGradient.java | 34 +++++++++++++-------- 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/src/jalview/schemes/AnnotationColourGradient.java b/src/jalview/schemes/AnnotationColourGradient.java index 2c8d5dd..856bee9 100755 --- a/src/jalview/schemes/AnnotationColourGradient.java +++ b/src/jalview/schemes/AnnotationColourGradient.java @@ -289,8 +289,7 @@ public class AnnotationColourGradient extends FollowerColourScheme } if ((threshold == 0) || aboveThreshold(c, j)) { - if (ann.annotations != null - && j < ann.annotations.length + if (ann.annotations != null && j < ann.annotations.length && ann.annotations[j] != null && !jalview.util.Comparison.isGap(c)) { @@ -372,31 +371,41 @@ public class AnnotationColourGradient extends FollowerColourScheme return currentColour; } - private Color shadeCalculation(AlignmentAnnotation ann, int j) + /** + * Returns a graduated colour for the annotation at the given column. If there + * is a threshold value, and it is used as the top/bottom of the colour range, + * and the value satisfies the threshold condition, then a colour + * proportionate to the range from the threshold is calculated. For all other + * cases, a colour proportionate to the annotation's min-max range is + * calulated. Note that thresholding is _not_ done here (a colour is computed + * even if threshold is not passed), but by the renderer. + * + * @param ann + * @param col + * @return + */ + Color shadeCalculation(AlignmentAnnotation ann, int col) { - - // calculate a shade float range = 1f; + float value = ann.annotations[col].value; if (thresholdIsMinMax && ann.threshold != null && aboveAnnotationThreshold == ABOVE_THRESHOLD - && ann.annotations[j].value >= ann.threshold.value) + && value >= ann.threshold.value) { - range = (ann.annotations[j].value - ann.threshold.value) + range = (value - ann.threshold.value) / (ann.graphMax - ann.threshold.value); } else if (thresholdIsMinMax && ann.threshold != null && aboveAnnotationThreshold == BELOW_THRESHOLD - && ann.annotations[j].value >= ann.graphMin) + && value <= ann.threshold.value) { - range = (ann.annotations[j].value - ann.graphMin) - / (ann.threshold.value - ann.graphMin); + range = (value - ann.graphMin) / (ann.threshold.value - ann.graphMin); } else { if (ann.graphMax != ann.graphMin) { - range = (ann.annotations[j].value - ann.graphMin) - / (ann.graphMax - ann.graphMin); + range = (value - ann.graphMin) / (ann.graphMax - ann.graphMin); } else { @@ -409,7 +418,6 @@ public class AnnotationColourGradient extends FollowerColourScheme int db = (int) (blueRange * range + blueMin); return new Color(dr, dg, db); - } public boolean isPredefinedColours() -- 1.7.10.2