<commit_before>package edu.berkeley.guir.prefuse.util;

import java.awt.Color;
import java.awt.Paint;

/**
 * A color map provides a mapping from numeric values to specific colors.
 * This useful for assigning colors to visualized items. The numeric values
 * may represent different categories (i.e. nominal variables) or run along
 * a spectrum of values (i.e. quantitative variables).
 *
 * @version 1.0
 * @author <a href="http://jheer.org"><NAME></a> prefuse(AT)jheer.org
 */
public class ColorMap {

    /**
     * The default length of a color map array if its size
     * is not otherwise specified.
     */
    public static final int DEFAULT_MAP_SIZE = 64;
    
    private Paint colorMap[];
    private double minValue, maxValue;
    
    /**
     * Creates a new ColorMap instance using the given internal color map
     * array and minimum and maximum index values.
     * @param map a Paint array constituing the color map
     * @param min the minimum value in the color map
     * @param max the maximum value in the color map
     */
    public ColorMap(Paint[] map, double min, double max) {
        colorMap = map;
        minValue = min;
        maxValue = max;
    } //
    
    /**
     * Returns the color associated with the given value. If the value
     * is outside the range defined by this map's minimum or maximum
     * values, a saturated value is returned (i.e. the first entry
     * in the color map for values below the minimum, the last enty
     * for value above the maximum).
     * @param val the value for which to retrieve the corresponding color
     * @return the color (as a Paint instance) corresponding the given value
     */
    public Paint getColor(double val) {
        if ( val < minValue ) {
            return colorMap[0];
        } else if ( val > maxValue ) {
            return colorMap[colorMap.length-1];
        } else {
            int idx = (int)Math.round((colorMap.length-1) *
                          (val-minValue)/(maxValue-minValue));
            return colorMap[idx];
        }
    } //

    /**
     * Sets the internal color map, an array of Paint values.
     * @return Returns the colormap.
     */
    public Paint[] getColorMap() {
        return colorMap;
    } //

    /**
     * Sets the internal color map, an array of Paint values.
     * @param colorMap The new colormap.
     */
    public void setColorMap(Paint[] colorMap) {
        this.colorMap = colorMap;
    } //

    /**
     * Gets the maximum value that corresponds to the last
     * color in the color map.
     * @return Returns the max index value into the colormap.
     */
    public double getMaxValue() {
        return maxValue;
    } //

    /**
     * Sets the maximum value that corresponds to the last
     * color in the color map.
     * @param maxValue The max index value to set.
     */
    public void setMaxValue(double maxValue) {
        this.maxValue = maxValue;
    } //

    /**
     * Sets the minimum value that corresponds to the first
     * color in the color map.
     * @return Returns the min index value.
     */
    public double getMinValue() {
        return minValue;
    } //

    /**
     * Gets the minimum value that corresponds to the first
     * color in the color map.
     * @param minValue The min index value to set.
     */
    public void setMinValue(double minValue) {
        this.minValue = minValue;
    } //

    /**
     * Returns a color map array of default size that ranges from black to
     * white through shades of gray.
     * @return the color map array
     */
    public static Paint[] getGrayscaleMap() {
        return getGrayscaleMap(DEFAULT_MAP_SIZE);
    } //
    
    /**
     * /**
     * Returns a color map array of specified size that ranges from black to
     * white through shades of gray.
     * @param size the size of the color map array
     * @return the color map array
     */
    public static Paint[] getGrayscaleMap(int size) {
        Paint[] cm = new Paint[size];
        for ( int i=0; i<size; i++ ) {
            float g = ((float)i)/(size-1);
            cm[i] = ColorLib.getColor(g,g,g,1.f);
        }
        return cm;
    } //
    
    /**
     * Returns a color map array of default size that ranges from one
     * given color to the other.
     * @param c1 the initial color in the color map
     * @param c2 the final color in the color map
     * @return the color map array
     */
    public static Paint[] getInterpolatedMap(Color c1, Color c2) {
        return getInterpolatedMap(DEFAULT_MAP_SIZE, c1, c2);
    } //
    
