package yi.stat.graph;

public class Graph {
  /**
   * Draw a gray level graph to demonstrate the data value.
   *
   * For example, data {200, 400, 800, 400} will be drawn as gray level
   * {63, 127, 255, 127} if the minimum = 1 and the maximum = 800
   * @param data the data to be graph-ed
   * @param minimum the minimum of the data
   * @param maximum the maximum of the data
   * @return the gray level image
   */
  public static int[] grayGraph(int[] data, int minimum, int maximum) {
    int[] normalized = yi.stat.Util.normalize(data, minimum, maximum, 255);
    return yi.util.ImageUtil.makeNewImageFromGray(normalized);
  }

  /**
   * Draw a gray level graph to demonstrate the data value.  See #grayGraph for
   * more details
   * @param data the data to be graph-ed
   * @return the gray level image
   */
  public static int[] grayGraph(int[] data) {
    int minimum = yi.stat.Util.minimum(data);
    int maximum = yi.stat.Util.maximum(data);
    return grayGraph(data, minimum, maximum);
  }

  /**
   * Draw a color graph to demonstrate the data value.  The different data will
   * be represented by different hue.
   *
   * For example, data {200, 400, 800, 1} will be will first normalized to
   * {89, 179, 359, 0} if the minimum = 1 and the maximum = 800 and then those
   * value will be used as the Hue value
   * @param data the data to be graph-ed
   * @param minimum the minimum of the data
   * @param maximum the maximum of the data
   * @return the hue level image
   */
  public static int[] hueGraph(int[] data, int minimum, int maximum) {
    int[] normalized = yi.stat.Util.normalize(data, minimum, maximum, 359);
    for (int i=0; i<data.length; i++) {
      normalized[i] = java.awt.Color.HSBtoRGB(normalized[i], 1, 1);
    }
    return normalized;
  }

}