Class AxisIntervals


  • public final class AxisIntervals
    extends Object
    Provides a utility for computing the intervals for labeling a coordinate axis in a legend or other graph.

    This class is used in many of the demonstration applications supplied with the Tinfour software library. For example, it is used to select intervals for legends in color-coded surface representations. It is used to label axes in trend-line graphs. And it is also used to pick contour intervals in contour-rendering applications.

    • Method Detail

      • getValue0

        public double getValue0()
        Gets the minimum value of the range used to specify the axis.
        Returns:
        a valid floating point value
      • getValue1

        public double getValue1()
        Gets the maximum value of the range used to specify the axis.
        Returns:
        a valid floating point value
      • isValue0Labeled

        public boolean isValue0Labeled()
        Indicates if value0 was included in the primary tic coordinates. This happens when value0 is an integral multiple of the primary interval.
        Returns:
        true if value0 is included in the tic coordinates; otherwise false
      • isValue1Labeled

        public boolean isValue1Labeled()
        Indicates if value1 was included in the primary tic coordinates. This happens when value1 is an integral multiple of the primary interval.
        Returns:
        true if value1 is included in the tic coordinates; otherwise false
      • getTicCoordinates

        public double[][] getTicCoordinates()
        Gets the coordinates for the tic marks to be added to the axis. The array turned may be of dimension one or two. If it is of dimension 1, only primary tic intervals are included. If it is of dimension 2, then secondary tic intervals are included. Note that the coordinates for the secondary tic marks do not overlap those of the primary intervals.
        Returns:
        a valid array of dimension one or two.
      • getLabelCoordinates

        public double[] getLabelCoordinates()
        Gets the coordinates for labels. This value is redundant with the primary tic coordinates/
        Returns:
        a valid array
      • getLabels

        public String[] getLabels()
        Gets formatted labels for the tic coordinates.
        Returns:
        a valid array
      • getLabelFormat

        public String getLabelFormat()
        Get a label format that is intended to be appropriate to the magnitude of the primary interval
        Returns:
        a valid Java format string
      • getCoordinateScale

        public double getCoordinateScale()
        Get a multiplicative factor for scaling coordinates to pixels.
        Returns:
        a valid floating point value
      • computeIntervals

        public static AxisIntervals computeIntervals​(double value0,
                                                     double value1,
                                                     int primaryMinIntervalInPixels,
                                                     int secondaryMinIntervalInPixels,
                                                     int sizeInPixels)
        Compute the intervals over a range of values. This method attempts to select the the finest real-valued intervals that map to a pixel scale larger than the specified limits and confirm to nice "human friendly" values.
        Parameters:
        value0 - the minimum value to be represented.
        value1 - the maximum value to be represented.
        primaryMinIntervalInPixels - the minimum spacing allowed for the primary interval
        secondaryMinIntervalInPixels - the minimum space allowed for the secondary interval
        sizeInPixels - the overall size of the area for labeling, i..e$#46; the length of a horizontal axis or the height of a vertical axis
        Returns:
        if successful, a valid instance; otherwise, a null.
      • computeIntervals

        public static AxisIntervals computeIntervals​(double value0,
                                                     double value1,
                                                     int primaryMinIntervalInPixels,
                                                     int secondaryMinIntervalInPixels,
                                                     int sizeInPixels,
                                                     boolean bracketValues)
        Compute the intervals over a range of values. This method attempts to select the the finest real-valued intervals that map to a pixel scale larger than the specified limits and confirm to nice "human friendly" values.
        Parameters:
        value0 - the minimum value to be represented.
        value1 - the maximum value to be represented.
        primaryMinIntervalInPixels - the minimum spacing allowed for the primary interval
        secondaryMinIntervalInPixels - the minimum space allowed for the secondary interval
        sizeInPixels - the overall size of the area for labeling, i..e$#46; the length of a horizontal axis or the height of a vertical axis
        bracketValues - true if the computed interval must fully bracket the input values; false if bracketing is optional.
        Returns:
        if successful, a valid instance; otherwise, a null.
      • mapValueToPixel

        public double mapValueToPixel​(double value)
        Maps a value to a corresponding pixel coordinate. Value0 maps to zero. Value1 maps to (value1-value0)/unitsPerPixel.
        Parameters:
        value - the value to be mapped.
        Returns:
        a valid floating point value
      • getIntervalMagnitude

        public int getIntervalMagnitude()
        Gets the integer power of ten corresponding to the magnitude of the primary interval. For example, if the primary interval were 0.2, the interval magnitude would be -1.
        Returns:
        an integer
      • getUnitsPerPixel

        public double getUnitsPerPixel()
        Gets the scale factor for units in the value coordinate system compare to pixels. Useful for creating affine transforms.
        Returns:
        a finite, non-zero floating point value;