    /**
     * Returns a color map array of given size that ranges from one
     * given color to the other.
     * @param size the size of the color map array
     * @param c1 the initial color in the color map
     * @param c2 the final color in the color map
     * @return the color map array
     */
    public static Paint[] getInterpolatedMap(int size, Color c1, Color c2) {
        Paint[] cm = new Paint[size];
        for ( int i=0; i<size; i++ ) {
            float f = ((float)i)/(size-1);
            cm[i] = ColorLib.getIntermediateColor(c1,c2,f);
        }
        return cm;
    } //
    
    /**
     * Returns a color map array of default size that cycles through
     * the hues of the HSB (Hue/Saturation/Brightness) color space at
     * full saturation and brightness.
     * @return the color map array
     */
    public static Paint[] getHSBMap() {
        return getHSBMap(DEFAULT_MAP_SIZE, 1.f, 1.f);
    } //
    
    /**
     * Returns a color map array of given size that cycles through
     * the hues of the HSB (Hue/Saturation/Brightness) color space.
     * @param size the size of the color map array
     * @param s the saturation value to use
     * @param b the brightness value to use
     * @return the color map array
     */
    public static Paint[] getHSBMap(int size, float s, float b) {
        Paint[] cm = new Paint[size];
        for ( int i=0; i<size; i++ ) {
            float h = ((float)i)/(size-1);
            cm[i] = ColorLib.getColor(Color.HSBtoRGB(h,s,b));
        }
        return cm;
    } //
    
    /**
     * Returns a color map of default size that moves from black to
     * red to yellow to white.
     * @return the color map array
     */
    public static Paint[] getHotMap() {
        return getHotMap(DEFAULT_MAP_SIZE);
    } //
    
    /**
     * Returns a color map that moves from black to red to yellow
     * to white.
     * @param size the size of the color map array
     * @return the color map array
     */
    public static Paint[] getHotMap(int size) {
        Paint[] cm = new Paint[size];
        for ( int i=0; i<size; i++ ) {
            int n = (3*size)/8;
            float r = ( i<n ? ((float)(i+1))/n : 1.f );
            float g = ( i<n ? 0.f : ( i<2*n ? ((float)(i-n))/n : 1.f ));
            float b = ( i<2*n ? 0.f : ((float)(i-2*n))/(size-2*n) );
            cm[i] = ColorLib.getColor(r,g,b,1.0f);
        }
        return cm;
    } //
    
    /**
     * Returns a color map array of default size that uses a "cool",
     * blue-heavy color scheme.
     * @return the color map array
     */
    public static Paint[] getCoolMap() {
        return getCoolMap(DEFAULT_MAP_SIZE);
    } //
    
    /**
     * Returns a color map array that uses a "cool",
     * blue-heavy color scheme.
     * @param size the size of the color map array
     * @return the color map array
     */
    public static Paint[] getCoolMap(int size) {
        Paint[] cm = new Paint[size];
        for( int i=0; i<size; i++ ) {
            float r = ((float)i) / Math.max(size-1,1.f);
            cm[i] = ColorLib.getColor(r,1-r,1.f,1.f);
        }
        return cm;
    } //
    
} // end of class ColorMap
<commit_msg>Added categorical color map.<commit_after>package edu.berkeley.guir.prefuse.util;

import java.awt.Color;
import java.awt.Paint;

/**
 * A color map provides a mapping from numeric values to specific colors.
 * This useful for assigning colors to visualized items. The numeric values
 * may represent different categories (i.e. nominal variables) or run along
 * a spectrum of values (i.e. quantitative variables).
 *
 * @version 1.0
 * @author <a href="http://jheer.org"><NAME></a> prefuse(AT)jheer.org
 */
public class ColorMap {

	/**
	 * Default palette of category hues.
	 */
	public static final float[] CATEGORY_HUES = {
		0f, 1f/12f, 1f/6f, 5f/24f, 1f/3f, 1f/2f, 2f/3f, 3f/4f, 5f/6f, 11f/12f
	};
	
    /**
     * The default length of a color map array if its size
     * is not otherwise specified.
     */
    public static final int DEFAULT_MAP_SIZE = 64;
    
    private Paint colorMap[];
    private double minValue, maxValue;
    
