Class NiceScale

java.lang.Object
edu.cnu.mdi.splot.plot.NiceScale

public class NiceScale extends Object
Utility for generating "nice" axis bounds and tick spacing.

Produces a tick spacing from the set {1, 2, 5}×10^n and expands the requested min/max to "nice" endpoints aligned to that spacing.

  • Constructor Summary

    Constructors
    Constructor
    Description
    NiceScale(double min, double max)
    Convenience constructor: defaults to 10 ticks including ends, not forced to include zero.
    NiceScale(double min, double max, int numTicks)
    Convenience constructor: not forced to include zero.
    NiceScale(double min, double max, int numTicks, boolean includeZero)
    Instantiates a new instance of the NiceScale class.
  • Method Summary

    Modifier and Type
    Method
    Description
    double
    Get the nice plot max (expanded and aligned).
    double
    Get the nice plot min (expanded and aligned).
    int
    Get the number of ticks (including the ends).
    int
    The actual number of ticks returned by getTicks().
    double[]
    Return the tick locations from niceMin to niceMax inclusive.
    double
    Get the tick spacing.
    void
    setMaxTicks(int maxTicks)
    Sets maximum number of tick marks we're comfortable with (including ends).
    void
    setMinMaxPoints(double min, double max)
    Sets the minimum and maximum data points for the axis.

    Methods inherited from class java.lang.Object

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

    • NiceScale

      public NiceScale(double min, double max)
      Convenience constructor: defaults to 10 ticks including ends, not forced to include zero.
      Parameters:
      min - minimum data value
      max - maximum data value
    • NiceScale

      public NiceScale(double min, double max, int numTicks)
      Convenience constructor: not forced to include zero.
      Parameters:
      min - minimum data value
      max - maximum data value
      numTicks - number of ticks including ends (min 2 recommended)
    • NiceScale

      public NiceScale(double min, double max, int numTicks, boolean includeZero)
      Instantiates a new instance of the NiceScale class.
      Parameters:
      min - the minimum data point on the axis
      max - the maximum data point on the axis
      numTicks - the number of ticks including the ends
      includeZero - if true, expand min/max so that 0 is included
  • Method Details

    • getTickSpacing

      public double getTickSpacing()
      Get the tick spacing.
      Returns:
      tick spacing
    • getNiceMin

      public double getNiceMin()
      Get the nice plot min (expanded and aligned).
      Returns:
      nice min
    • getNiceMax

      public double getNiceMax()
      Get the nice plot max (expanded and aligned).
      Returns:
      nice max
    • getNumTicks

      public int getNumTicks()
      Get the number of ticks (including the ends).
      Returns:
      number of ticks
    • setMinMaxPoints

      public void setMinMaxPoints(double min, double max)
      Sets the minimum and maximum data points for the axis. Recomputes tick spacing and nice endpoints.
      Parameters:
      min - minimum data value
      max - maximum data value
    • setMaxTicks

      public void setMaxTicks(int maxTicks)
      Sets maximum number of tick marks we're comfortable with (including ends). Recomputes tick spacing and nice endpoints.
      Parameters:
      maxTicks - maximum number of ticks (min 2)
    • getTicks

      public double[] getTicks()
      Return the tick locations from niceMin to niceMax inclusive.
      Returns:
      array of tick values (never null)
    • getTickCount

      public int getTickCount()
      The actual number of ticks returned by getTicks().
      Returns:
      tick count