import jalview.datamodel.SequencePoint;
import jalview.math.RotatableMatrix;
import jalview.math.RotatableMatrix.Axis;
+import jalview.util.ColorUtils;
import jalview.util.MessageManager;
import jalview.viewmodel.AlignmentViewport;
sequenceColour = Color.gray;
}
}
- if (sp.coord.z < 0f)
+
+ /*
+ * graduate brighter for point in front of centre, darker if behind centre
+ */
+ float zCentre = (seqMin[2] + seqMax[2]) / 2f;
+ if (sp.coord.z > zCentre)
+ {
+ sequenceColour = ColorUtils.getGraduatedColour(sp.coord.z, 0,
+ sequenceColour, seqMax[2], sequenceColour.brighter());
+ }
+ else if (sp.coord.z < zCentre)
{
- sequenceColour = sequenceColour.darker();
+ sequenceColour = ColorUtils.getGraduatedColour(sp.coord.z, seqMin[2],
+ sequenceColour.darker(), 0, sequenceColour);
}
return sequenceColour;
public class ColorUtils
{
- // constant borrowed from java.awt.Color
- private static final float FACTOR = 0.7f;
-
private static final int MAX_CACHE_SIZE = 1729;
/*
* a cache for colours generated from text strings
return col;
}
-
- /**
- * Generates a colour that is interpolated between
- * <code>colour.darker()</code> and <code>colour.brighter()</code> in
- * proportion as <code>value</code> is between <code>min</code> and
- * <code>max</code>. Note that the 'neutral point' (unchanged colour) is
- * closer to 'brighter' than to 'darker'as this is a geometric range.
- *
- * @param value
- * @param min
- * @param max
- * @param colour
- * @return
- */
- public static Color getGraduatedColour(float value, float min, float max,
- Color colour)
- {
- /*
- * this computes the equivalent of
- * getGraduatedColour(value, min, colour.darker(), max, colour.brighter())
- * but avoiding object creation except for the return value
- */
- if (value < min)
- {
- value = min;
- }
- if (value > max)
- {
- value = max;
- }
-
- int r = colour.getRed();
- int g = colour.getGreen();
- int b = colour.getBlue();
-
- /*
- * rgb for colour.darker():
- */
- float minR = r * FACTOR;
- float minG = g * FACTOR;
- float minB = b * FACTOR;
-
- /*
- * rgb for colour.brighter():
- */
- float maxR = Math.min(255f, r / FACTOR);
- float maxG = Math.min(255f, g / FACTOR);
- float maxB = Math.min(255f, b / FACTOR);
-
- /*
- * interpolation
- */
- float p = (value - min) / (max - min);
- int newR = (int) (minR + p * (maxR - minR));
- int newG = (int) (minG + p * (maxG - minG));
- int newB = (int) (minB + p * (maxB - minB));
-
- return new Color(newR, newG, newB, colour.getAlpha());
- }
}
assertEquals(new Color(184, 184, 184),
ColorUtils.createColourFromName("HELLO HELLO HELLO "));
}
-
- /**
- * Tests for the method that returns a colour graduated between darker() and
- * brighter()
- */
- @Test(groups = { "Functional" })
- public void testGetGraduatedColour_darkerToBrighter()
- {
- final Color colour = new Color(180, 200, 220);
-
- /*
- * value half-way between min and max does _not_ mean colour unchanged
- * darker (*.7) is (126, 140, 154)
- * brighter (*1/.7) is (255, 255, 255)
- * midway is (190, 197, 204)
- */
- Color col = ColorUtils.getGraduatedColour(20f, 10f, 30f, colour);
- assertEquals(190, col.getRed());
- assertEquals(197, col.getGreen());
- assertEquals(204, col.getBlue());
-
- // minValue (or less) returns colour.darker()
- // - or would do if Color.darker calculated better!
- col = ColorUtils.getGraduatedColour(10f, 10f, 30f, colour);
- assertEquals(col, new Color(126, 140, 154));
- // Color.darker computes 125.999999 and rounds down!
- assertEquals(new Color(125, 140, 154), colour.darker());
- col = ColorUtils.getGraduatedColour(-10f, 10f, 30f, colour);
- assertEquals(new Color(126, 140, 154), col);
-
- // maxValue (or more) returns colour.brighter()
- col = ColorUtils.getGraduatedColour(30f, 10f, 30f, colour);
- assertEquals(colour.brighter(), col);
- col = ColorUtils.getGraduatedColour(40f, 10f, 30f, colour);
- assertEquals(colour.brighter(), col);
-
- /*
- * 'linear' mid-point between 0.7 and 1/0.7 is 1.057
- * so the '
- */
- Color c = new Color(200, 200, 200);
- col = ColorUtils.getGraduatedColour(106f, 0f, 200f, c);
- assertEquals(c, col);
- }
}