    /**
     * Creates a new ColorMap instance using the given internal color map
     * array and minimum and maximum index values.
     * @param map a Paint array constituing the color map
     * @param min the minimum value in the color map
     * @param max the maximum value in the color map
     */
    public ColorMap(Paint[] map, double min, double max) {
        colorMap = map;
        minValue = min;
        maxValue = max;
    } //
    
    /**
     * Returns the color associated with the given value. If the value
     * is outside the range defined by this map's minimum or maximum
     * values, a saturated value is returned (i.e. the first entry
     * in the color map for values below the minimum, the last enty
     * for value above the maximum).
     * @param val the value for which to retrieve the corresponding color
     * @return the color (as a Paint instance) corresponding the given value
     */
    public Paint getColor(double val) {
        if ( val < minValue ) {
            return colorMap[0];
        } else if ( val > maxValue ) {
            return colorMap[colorMap.length-1];
        } else {
            int idx = (int)Math.round((colorMap.length-1) *
                          (val-minValue)/(maxValue-minValue));
            return colorMap[idx];
        }
    } //

    /**
     * Sets the internal color map, an array of Paint values.
     * @return Returns the colormap.
     */
    public Paint[] getColorMap() {
        return colorMap;
    } //

    /**
     * Sets the internal color map, an array of Paint values.
     * @param colorMap The new colormap.
     */
    public void setColorMap(Paint[] colorMap) {
        this.colorMap = colorMap;
    } //

    /**
     * Gets the maximum value that corresponds to the last
     * color in the color map.
     * @return Returns the max index value into the colormap.
     */
    public double getMaxValue() {
        return maxValue;
    } //

    /**
     * Sets the maximum value that corresponds to the last
     * color in the color map.
     * @param maxValue The max index value to set.
     */
    public void setMaxValue(double maxValue) {
        this.maxValue = maxValue;
    } //

    /**
     * Sets the minimum value that corresponds to the first
     * color in the color map.
     * @return Returns the min index value.
     */
    public double getMinValue() {
        return minValue;
    } //

    /**
     * Gets the minimum value that corresponds to the first
     * color in the color map.
     * @param minValue The min index value to set.
     */
    public void setMinValue(double minValue) {
        this.minValue = minValue;
    } //

    /**
     * Returns a color map array of default size that ranges from black to
     * white through shades of gray.
     * @return the color map array
     */
    public static Paint[] getGrayscaleMap() {
        return getGrayscaleMap(DEFAULT_MAP_SIZE);
    } //
    
    /**
     * /**
     * Returns a color map array of specified size that ranges from black to
     * white through shades of gray.
     * @param size the size of the color map array
     * @return the color map array
     */
    public static Paint[] getGrayscaleMap(int size) {
        Paint[] cm = new Paint[size];
        for ( int i=0; i<size; i++ ) {
            float g = ((float)i)/(size-1);
            cm[i] = ColorLib.getColor(g,g,g,1.f);
        }
        return cm;
    } //
    
    /**
     * Returns a color map array of default size that ranges from one
     * given color to the other.
     * @param c1 the initial color in the color map
     * @param c2 the final color in the color map
     * @return the color map array
     */
    public static Paint[] getInterpolatedMap(Color c1, Color c2) {
        return getInterpolatedMap(DEFAULT_MAP_SIZE, c1, c2);
    } //
    
    /**
     * Returns a color map array of given size that ranges from one
     * given color to the other.
     * @param size the size of the color map array
     * @param c1 the initial color in the color map
     * @param c2 the final color in the color map
     * @return the color map array
     */
    public static Paint[] getInterpolatedMap(int size, Color c1, Color c2) {
        Paint[] cm = new Paint[size];
        for ( int i=0; i<size; i++ ) {
            float f = ((float)i)/(size-1);
            cm[i] = ColorLib.getIntermediateColor(c1,c2,f);
        }
        return cm;
    } //
    
    /**
     * Returns a color map array of default size that cycles through
     * the hues of the HSB (Hue/Saturation/Brightness) color space at
     * full saturation and brightness.
     * @return the color map array
     */
    public static Paint[] getHSBMap() {
        return getHSBMap(DEFAULT_MAP_SIZE, 1.f, 1.f);
    } //
    
    /**
     * Returns a color map array of given size that cycles through
     * the hues of the HSB (Hue/Saturation/Brightness) color space.
     * @param size the size of the color map array
     * @param s the saturation value to use
     * @param b the brightness value to use
     * @return the color map array
     */
    public static Paint[] getHSBMap(int size, float s, float b) {
        Paint[] cm = new Paint[size];
        for ( int i=0; i<size; i++ ) {
            float h = ((float)i)/(size-1);
            cm[i] = ColorLib.getColor(Color.HSBtoRGB(h,s,b));
        }
        return cm;
    } //
    
    /**
     * Returns a color map array of given size tries to provide colors
     * appropriate as category labels. There are 12 basic color hues
     * (red, orange, yellow, olive, green, cyan, blue, purple, magenta,
     * and pink). If the size is greater than 12, these colors will be
     * continually repeated, but with varying saturation levels.
     * @param size the size of the color map array
     */
    public static Paint[] getCategoryMap(int size) {
    	return getCategoryMap(size, 1.f, 0.4f, 1.f, 255);
    } //
    
    /**
     * Returns a color map array of given size tries to provide colors
     * appropriate as category labels. There are 12 basic color hues
     * (red, orange, yellow, olive, green, cyan, blue, purple, magenta,
     * and pink). If the size is greater than 12, these colors will be
     * continually repeated, but with varying saturation levels.
     * @param size the size of the color map array
     * @param s1 the initial saturation to use
     * @param s2 the final (most distant) saturation to use
     * @param b the brightness value to use
     * @param a the alpha value to use
     */
    public static Paint[] getCategoryMap(int size, 
    		float s1, float s2, float b, int a)
    {
    	Paint[] cm = new Paint[size];
    	float s = s1;
    	for ( int i=0; i<size; i++ ) {
    		int j = i % CATEGORY_HUES.length;
    		if ( j == 0 )
    			s = s1 + (((float)i)/size)*(s2-s1);
    		int color = ((0xFF & a)<<24) | 
    					 (0x00FFFFFF & Color.HSBtoRGB(CATEGORY_HUES[j],s,b));
    		cm[i] = ColorLib.getColor(color);
    	}
    	return cm;
    } //
    
    /**
     * Returns a color map of default size that moves from black to
     * red to yellow to white.
     * @return the color map array
     */
    public static Paint[] getHotMap() {
        return getHotMap(DEFAULT_MAP_SIZE);
    } //
    
    /**
     * Returns a color map that moves from black to red to yellow
     * to white.
     * @param size the size of the color map array
     * @return the color map array
     */
    public static Paint[] getHotMap(int size) {
        Paint[] cm = new Paint[size];
        for ( int i=0; i<size; i++ ) {
            int n = (3*size)/8;
            float r = ( i<n ? ((float)(i+1))/n : 1.f );
            float g = ( i<n ? 0.f : ( i<2*n ? ((float)(i-n))/n : 1.f ));
            float b = ( i<2*n ? 0.f : ((float)(i-2*n))/(size-2*n) );
            cm[i] = ColorLib.getColor(r,g,b,1.0f);
        }
        return cm;
    } //
    
    /**
     * Returns a color map array of default size that uses a "cool",
     * blue-heavy color scheme.
     * @return the color map array
     */
    public static Paint[] getCoolMap() {
        return getCoolMap(DEFAULT_MAP_SIZE);
    } //
    
    /**
     * Returns a color map array that uses a "cool",
     * blue-heavy color scheme.
     * @param size the size of the color map array
     * @return the color map array
     */
    public static Paint[] getCoolMap(int size) {
        Paint[] cm = new Paint[size];
        for( int i=0; i<size; i++ ) {
            float r = ((float)i) / Math.max(size-1,1.f);
            cm[i] = ColorLib.getColor(r,1-r,1.f,1.f);
        }
        return cm;
    } //
    
} // end of class ColorMap

{'fraction_non_alphanumeric': 0.1031997693859902, 'fraction_numerical': 0.008648025367541078, 'mean_word_length': 2.0140747176368374, 'pattern_counts': {'":': 0, '<': 32, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2005885', 'n_tokens_mistral': 5354, 'n_tokens_neox': 5142, 'n_words': 1971}