RainbowColorMap implements ColorMap<Number> { @Override public Color valueToColor(Number value) { Color color = new Color(EMPTY, EMPTY, EMPTY); int index = 0; if (range.extent != 0.0d) { double coef = (value.doubleValue() - range.min) / range.extent; index = (int)Math.floor(coef * MAX_VALUES); } if (index >= RED && index < RED_TO_YELLOW) { int addToGreen = index - RED; int red = FULL; int green = EMPTY + addToGreen; int blue = EMPTY; color = new Color(red, green, blue); } else if (index >= RED_TO_YELLOW && index < YELLOW_TO_GREEN) { int removeFromRed = index - RED_TO_YELLOW; int red = FULL - removeFromRed; int green = FULL; int blue = EMPTY; color = new Color(red, green, blue); } else if (index >= YELLOW_TO_GREEN && index < GREEN_TO_TEAL) { int addToBlue = index - YELLOW_TO_GREEN; int red = EMPTY; int green = FULL; int blue = EMPTY + addToBlue; color = new Color(red, green, blue); } else if (index >= GREEN_TO_TEAL && index < TEAL_TO_BLUE) { int removeFromGreen = index - GREEN_TO_TEAL; int red = EMPTY; int green = FULL - removeFromGreen; int blue = FULL; color = new Color(red, green, blue); } else if (index >= TEAL_TO_BLUE && index <= BLUE_TO_PURPLE) { int addToRed = index - TEAL_TO_BLUE; int red = EMPTY + addToRed; int green = EMPTY; int blue = FULL; color = new Color(red, green, blue); } return color; } RainbowColorMap(AttributeRange range); @Override Color valueToColor(Number value);  }
@Test public void testRed() { AttributeRange range = new AttributeRange(1900, 1975); RainbowColorMap instance = new RainbowColorMap(range); Color result = instance.valueToColor(1900); String hex = ColorUtility.toHex(result); assertThat("#FF0000", is(equalTo(hex))); }
@Test public void testGreenish() { AttributeRange range = new AttributeRange(1900, 1975); RainbowColorMap instance = new RainbowColorMap(range); Color result = instance.valueToColor(1933); String hex = ColorUtility.toHex(result); assertThat("#05FF00", is(equalTo(hex))); }
@Test public void testBlueish() { AttributeRange range = new AttributeRange(1900, 1975); RainbowColorMap instance = new RainbowColorMap(range); Color result = instance.valueToColor(1967); String hex = ColorUtility.toHex(result); assertThat("#0400FF", is(equalTo(hex))); }
@Test public void testPurple() { AttributeRange range = new AttributeRange(1900, 1975); RainbowColorMap instance = new RainbowColorMap(range); Color result = instance.valueToColor(1975); String hex = ColorUtility.toHex(result); assertThat("#7F00FF", is(equalTo(hex))); }
@Test public void testSingleDate() { AttributeRange range = new AttributeRange(1900, 1900); RainbowColorMap instance = new RainbowColorMap(range); Color result = instance.valueToColor(1900); String hex = ColorUtility.toHex(result); assertThat("#FF0000", is(equalTo(hex))); }