Skip to content

Commit 245e798

Browse files
authored
Hash entry method ID to select default colors (#144)
Previously, the default color mapping used in most tools resulted in consecutive entry methods having very similar colors. Now, it uses a hash of the entry method ID, resulting in an increased likelihood of perceptible difference between consecutive entry methods.
1 parent 831b63a commit 245e798

File tree

2 files changed

+17
-25
lines changed

2 files changed

+17
-25
lines changed

src/projections/Tools/Timeline/EntryMethodObject.java

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import projections.analysis.ObjectId;
2626
import projections.analysis.PackTime;
2727
import projections.analysis.TimelineEvent;
28+
import projections.gui.ColorManager;
2829
import projections.gui.MainWindow;
2930
import projections.gui.U;
3031
import projections.misc.MiscUtil;
@@ -1063,21 +1064,7 @@ private Paint determineColor() {
10631064
color += (extraFields.memoryUsage * 6121) % 5953;
10641065
}
10651066

1066-
// Should range from 0.0 to 2.0
1067-
float h2 = ((color+512) % 512) / 256.0f;
1068-
// Should range from 0.0 to 1.0
1069-
float h = ((color+512) % 512) / 512.0f;
1070-
1071-
1072-
1073-
float s = 1.0f; // Should be 1.0
1074-
1075-
float b = 1.0f; // Should be 0.5 or 1.0
1076-
1077-
if(h2 > 1.0)
1078-
b = 0.6f;
1079-
1080-
colToSave = Color.getHSBColor(h, s, b);
1067+
colToSave = ColorManager.createFromLong(color);
10811068

10821069
}
10831070
if (colToSave == null) {

src/projections/gui/ColorManager.java

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -193,21 +193,26 @@ public void saveColors(TreeMap<Integer,Color> overrideMapping)
193193
// }
194194
// }
195195

196-
197-
198196
public static Color[] createColorMap(int numColors) {
199197
Color[] colors = new Color[numColors];
200-
float H = (float)1.0;
201-
float S = (float)1.0;
202-
float B = (float)1.0;
203-
float delta = (float)(1.0/numColors);
204-
for(int i=0; i<numColors; i++) {
205-
colors[i] = Color.getHSBColor(H, S, B);
206-
H -= delta;
207-
if(H < 0.0) { H = (float)1.0; }
198+
for (int i = 0; i < numColors; i++) {
199+
colors[i] = createFromLong((i * 251) % 5113);
208200
}
209201
return colors;
210202
}
203+
204+
public static Color createFromLong(long color) {
205+
// Should range from 0.0 to 1.0
206+
final float H = (color * 29 % 512) / 512.0f;
207+
208+
float S = (color % 1536) / 512.0f;
209+
S = (S < 1.0) ? 0.7f : 1.0f;
210+
211+
float B = (color % 1536) / 512.0f;
212+
B = (B < 2.0) ? 1.0f : 0.6f;
213+
214+
return Color.getHSBColor(H, S, B);
215+
}
211216

212217
public static Color[] createComplementaryColorMap(int numUserEntries) {
213218
if (numUserEntries>=2) {

0 commit comments

Comments
 (0)