From: gmungoc Date: Fri, 21 Sep 2018 08:52:19 +0000 (+0100) Subject: JAL-3120 preserve feature colour/mincolour/maxcolour while modifying, X-Git-Tag: Release_2_11_0~17^2~80^2 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=e42eed3a0089a8a064560df4cf17a5021fd1e16a;p=jalview.git JAL-3120 preserve feature colour/mincolour/maxcolour while modifying, rationalise FeatureColour constructors --- diff --git a/src/jalview/appletgui/FeatureColourChooser.java b/src/jalview/appletgui/FeatureColourChooser.java index d9eae11..5569ab0 100644 --- a/src/jalview/appletgui/FeatureColourChooser.java +++ b/src/jalview/appletgui/FeatureColourChooser.java @@ -134,7 +134,8 @@ public class FeatureColourChooser extends Panel implements ActionListener, if (oldcs.isGraduatedColour()) { threshline.value = oldcs.getThreshold(); - cs = new FeatureColour((FeatureColour) oldcs, min, max); + cs = new FeatureColour(oldcs.getColour(), oldcs.getMinColour(), + oldcs.getMaxColour(), oldcs.getNoColour(), min, max); } else { @@ -145,7 +146,8 @@ public class FeatureColourChooser extends Panel implements ActionListener, bl = oldcs.getColour(); } // original colour becomes the maximum colour - cs = new FeatureColour(Color.white, bl, mm[0], mm[1]); + cs = new FeatureColour(bl, Color.white, bl, Color.white, mm[0], + mm[1]); } minColour.setBackground(cs.getMinColour()); maxColour.setBackground(cs.getMaxColour()); @@ -411,8 +413,9 @@ public class FeatureColourChooser extends Panel implements ActionListener, slider.setEnabled(true); thresholdValue.setEnabled(true); - FeatureColour acg = new FeatureColour(minColour.getBackground(), - maxColour.getBackground(), min, max); + Color minc = minColour.getBackground(); + Color maxc = maxColour.getBackground(); + FeatureColour acg = new FeatureColour(maxc, minc, maxc, minc, min, max); acg.setColourByLabel(colourFromLabel.getState()); maxColour.setEnabled(!colourFromLabel.getState()); @@ -448,11 +451,15 @@ public class FeatureColourChooser extends Panel implements ActionListener, { if (thresholdOption == AnnotationColourGradient.ABOVE_THRESHOLD) { - acg = new FeatureColour(acg, threshline.value, max); + acg = new FeatureColour(acg.getColour(), acg.getMinColour(), + acg.getMaxColour(), acg.getNoColour(), threshline.value, + max); } else { - acg = new FeatureColour(acg, min, threshline.value); + acg = new FeatureColour(acg.getColour(), acg.getMinColour(), + acg.getMaxColour(), acg.getNoColour(), min, + threshline.value); } } diff --git a/src/jalview/gui/FeatureTypeSettings.java b/src/jalview/gui/FeatureTypeSettings.java index 55bc519..843c1f3 100644 --- a/src/jalview/gui/FeatureTypeSettings.java +++ b/src/jalview/gui/FeatureTypeSettings.java @@ -563,13 +563,20 @@ public class FeatureTypeSettings extends JalviewDialog maxColour.setBorder(new LineBorder(Color.black)); /* - * default max colour to last plain colour; - * make min colour a pale version of max colour + * if not set, default max colour to last plain colour, + * and make min colour a pale version of max colour */ - FeatureColourI fc = fr.getFeatureColours().get(featureType); - Color bg = fc.getColour() == null ? Color.BLACK : fc.getColour(); - maxColour.setBackground(bg); - minColour.setBackground(ColorUtils.bleachColour(bg, 0.9f)); + Color max = originalColour.getMaxColour(); + if (max == null) + { + max = originalColour.getColour(); + minColour.setBackground(ColorUtils.bleachColour(max, 0.9f)); + } + else + { + maxColour.setBackground(max); + minColour.setBackground(originalColour.getMinColour()); + } noValueCombo = new JComboBox<>(); noValueCombo.addItem(MessageManager.getString("label.no_colour")); @@ -747,16 +754,16 @@ public class FeatureTypeSettings extends JalviewDialog singleColour.setFont(JvSwingUtils.getLabelFont()); singleColour.setBorder(BorderFactory.createLineBorder(Color.black)); singleColour.setPreferredSize(new Dimension(40, 20)); - if (originalColour.isGraduatedColour()) - { - singleColour.setBackground(originalColour.getMaxColour()); - singleColour.setForeground(originalColour.getMaxColour()); - } - else - { + // if (originalColour.isGraduatedColour()) + // { + // singleColour.setBackground(originalColour.getMaxColour()); + // singleColour.setForeground(originalColour.getMaxColour()); + // } + // else + // { singleColour.setBackground(originalColour.getColour()); singleColour.setForeground(originalColour.getColour()); - } + // } singleColour.addMouseListener(new MouseAdapter() { @Override @@ -881,42 +888,9 @@ public class FeatureTypeSettings extends JalviewDialog private FeatureColourI makeColourFromInputs() { /* - * easiest case - a single colour + * min-max range is to (or from) threshold value if + * 'threshold is min/max' is selected */ - if (simpleColour.isSelected()) - { - return new FeatureColour(singleColour.getBackground()); - } - - /* - * next easiest case - colour by Label, or attribute text - */ - if (byCategory.isSelected()) - { - Color c = singleColour.getBackground(); - FeatureColourI fc = new FeatureColour(c); - fc.setColourByLabel(true); - String byWhat = (String) colourByTextCombo.getSelectedItem(); - if (!LABEL_18N.equals(byWhat)) - { - fc.setAttributeName( - FeatureMatcher.fromAttributeDisplayName(byWhat)); - } - return fc; - } - - /* - * remaining case - graduated colour by score, or attribute value - */ - Color noColour = null; - if (noValueCombo.getSelectedIndex() == MIN_COLOUR_OPTION) - { - noColour = minColour.getBackground(); - } - else if (noValueCombo.getSelectedIndex() == MAX_COLOUR_OPTION) - { - noColour = maxColour.getBackground(); - } float thresh = 0f; try @@ -926,11 +900,6 @@ public class FeatureTypeSettings extends JalviewDialog { // invalid inputs are already handled on entry } - - /* - * min-max range is to (or from) threshold value if - * 'threshold is min/max' is selected - */ float minValue = min; float maxValue = max; final int thresholdOption = threshold.getSelectedIndex(); @@ -944,14 +913,50 @@ public class FeatureTypeSettings extends JalviewDialog { maxValue = thresh; } + Color noColour = null; + if (noValueCombo.getSelectedIndex() == MIN_COLOUR_OPTION) + { + noColour = minColour.getBackground(); + } + else if (noValueCombo.getSelectedIndex() == MAX_COLOUR_OPTION) + { + noColour = maxColour.getBackground(); + } + + /* + * construct a colour that 'remembers' all the options, including + * those not currently selected + */ + FeatureColourI fc = new FeatureColour(singleColour.getBackground(), + minColour.getBackground(), maxColour.getBackground(), noColour, + minValue, maxValue); + + /* + * easiest case - a single colour + */ + if (simpleColour.isSelected()) + { + ((FeatureColour) fc).setGraduatedColour(false); + return fc; + } /* - * make the graduated colour + * next easiest case - colour by Label, or attribute text */ - FeatureColourI fc = new FeatureColour(minColour.getBackground(), - maxColour.getBackground(), noColour, minValue, maxValue); + if (byCategory.isSelected()) + { + fc.setColourByLabel(true); + String byWhat = (String) colourByTextCombo.getSelectedItem(); + if (!LABEL_18N.equals(byWhat)) + { + fc.setAttributeName( + FeatureMatcher.fromAttributeDisplayName(byWhat)); + } + return fc; + } /* + * remaining case - graduated colour by score, or attribute value; * set attribute to colour by if selected */ String byWhat = (String) colourByRangeCombo.getSelectedItem(); diff --git a/src/jalview/gui/Jalview2XML.java b/src/jalview/gui/Jalview2XML.java index 9285754..28077e6 100644 --- a/src/jalview/gui/Jalview2XML.java +++ b/src/jalview/gui/Jalview2XML.java @@ -52,7 +52,6 @@ import jalview.schemabinding.version2.Annotation; import jalview.schemabinding.version2.AnnotationColours; import jalview.schemabinding.version2.AnnotationElement; import jalview.schemabinding.version2.CalcIdParam; -import jalview.schemabinding.version2.Colour; import jalview.schemabinding.version2.CompoundMatcher; import jalview.schemabinding.version2.DBRef; import jalview.schemabinding.version2.Features; @@ -4694,8 +4693,8 @@ public class Jalview2XML } float min = setting.hasMin() ? setting.getMin() : 0f; float max = setting.hasMin() ? setting.getMax() : 1f; - FeatureColourI gc = new FeatureColour(minColour, maxColour, - noValueColour, min, max); + FeatureColourI gc = new FeatureColour(maxColour, minColour, + maxColour, noValueColour, min, max); if (setting.getAttributeNameCount() > 0) { gc.setAttributeName(setting.getAttributeName()); @@ -5955,9 +5954,8 @@ public class Jalview2XML noValueColour = maxcol; } - colour = new FeatureColour(mincol, maxcol, noValueColour, - colourModel.getMin(), - colourModel.getMax()); + colour = new FeatureColour(maxcol, mincol, maxcol, noValueColour, + colourModel.getMin(), colourModel.getMax()); String[] attributes = colourModel.getAttributeName(); if (attributes != null && attributes.length > 0) { diff --git a/src/jalview/schemes/FeatureColour.java b/src/jalview/schemes/FeatureColour.java index 7d14662..55fdf24 100644 --- a/src/jalview/schemes/FeatureColour.java +++ b/src/jalview/schemes/FeatureColour.java @@ -358,8 +358,8 @@ public class FeatureColour implements FeatureColourI Color maxColour = ColorUtils.parseColourString(maxcol); Color noColour = noValueColour.equals(NO_VALUE_MAX) ? maxColour : (noValueColour.equals(NO_VALUE_NONE) ? null : minColour); - featureColour = new FeatureColour(minColour, maxColour, noColour, min, - max); + featureColour = new FeatureColour(maxColour, minColour, maxColour, + noColour, min, max); featureColour.setColourByLabel(minColour == null); featureColour.setAutoScaled(autoScaled); if (byAttribute) @@ -429,36 +429,25 @@ public class FeatureColour implements FeatureColourI } /** - * Constructor given a simple colour + * Constructor given a simple colour. This also 'primes' a graduated colour + * range, where the maximum colour is the given simple colour, and the minimum + * colour a paler shade of it. This is for convenience when switching from a + * simple colour to a graduated colour scheme. * * @param c */ public FeatureColour(Color c) { - minColour = Color.WHITE; - maxColour = Color.BLACK; - noColour = DEFAULT_NO_COLOUR; - minRed = 0f; - minGreen = 0f; - minBlue = 0f; - deltaRed = 0f; - deltaGreen = 0f; - deltaBlue = 0f; - colour = c; - } + /* + * set max colour to the simple colour, min colour to a paler shade of it + */ + this(c, c == null ? Color.white : ColorUtils.bleachColour(c, 0.9f), + c == null ? Color.black : c, DEFAULT_NO_COLOUR, 0, 0); - /** - * Constructor given a colour range and a score range, defaulting 'no value - * colour' to be the same as minimum colour - * - * @param low - * @param high - * @param min - * @param max - */ - public FeatureColour(Color low, Color high, float min, float max) - { - this(low, high, low, min, max); + /* + * but enforce simple colour for now! + */ + setGraduatedColour(false); } /** @@ -491,29 +480,23 @@ public class FeatureColour implements FeatureColourI } /** - * Copy constructor with new min/max ranges - * - * @param fc - * @param min - * @param max - */ - public FeatureColour(FeatureColour fc, float min, float max) - { - this(fc); - updateBounds(min, max); - } - - /** - * Constructor for a graduated colour + * Constructor that sets both simple and graduated colour values. This allows + * alternative colour schemes to be 'preserved' while switching between them + * to explore their effects on the visualisation. + *

