Class ColorMap.Gradient1D<T>

Object
ColorMap<T>
ColorMap.Gradient<T>
Gradient1D<T>
Type Parameters:
T - type of color object: String or MeshLambertMaterial for GWT and Color for JRE
Direct Known Subclasses:
ColorMap.Hue, ColorMap3D.Gradient1D, ColorMapCSS.Gradient1D
Enclosing class:
ColorMap<T>

public abstract static class ColorMap.Gradient1D<T> extends ColorMap.Gradient<T>
One dimensional color gradient spanning two or more colors
See Also:
  • Nested Class Summary

  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected T[]
    Reference to pre-allocated gradient colors.
    protected double
    Helper variable to make the mapping from a range of data values to indices of the gradient array more efficient: map=nBins/(max-min), where max maximum data value to be mapped.
    protected double
    Minimum data value.
    protected final int
    Number of colors in the gradient: nGradient+1.
    protected final int
    The index of the trait that this gradient refers to (or -1 if not applicable).

    Fields inherited from class ColorMap

    INV255
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    protected
    Gradient1D(Color[] colors, int trait, T[] gradient)
    For internal use only.
    protected
    Gradient1D(T[] gradient)
    For internal use only.
    protected
    Gradient1D(T[] gradient, int trait)
    For internal use only.
  • Method Summary

    Modifier and Type
    Method
    Description
    protected int
    binOf(double value)
    Utility method to calculate the index of the gradient color that corresponds to value.
    void
    setColor(double value, Color color)
    Assign a new color to the gradient for value.
    void
    setColor(double value, Color color, int alpha)
    Assign a new color to the gradient for value with transparency alpha.
    void
    setGradient(Color[] colors)
    Sets the gradient to span the colors in the array colors.
    void
    setGradient(Color[] colors, int trait)
    Sets the gradient for the trait with index trait to span the colors in the array colors.
    void
    setRange(double min, double max)
    Sets the range of values spanned by the gradient to [min,max].
    translate(double data)
    Translate the double value data to a color gradient.
    boolean
    translate(double[][] data1, double[][] data2, T[] color)
    Translate the data1 and data2 arrays of double[] multi-trait values to colors and store the results in the color array.
    boolean
    translate(double[][] data, T[] color)
    Translate the data array of double[] multi-trait values to colors and store the results in the color array.
    boolean
    translate(double[] data, T[] color)
    Translate the data array of double values to colors and store the results in the color array.

    Methods inherited from class ColorMap.Gradient

    interpolateColors, interpolateColors

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • gradient

      protected T[] gradient
      Reference to pre-allocated gradient colors.
    • nGradient

      protected final int nGradient
      Number of colors in the gradient: nGradient+1.
    • min

      protected double min
      Minimum data value. This value is mapped onto color gradient[0].
    • map

      protected double map
      Helper variable to make the mapping from a range of data values to indices of the gradient array more efficient: map=nBins/(max-min), where max maximum data value to be mapped.
    • trait

      protected final int trait
      The index of the trait that this gradient refers to (or -1 if not applicable).
  • Constructor Details

    • Gradient1D

      protected Gradient1D(Color[] colors, int trait, T[] gradient)
      For internal use only. Construct color gradient running through all the colors in the array colors for the trait with index trait (or -1 if not applicable). The gradient colors of type T are stored in gradient. The number of interpolated intermediate colors between two subsequent entries in colors is (gradient.length-1)/(N-1), where N is the number of colors in colors. The default range for mapping data values onto the color gradient is [0.0, 1.0].
      Parameters:
      colors - the equally spaced reference colors of the gradient
      trait - the trait index for the color gradient
      gradient - the array to store the gradient colors
      See Also:
    • Gradient1D

      protected Gradient1D(T[] gradient)
      For internal use only. Initializes gradient based on the supplied array gradient of type T.
      Parameters:
      gradient - the array to store the gradient colors
    • Gradient1D

      protected Gradient1D(T[] gradient, int trait)
      For internal use only. Initializes gradient based on the supplied array gradient of type T for trait with index trait. The default range for mapping data values onto the color gradient is [0.0, 1.0].
      Parameters:
      gradient - the array to store the gradient colors
      trait - the trait index for the color gradient
      See Also:
  • Method Details

    • setColor

      public void setColor(double value, Color color)
      Assign a new color to the gradient for value.
      Parameters:
      value - the value of the color
      color - the new color for value
    • setColor

      public void setColor(double value, Color color, int alpha)
      Assign a new color to the gradient for value with transparency alpha.

      Note: the transparency of the supplied color is always honoured but overruled if alpha != 255.

      Parameters:
      value - the value of the color
      color - the new color for value
      alpha - the transparency of the new color
    • binOf

      protected int binOf(double value)
      Utility method to calculate the index of the gradient color that corresponds to value. Returns -1 if value is invalid or lies outside the range of the gradient.
      Parameters:
      value - the value to convert to a bin index of the gradient
      Returns:
      the index of the bin or -1
    • setGradient

      public void setGradient(Color[] colors)
      Sets the gradient to span the colors in the array colors.
      Parameters:
      colors - the array of colors for the gradient
    • setGradient

      public void setGradient(Color[] colors, int trait)
      Sets the gradient for the trait with index trait to span the colors in the array colors.
      Parameters:
      colors - the array of colors for the gradient
      trait - the trait index for the color gradient
    • setRange

      public void setRange(double min, double max)
      Sets the range of values spanned by the gradient to [min,max].
      Parameters:
      min - the minimum value of the gradient
      max - the maximum value of the gradient
    • translate

      public T translate(double data)
      Description copied from class: ColorMap.Gradient
      Translate the double value data to a color gradient. The type of object returned depends on the implementation.
      Overrides:
      translate in class ColorMap.Gradient<T>
      Parameters:
      data - the double value to convert to a color
      Returns:
      the color object
    • translate

      public boolean translate(double[] data, T[] color)
      Translate the data array of double values to colors and store the results in the color array. The type of the color array depends on the implementation.

      Note: whether data refers to a single or multiple traits is up to the implementation to decide. For example, CXPopulation stores multiple traits in a linear array.

      Implementation: For performance reasons no validity checks on data. In particular, all data entries must lie inside the range for mapping data values.

      Overrides:
      translate in class ColorMap<T>
      Parameters:
      data - the double[] array to convert to colors
      color - the array for the resulting colors
      Returns:
      true if translation successful
    • translate

      public boolean translate(double[][] data, T[] color)
      Translate the data array of double[] multi-trait values to colors and store the results in the color array. The type of the color array depends on the implementation.

      Implementation:

      1. Each entry in data is assumed to be one dimensional (only first entry used) and converted to the corresponding gradient color and returned in the color array.
      2. For performance reasons no validity checks on data. In particular, all data entries must lie inside the range for mapping data values.
      Overrides:
      translate in class ColorMap<T>
      Parameters:
      data - the double[][] array to convert to colors
      color - the array for the resulting colors
      Returns:
      true if translation successful
      See Also:
    • translate

      public boolean translate(double[][] data1, double[][] data2, T[] color)
      Translate the data1 and data2 arrays of double[] multi-trait values to colors and store the results in the color array. The type of the color array depends on the implementation.

      For example, frequencies and fitnesses, say data1 and data2, respectively, yield the average fitness as data1·data2 (dot product), which then gets converted to a color.

      Overrides:
      translate in class ColorMap<T>
      Parameters:
      data1 - the first double[] array to convert to colors
      data2 - the second double[] array to convert to colors
      color - the array for the resulting colors
      Returns:
      true if translation successful
      See Also: