Skip to content

Instantly share code, notes, and snippets.

@roloenusa
Last active April 25, 2019 18:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save roloenusa/19b9ba9c563773e284ba4dd873394b2a to your computer and use it in GitHub Desktop.
Save roloenusa/19b9ba9c563773e284ba4dd873394b2a to your computer and use it in GitHub Desktop.
Normalize and Heatmap formulas.
class Utilities
{
/**
* Normalize the data point between 0 - 1. The data is weighted to prop up
* smaller numbers to provide a more interesting spread.
* @param The normalized data point value.
* @return The weighted value.
*/
public static Float normalize(float point, int max, int min)
{
Float value = (point - min) / (max - min);
// Apply some weights to make it more interesting.
if (value < .2)
value *= 2;
else if (value < .4)
value *= (float)1.7;
else if (value < .6)
value *= (float)1.3;
else if (value < .8)
value *= (float)1.2;
return value;
}
/**
* Gets the color value for a normalized data point.
* @param The current data point value.
* @param The maximum value.
* @param The minimum value.
* @return The color to assign.
*/
private Color getHeatMapColor(Float value)
{
float ratio = 2 * value;
Float r = Math.max(0, 255 * (ratio -1));
Float b = Math.max(0, 255 * (1-ratio));
Float g = 255 - b - r;
Color color = new Color(r.intValue(), g.intValue(), b.intValue());
return color;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment