Browse Source

nicer colors for statistics

Fabio Arnold 10 years ago
parent
commit
2ce3923744

+ 6 - 44
src/de/tudarmstadt/informatik/hostage/ui2/fragment/StatisticsFragment.java

@@ -38,6 +38,7 @@ import de.tudarmstadt.informatik.hostage.logging.UglyDbHelper;
 import de.tudarmstadt.informatik.hostage.ui.LogFilter;
 import de.tudarmstadt.informatik.hostage.ui2.adapter.StatisticListAdapter;
 import de.tudarmstadt.informatik.hostage.ui2.dialog.ChecklistDialog;
+import de.tudarmstadt.informatik.hostage.ui2.helper.ColorSequenceGenerator;
 import de.tudarmstadt.informatik.hostage.ui2.model.PlotComparisonItem;
 import de.tudarmstadt.informatik.hostage.ui2.popup.AbstractPopup;
 import de.tudarmstadt.informatik.hostage.ui2.popup.AbstractPopupItem;
@@ -935,50 +936,11 @@ public class StatisticsFragment extends Fragment implements ChecklistDialog.Chec
 
 
     public int getOtherColor(){
-        return Color.argb(255,0,0,0);
-    }
-
-     public ArrayList<Integer> getColorList(){
-        if (this.colorList == null){
-            this.colorList = new ArrayList<Integer>();
-            for (int i =0; i < 255; i++){
-                Integer color = this.generateColorForIndex(i);
-                this.colorList.add(color);
-            }
-        }
-        return this.colorList;
-    }
-
-    public Integer getColor(int index){
-        if (this.colorList == null) this.colorList = new ArrayList<Integer>();
-        if (index >= this.colorList.size()) {
-            for (int i = this.colorList.size(); i<= index; i++){
-                Integer color = this.generateColorForIndex(i);
-                this.colorList.add(color);
-            }
-            return this.generateColorForIndex(index);
-        }
-        return this.colorList.get(index);
-    }
-
-    public Integer generateColorForIndex(int index){
-        int r[] = new int[]{0,0,1,1,0,1,1};
-        int g[] = new int[]{0,1,0,0,1,1,1};
-        int b[] = new int[]{1,0,0,1,1,0,1};
-
-        int a = (index / 7);
-        int n = index % 7;
-
-        int q = Math.max(1, 2 * (a / 7));
-        int multiplier = 16 / (q);
-
-        int sub = (Math.min(((Math.max(0,(a ))) * multiplier), 16));
-
-        int R = Math.max( (r[n] * 255) - sub, 0);
-        int G = Math.max( (g[n] * 255) - sub, 0);
-        int B = Math.max( (b[n] * 255) - sub, 0);
-
-        return Color.argb(255,R,G,B);
+        return Color.argb(255, 80, 80, 80); // grey
+	}
+	
+    public Integer getColor(int index) {
+		return ColorSequenceGenerator.getColorForIndex(index);
     }
 
 

+ 27 - 0
src/de/tudarmstadt/informatik/hostage/ui2/helper/ColorSequenceGenerator.java

@@ -0,0 +1,27 @@
+package de.tudarmstadt.informatik.hostage.ui2.helper;
+
+import android.graphics.Color;
+
+/**
+ * Idea from http://ridiculousfish.com/blog/posts/colors.html
+ * Created by Fabio Arnold on 25.02.14.
+ */
+public class ColorSequenceGenerator {
+	private static final int BIT_COUNT = 31; // sadly there is no unsigned type in java
+	public static int getColorForIndex(int index) {
+		int reverseIndex = 0;
+		for (int i = 0; i  < BIT_COUNT; i++) {
+			reverseIndex = (reverseIndex << 1) | (index & 1);
+			index >>= 1;
+		}
+		float hue = ((float)reverseIndex / (float)(1 << BIT_COUNT) + 0.6f) % 1.0f;
+
+
+		float[] hsv = new float[3];
+		hsv[0] = 360.0f * hue;
+		hsv[1] = 0.7f; // not fully saturated
+		hsv[2] = 1.0f;
+
+		return Color.HSVToColor(hsv);
+	}
+}