+ * This sets the colour scheme to 'graduated' by default. Override this if + * wanted by calling setGraduatedColour(false) for a simple + * colour, or setColourByLabel(true) for colour by label. * + * @param myColour * @param low * @param high * @param noValueColour * @param min * @param max */ - public FeatureColour(Color low, Color high, Color noValueColour, - float min, float max) + public FeatureColour(Color myColour, Color low, Color high, + Color noValueColour, float min, float max) { if (low == null) { @@ -523,10 +506,10 @@ public class FeatureColour implements FeatureColourI { high = Color.black; } - graduatedColour = true; - colour = null; + colour = myColour; minColour = low; maxColour = high; + setGraduatedColour(true); noColour = noValueColour; threshold = Float.NaN; isHighToLow = min >= max; @@ -558,7 +541,7 @@ public class FeatureColour implements FeatureColourI * Sets the 'graduated colour' flag. If true, also sets 'colour by label' to * false. */ - void setGraduatedColour(boolean b) + public void setGraduatedColour(boolean b) { graduatedColour = b; if (b) @@ -830,9 +813,20 @@ public class FeatureColour implements FeatureColourI sb.append(BAR).append(Format.getHexString(getMinColour())) .append(BAR); sb.append(Format.getHexString(getMaxColour())).append(BAR); - String noValue = minColour.equals(noColour) ? NO_VALUE_MIN - : (maxColour.equals(noColour) ? NO_VALUE_MAX - : NO_VALUE_NONE); + + /* + * 'no value' colour should be null, min or max colour; + * if none of these, coerce to minColour + */ + String noValue = NO_VALUE_MIN; + if (maxColour.equals(noColour)) + { + noValue = NO_VALUE_MAX; + } + if (noColour == null) + { + noValue = NO_VALUE_NONE; + } sb.append(noValue).append(BAR); if (!isAutoScaled()) { diff --git a/src/jalview/ws/jws2/AADisorderClient.java b/src/jalview/ws/jws2/AADisorderClient.java index 9a2316c..a1b8e7a 100644 --- a/src/jalview/ws/jws2/AADisorderClient.java +++ b/src/jalview/ws/jws2/AADisorderClient.java @@ -344,8 +344,9 @@ public class AADisorderClient extends JabawsCalcWorker { // set graduated color as fading to white for minimum, and // autoscaling to values on alignment - FeatureColourI ggc = new FeatureColour(Color.white, - gc.getColour(), Float.MIN_VALUE, Float.MAX_VALUE); + FeatureColourI ggc = new FeatureColour(gc.getColour(), + Color.white, gc.getColour(), Color.white, + Float.MIN_VALUE, Float.MAX_VALUE); ggc.setAutoScaled(true); fr.setColour(ft, ggc); } diff --git a/test/jalview/controller/AlignViewControllerTest.java b/test/jalview/controller/AlignViewControllerTest.java index efee93b..68b0b57 100644 --- a/test/jalview/controller/AlignViewControllerTest.java +++ b/test/jalview/controller/AlignViewControllerTest.java @@ -147,7 +147,8 @@ public class AlignViewControllerTest * seq1 feature in columns 4-6 is hidden * seq2 feature in columns 6-7 is shown */ - FeatureColourI fc = new FeatureColour(Color.red, Color.blue, 0f, 10f); + FeatureColourI fc = new FeatureColour(null, Color.red, Color.blue, null, + 0f, 10f); fc.setAboveThreshold(true); fc.setThreshold(5f); af.getFeatureRenderer().setColour("Metal", fc); diff --git a/test/jalview/gui/AlignFrameTest.java b/test/jalview/gui/AlignFrameTest.java index b0aaab9..afb61d0 100644 --- a/test/jalview/gui/AlignFrameTest.java +++ b/test/jalview/gui/AlignFrameTest.java @@ -118,7 +118,8 @@ public class AlignFrameTest * seq1 feature in columns 1-5 is hidden * seq2 feature in columns 6-10 is shown */ - FeatureColourI fc = new FeatureColour(Color.red, Color.blue, 0f, 10f); + FeatureColourI fc = new FeatureColour(null, Color.red, Color.blue, null, + 0f, 10f); fc.setAboveThreshold(true); fc.setThreshold(5f); alignFrame.getFeatureRenderer().setColour("Metal", fc); diff --git a/test/jalview/gui/FeatureSettingsTest.java b/test/jalview/gui/FeatureSettingsTest.java index 6ddebf8..29c3e56 100644 --- a/test/jalview/gui/FeatureSettingsTest.java +++ b/test/jalview/gui/FeatureSettingsTest.java @@ -60,8 +60,8 @@ public class FeatureSettingsTest fr.setColour("type2", byLabel); // type3: by score above threshold - FeatureColourI byScore = new FeatureColour(Color.BLACK, Color.BLUE, 1, - 10); + FeatureColourI byScore = new FeatureColour(null, Color.BLACK, + Color.BLUE, null, 1, 10); byScore.setAboveThreshold(true); byScore.setThreshold(2f); fr.setColour("type3", byScore); @@ -73,8 +73,8 @@ public class FeatureSettingsTest fr.setColour("type4", byAF); // type5: by attribute CSQ:PolyPhen below threshold - FeatureColourI byPolyPhen = new FeatureColour(Color.BLACK, Color.BLUE, - 1, 10); + FeatureColourI byPolyPhen = new FeatureColour(null, Color.BLACK, + Color.BLUE, null, 1, 10); byPolyPhen.setBelowThreshold(true); byPolyPhen.setThreshold(3f); byPolyPhen.setAttributeName("CSQ", "PolyPhen"); diff --git a/test/jalview/io/Jalview2xmlTests.java b/test/jalview/io/Jalview2xmlTests.java index 53bb0e7..505d1f1 100644 --- a/test/jalview/io/Jalview2xmlTests.java +++ b/test/jalview/io/Jalview2xmlTests.java @@ -914,8 +914,8 @@ public class Jalview2xmlTests extends Jalview2xmlBase fr.setColour("type2", byLabel); // type3: by score above threshold - FeatureColourI byScore = new FeatureColour(Color.BLACK, Color.BLUE, 1, - 10); + FeatureColourI byScore = new FeatureColour(null, Color.BLACK, + Color.BLUE, null, 1, 10); byScore.setAboveThreshold(true); byScore.setThreshold(2f); fr.setColour("type3", byScore); @@ -927,8 +927,8 @@ public class Jalview2xmlTests extends Jalview2xmlBase fr.setColour("type4", byAF); // type5: by attribute CSQ:PolyPhen below threshold - FeatureColourI byPolyPhen = new FeatureColour(Color.BLACK, Color.BLUE, - 1, 10); + FeatureColourI byPolyPhen = new FeatureColour(null, Color.BLACK, + Color.BLUE, null, 1, 10); byPolyPhen.setBelowThreshold(true); byPolyPhen.setThreshold(3f); byPolyPhen.setAttributeName("CSQ", "PolyPhen"); diff --git a/test/jalview/io/SequenceAnnotationReportTest.java b/test/jalview/io/SequenceAnnotationReportTest.java index 87e35c7..cf3c7e5 100644 --- a/test/jalview/io/SequenceAnnotationReportTest.java +++ b/test/jalview/io/SequenceAnnotationReportTest.java @@ -37,11 +37,11 @@ import jalview.viewmodel.seqfeatures.FeatureRendererModel; import java.awt.Color; import java.util.Map; -import junit.extensions.PA; - import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; +import junit.extensions.PA; + public class SequenceAnnotationReportTest { @@ -158,7 +158,8 @@ public class SequenceAnnotationReportTest /* * then with colour by an attribute the feature lacks */ - FeatureColourI fc = new FeatureColour(Color.white, Color.black, 5, 10); + FeatureColourI fc = new FeatureColour(null, Color.white, Color.black, + null, 5, 10); fc.setAttributeName("Pfam"); fr.setColour("METAL", fc); sb.setLength(0); @@ -187,7 +188,8 @@ public class SequenceAnnotationReportTest FeatureRendererModel fr = new FeatureRenderer(null); Map minmax = fr.getMinMax(); - FeatureColourI fc = new FeatureColour(Color.white, Color.blue, 12, 22); + FeatureColourI fc = new FeatureColour(null, Color.white, Color.blue, + null, 12, 22); fc.setAttributeName("clinical_significance"); fr.setColour("METAL", fc); minmax.put("METAL", new float[][] { { 0f, 1f }, null }); @@ -328,7 +330,8 @@ public class SequenceAnnotationReportTest // with showDbRefs = true, colour Variant features by clinical_significance sb.setLength(0); - FeatureColourI fc = new FeatureColour(Color.green, Color.pink, 2, 3); + FeatureColourI fc = new FeatureColour(null, Color.green, Color.pink, + null, 2, 3); fc.setAttributeName("clinical_significance"); fr.setColour("Variant", fc); sar.createSequenceAnnotationReport(sb, seq, true, true, fr); diff --git a/test/jalview/renderer/seqfeatures/FeatureColourFinderTest.java b/test/jalview/renderer/seqfeatures/FeatureColourFinderTest.java index d8b905e..af7c2ed 100644 --- a/test/jalview/renderer/seqfeatures/FeatureColourFinderTest.java +++ b/test/jalview/renderer/seqfeatures/FeatureColourFinderTest.java @@ -323,7 +323,7 @@ public class FeatureColourFinderTest */ Color min = new Color(100, 50, 150); Color max = new Color(200, 0, 100); - FeatureColourI fc = new FeatureColour(min, max, 0, 10); + FeatureColourI fc = new FeatureColour(null, min, max, null, 0, 10); fr.setColour("kd", fc); fr.featuresAdded(); av.setShowSequenceFeatures(true); @@ -493,7 +493,7 @@ public class FeatureColourFinderTest */ Color min = new Color(100, 50, 150); Color max = new Color(200, 0, 100); - FeatureColourI fc = new FeatureColour(min, max, 0, 10); + FeatureColourI fc = new FeatureColour(null, min, max, null, 0, 10); fc.setAboveThreshold(true); fc.setThreshold(5f); fr.setColour(kdFeature, fc); diff --git a/test/jalview/renderer/seqfeatures/FeatureRendererTest.java b/test/jalview/renderer/seqfeatures/FeatureRendererTest.java index 11b129e..ba8b581 100644 --- a/test/jalview/renderer/seqfeatures/FeatureRendererTest.java +++ b/test/jalview/renderer/seqfeatures/FeatureRendererTest.java @@ -285,8 +285,8 @@ public class FeatureRendererTest * give "Type3" features a graduated colour scheme * - first with no threshold */ - FeatureColourI gc = new FeatureColour(Color.yellow, Color.red, null, 0f, - 10f); + FeatureColourI gc = new FeatureColour(Color.green, Color.yellow, + Color.red, null, 0f, 10f); fr.getFeatureColours().put("Type3", gc); features = fr.findFeaturesAtColumn(seq, 8); assertTrue(features.contains(sf4)); @@ -428,8 +428,8 @@ public class FeatureRendererTest * graduated colour by score, no threshold, no score * */ - FeatureColourI gc = new FeatureColour(Color.yellow, Color.red, - Color.green, 1f, 11f); + FeatureColourI gc = new FeatureColour(Color.red, Color.yellow, + Color.red, Color.green, 1f, 11f); fr.getFeatureColours().put("Cath", gc); assertEquals(fr.getColour(sf1), Color.green); @@ -453,7 +453,8 @@ public class FeatureRendererTest * threshold is min-max; now score 6 is 1/6 of the way from 5 to 11 * or from yellow(255, 255, 0) to red(255, 0, 0) */ - gc = new FeatureColour(Color.yellow, Color.red, Color.green, 5f, 11f); + gc = new FeatureColour(Color.red, Color.yellow, Color.red, Color.green, + 5f, 11f); fr.getFeatureColours().put("Cath", gc); gc.setAutoScaled(false); // this does little other than save a checkbox setting! assertEquals(fr.getColour(sf2), new Color(255, 213, 0)); @@ -476,7 +477,8 @@ public class FeatureRendererTest * colour by feature attribute value * first with no value held */ - gc = new FeatureColour(Color.yellow, Color.red, Color.green, 1f, 11f); + gc = new FeatureColour(Color.red, Color.yellow, Color.red, Color.green, + 1f, 11f); fr.getFeatureColours().put("Cath", gc); gc.setAttributeName("AF"); assertEquals(fr.getColour(sf2), Color.green); diff --git a/test/jalview/schemes/FeatureColourTest.java b/test/jalview/schemes/FeatureColourTest.java index 2eb718b..1a6a5f3 100644 --- a/test/jalview/schemes/FeatureColourTest.java +++ b/test/jalview/schemes/FeatureColourTest.java @@ -38,8 +38,6 @@ import java.awt.Color; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; -import junit.extensions.PA; - public class FeatureColourTest { @@ -51,6 +49,30 @@ public class FeatureColourTest } @Test(groups = { "Functional" }) + public void testConstructors() + { + FeatureColourI fc = new FeatureColour(); + assertNull(fc.getColour()); + assertTrue(fc.isSimpleColour()); + assertFalse(fc.isColourByLabel()); + assertFalse(fc.isGraduatedColour()); + assertFalse(fc.isColourByAttribute()); + assertEquals(Color.white, fc.getMinColour()); + assertEquals(Color.black, fc.getMaxColour()); + + fc = new FeatureColour(Color.RED); + assertEquals(Color.red, fc.getColour()); + assertTrue(fc.isSimpleColour()); + assertFalse(fc.isColourByLabel()); + assertFalse(fc.isGraduatedColour()); + assertFalse(fc.isColourByAttribute()); + assertEquals(ColorUtils.bleachColour(Color.RED, 0.9f), + fc.getMinColour()); + assertEquals(Color.RED, fc.getMaxColour()); + + } + + @Test(groups = { "Functional" }) public void testCopyConstructor() { /* @@ -67,7 +89,8 @@ public class FeatureColourTest /* * min-max colour */ - fc = new FeatureColour(Color.gray, Color.black, 10f, 20f); + fc = new FeatureColour(null, Color.gray, Color.black, Color.gray, 10f, + 20f); fc.setAboveThreshold(true); fc.setThreshold(12f); fc1 = new FeatureColour(fc); @@ -86,12 +109,14 @@ public class FeatureColourTest /* * min-max-noValue colour */ - fc = new FeatureColour(Color.gray, Color.black, Color.green, 10f, 20f); + fc = new FeatureColour(Color.red, Color.gray, Color.black, Color.green, + 10f, 20f); fc.setAboveThreshold(true); fc.setThreshold(12f); fc1 = new FeatureColour(fc); assertTrue(fc1.isGraduatedColour()); assertFalse(fc1.isColourByLabel()); + assertFalse(fc1.isSimpleColour()); assertFalse(fc1.isColourByAttribute()); assertNull(fc1.getAttributeName()); assertTrue(fc1.isAboveThreshold()); @@ -99,6 +124,7 @@ public class FeatureColourTest assertEquals(Color.gray, fc1.getMinColour()); assertEquals(Color.black, fc1.getMaxColour()); assertEquals(Color.green, fc1.getNoColour()); + assertEquals(Color.red, fc1.getColour()); assertEquals(10f, fc1.getMin()); assertEquals(20f, fc1.getMax()); @@ -128,7 +154,8 @@ public class FeatureColourTest /* * colour by attribute (value) */ - fc = new FeatureColour(Color.gray, Color.black, Color.green, 10f, 20f); + fc = new FeatureColour(Color.yellow, Color.gray, Color.black, + Color.green, 10f, 20f); fc.setAboveThreshold(true); fc.setThreshold(12f); fc.setAttributeName("AF"); @@ -136,104 +163,19 @@ public class FeatureColourTest assertTrue(fc1.isGraduatedColour()); assertFalse(fc1.isColourByLabel()); assertTrue(fc1.isColourByAttribute()); + assertFalse(fc1.isSimpleColour()); assertArrayEquals(new String[] { "AF" }, fc1.getAttributeName()); assertTrue(fc1.isAboveThreshold()); assertEquals(12f, fc1.getThreshold()); assertEquals(Color.gray, fc1.getMinColour()); assertEquals(Color.black, fc1.getMaxColour()); assertEquals(Color.green, fc1.getNoColour()); + assertEquals(Color.yellow, fc1.getColour()); assertEquals(10f, fc1.getMin()); assertEquals(20f, fc1.getMax()); } @Test(groups = { "Functional" }) - public void testCopyConstructor_minMax() - { - /* - * graduated colour - */ - FeatureColour fc = new FeatureColour(Color.BLUE, Color.RED, 1f, 5f); - assertTrue(fc.isGraduatedColour()); - assertFalse(fc.isColourByLabel()); - assertFalse(fc.isColourByAttribute()); - assertNull(fc.getAttributeName()); - assertEquals(1f, fc.getMin()); - assertEquals(5f, fc.getMax()); - - /* - * update min-max bounds - */ - FeatureColour fc1 = new FeatureColour(fc, 2f, 6f); - assertTrue(fc1.isGraduatedColour()); - assertFalse(fc1.isColourByLabel()); - assertFalse(fc1.isColourByAttribute()); - assertNull(fc1.getAttributeName()); - assertEquals(2f, fc1.getMin()); - assertEquals(6f, fc1.getMax()); - assertFalse((boolean) PA.getValue(fc1, "isHighToLow")); - - /* - * update min-max bounds - high to low - */ - fc1 = new FeatureColour(fc, 23f, 16f); - assertTrue(fc1.isGraduatedColour()); - assertFalse(fc1.isColourByLabel()); - assertFalse(fc1.isColourByAttribute()); - assertNull(fc1.getAttributeName()); - assertEquals(23f, fc1.getMin()); - assertEquals(16f, fc1.getMax()); - assertTrue((boolean) PA.getValue(fc1, "isHighToLow")); - - /* - * graduated colour by attribute - */ - fc1.setAttributeName("AF"); - fc1 = new FeatureColour(fc1, 13f, 36f); - assertTrue(fc1.isGraduatedColour()); - assertFalse(fc1.isColourByLabel()); - assertTrue(fc1.isColourByAttribute()); - assertArrayEquals(new String[] { "AF" }, fc1.getAttributeName()); - assertEquals(13f, fc1.getMin()); - assertEquals(36f, fc1.getMax()); - assertFalse((boolean) PA.getValue(fc1, "isHighToLow")); - - /* - * colour by label - */ - fc = new FeatureColour(Color.BLUE, Color.RED, 1f, 5f); - fc.setColourByLabel(true); - assertFalse(fc.isGraduatedColour()); - assertTrue(fc.isColourByLabel()); - assertFalse(fc.isColourByAttribute()); - assertNull(fc.getAttributeName()); - assertEquals(1f, fc.getMin()); - assertEquals(5f, fc.getMax()); - - /* - * update min-max bounds - */ - fc1 = new FeatureColour(fc, 2f, 6f); - assertFalse(fc1.isGraduatedColour()); - assertTrue(fc1.isColourByLabel()); - assertFalse(fc1.isColourByAttribute()); - assertNull(fc1.getAttributeName()); - assertEquals(2f, fc1.getMin()); - assertEquals(6f, fc1.getMax()); - - /* - * colour by attribute text - */ - fc1.setAttributeName("AC"); - fc1 = new FeatureColour(fc1, 13f, 36f); - assertFalse(fc1.isGraduatedColour()); - assertTrue(fc1.isColourByLabel()); - assertTrue(fc1.isColourByAttribute()); - assertArrayEquals(new String[] { "AC" }, fc1.getAttributeName()); - assertEquals(13f, fc1.getMin()); - assertEquals(36f, fc1.getMax()); - } - - @Test(groups = { "Functional" }) public void testGetColor_simpleColour() { FeatureColour fc = new FeatureColour(Color.RED); @@ -260,7 +202,8 @@ public class FeatureColourTest * score 0 to 100 * gray(128, 128, 128) to red(255, 0, 0) */ - FeatureColour fc = new FeatureColour(Color.GRAY, Color.RED, 0f, 100f); + FeatureColour fc = new FeatureColour(null, Color.GRAY, Color.RED, null, + 0f, 100f); // feature score is 75 which is 3/4 of the way from GRAY to RED SequenceFeature sf = new SequenceFeature("type", "desc", 0, 20, 75f, null); @@ -276,8 +219,8 @@ public class FeatureColourTest public void testGetColor_aboveBelowThreshold() { // gradient from [50, 150] from WHITE(255, 255, 255) to BLACK(0, 0, 0) - FeatureColour fc = new FeatureColour(Color.WHITE, Color.BLACK, 50f, - 150f); + FeatureColour fc = new FeatureColour(null, Color.WHITE, Color.BLACK, + Color.white, 50f, 150f); SequenceFeature sf = new SequenceFeature("type", "desc", 0, 20, 70f, null); @@ -371,7 +314,8 @@ public class FeatureColourTest * graduated colour by score, no threshold * - default constructor sets noValueColor = minColor */ - fc = new FeatureColour(Color.GREEN, Color.RED, 12f, 25f); + fc = new FeatureColour(null, Color.GREEN, Color.RED, Color.GREEN, 12f, + 25f); String greenHex = Format.getHexString(Color.GREEN); String expected = String.format( "domain\tscore|%s|%s|noValueMin|abso|12.0|25.0|none", greenHex, @@ -381,7 +325,8 @@ public class FeatureColourTest /* * graduated colour by score, no threshold, no value gets min colour */ - fc = new FeatureColour(Color.GREEN, Color.RED, Color.GREEN, 12f, 25f); + fc = new FeatureColour(Color.RED, Color.GREEN, Color.RED, Color.GREEN, + 12f, 25f); expected = String.format( "domain\tscore|%s|%s|noValueMin|abso|12.0|25.0|none", greenHex, redHex); @@ -390,7 +335,8 @@ public class FeatureColourTest /* * graduated colour by score, no threshold, no value gets max colour */ - fc = new FeatureColour(Color.GREEN, Color.RED, Color.RED, 12f, 25f); + fc = new FeatureColour(Color.RED, Color.GREEN, Color.RED, Color.RED, + 12f, 25f); expected = String.format( "domain\tscore|%s|%s|noValueMax|abso|12.0|25.0|none", greenHex, redHex); @@ -638,8 +584,9 @@ public class FeatureColourTest * graduated colour based on attribute value for AF * given a min-max range of 0-100 */ - FeatureColour fc = new FeatureColour(new Color(50, 100, 150), - new Color(150, 200, 250), Color.yellow, 0f, 100f); + FeatureColour fc = new FeatureColour(Color.white, + new Color(50, 100, 150), new Color(150, 200, 250), Color.yellow, + 0f, 100f); String attName = "AF"; fc.setAttributeName(attName);