Skip to content

Commit 7e87f18

Browse files
committed
fix color interpolation
1 parent 074bde9 commit 7e87f18

File tree

1 file changed

+16
-7
lines changed
  • EnrichmentMapPlugin/src/main/java/org/baderlab/csplugins/enrichmentmap/view/util

1 file changed

+16
-7
lines changed

EnrichmentMapPlugin/src/main/java/org/baderlab/csplugins/enrichmentmap/view/util/ColorUtil.java

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -62,15 +62,24 @@ public static Color getColor(
6262
final Color zeroColor,
6363
final Color upperColor
6464
) {
65-
final boolean hasZero = lowerBound < -EPSILON && upperBound > EPSILON && zeroColor != null;
66-
65+
boolean hasZero = lowerBound < -EPSILON && upperBound > EPSILON && zeroColor != null;
66+
6767
if (hasZero && value < EPSILON && value > -EPSILON)
6868
return zeroColor;
69-
70-
final Color color = value < 0.0 ? lowerColor : upperColor;
71-
float t = interpolate(value, lowerBound, upperBound);
72-
73-
return ColorUtil.interpolate(zeroColor, color, t);
69+
70+
var color = value < 0.0 ? lowerColor : upperColor;
71+
72+
// Linearly interpolate the value
73+
double f = value < 0.0 ?
74+
MathUtil.invLinearInterp(value, lowerBound, 0) : MathUtil.invLinearInterp(value, 0, upperBound);
75+
float t = (float) (value < 0.0 ? MathUtil.linearInterp(f, 0.0, 1.0) : MathUtil.linearInterp(f, 1.0, 0.0));
76+
77+
// Make sure it's between 0.0-1.0
78+
t = Math.max(0.0f, t);
79+
t = Math.min(1.0f, t);
80+
81+
Color c = ColorUtil.interpolate(zeroColor, color, t);
82+
return c;
7483
}
7584

7685
/**

0 commit comments

Comments
 (0)