mirror of
https://github.com/eclipse-sailing-analytics/sailing-analytics.git
synced 2026-10-04 03:13:49 +00:00
fixed little colormap bug and added a test to ensure the calculation of 100 distinct colors
This commit is contained in:
1 parent
09ce87180c
commit
5c23c6121b
2 files changed
+30
-2
No files matched your search
@@ -0,0 +1,28 @@
|
|||||||
|
package com.sap.sailing.gwt.ui.test;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import com.sap.sailing.gwt.ui.client.ColorMap;
|
||||||
|
|
||||||
|
public class ColorMapTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testHundredDistinctColors() {
|
||||||
|
ColorMap<Integer> colorMap = new ColorMap<Integer>();
|
||||||
|
List<String> existingColors = new ArrayList<String>();
|
||||||
|
int amountOfDistinctColorsToCreate = 100;
|
||||||
|
for(int i = 1; i <= amountOfDistinctColorsToCreate; i++) {
|
||||||
|
String colorByID = colorMap.getColorByID(i);
|
||||||
|
if(!existingColors.contains(colorByID)) {
|
||||||
|
existingColors.add(colorByID);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
assertEquals(amountOfDistinctColorsToCreate, existingColors.size());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
+2
-2
@@ -27,7 +27,7 @@ public class ColorMap<T> {
|
|||||||
baseColors[3] = new HSVColor(120.0f, 1.0f, 1.0f); // Green
|
baseColors[3] = new HSVColor(120.0f, 1.0f, 1.0f); // Green
|
||||||
baseColors[4] = new HSVColor(180.0f, 1.0f, 1.0f); // Cyan
|
baseColors[4] = new HSVColor(180.0f, 1.0f, 1.0f); // Cyan
|
||||||
baseColors[5] = new HSVColor(240.0f, 1.0f, 1.0f); // Blue
|
baseColors[5] = new HSVColor(240.0f, 1.0f, 1.0f); // Blue
|
||||||
baseColors[6] = new HSVColor(240.0f, 1.0f, 1.0f); // Pink
|
baseColors[6] = new HSVColor(270.0f, 1.0f, 1.0f); // Pink
|
||||||
baseColors[7] = new HSVColor(300.0f, 1.0f, 1.0f); // Magenta
|
baseColors[7] = new HSVColor(300.0f, 1.0f, 1.0f); // Magenta
|
||||||
|
|
||||||
idColor = new HashMap<T, String>();
|
idColor = new HashMap<T, String>();
|
||||||
@@ -59,7 +59,7 @@ public class ColorMap<T> {
|
|||||||
private String createHexColor(int index) {
|
private String createHexColor(int index) {
|
||||||
int baseColorCount = baseColors.length;
|
int baseColorCount = baseColors.length;
|
||||||
int baseColorsIndex = index % baseColorCount;
|
int baseColorsIndex = index % baseColorCount;
|
||||||
float brightnessDecrease = Math.round(index / baseColorCount) * 0.75f;
|
float brightnessDecrease = Math.round(index / baseColorCount) * 0.05f;
|
||||||
float saturationDecrease = Math.round(index / baseColorCount) * 0.05f;
|
float saturationDecrease = Math.round(index / baseColorCount) * 0.05f;
|
||||||
HSVColor hsvColor = baseColors[baseColorsIndex];
|
HSVColor hsvColor = baseColors[baseColorsIndex];
|
||||||
HSVColor newColor = new HSVColor(hsvColor.getHue(), hsvColor.getSaturation() - saturationDecrease,
|
HSVColor newColor = new HSVColor(hsvColor.getHue(), hsvColor.getSaturation() - saturationDecrease,
|
||||||
|
|||||||
Reference in new issue
Block a user